Quantcast

Create database using JPA annotations: Problem with foreign keys

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Create database using JPA annotations: Problem with foreign keys

Hohl, Gerrit

Hello everyone, :-)

 

currently I'm trying to use EclipseLink v2.6.4 and an Apache Derby In-Memory database for some JUnit tests.

But somehow it doesn't work.

 

EclipseLink recognized the JPA annotations on my entities - which looks like this:

 

@ManyToOne(targetEntity = DealerEntity.class, cascade = { CascadeType.ALL })

@JoinColumn(name = "dealer_id", referencedColumnName = "id", nullable = false, foreignKey = @ForeignKey(name = "article_dealer_foreign_key"))

private DealerEntity dealer;

 

And if I step through the code in debugging mode I see that a ForeignKeyContstraint object is created internally and the source fields and target fields are set (not by calling addSourceField(String) and addTargetField(String), but by calling getSourceFields().add(String) and getTargetFields().add(String)).

This ForeignKeyContstraint object seems to be used for the table DDL.

But then a second ForeignKeyContstraint object is instantiated. In this case sourceFields and targetFields are not set.

And that object is used for creating the foreign constraint DDL, resulting in a SQL statement like this:

 

ALTER TABLE article ADD CONSTRAINT article_dealer_foreign_key FOREIGN KEY () REFERENCES  ()

 

One possibility would be to additional set the foreignKeyDefinition of the @ForeignKey definition.

But that would mean extra work and it has to be kept in sync with the rest of the annotation.

Instead it would be great to get the sourceFields and targetFields set like it is the first time the ForeignKeyConstraint object is instantiated.

I even don't know why EclipseLink does that 2 times.

 

Regards

Gerrit

 


_______________________________________________
eclipselink-users mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/eclipselink-users
Loading...