This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Soft Skills and have John Sonmez on-line!
See this thread for details.
The moose likes Object Relational Mapping and the fly likes JPA Provider issue Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "JPA Provider issue" Watch "JPA Provider issue" New topic
Author

JPA Provider issue

Amr k. Saleh
Ranch Hand

Joined: Aug 23, 2010
Posts: 41
Hi All,

I'm using Toplink as provider for JPA and here is my persistance.xml



but when exception is logged it says EclipseLink exception


Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.3.2.v20111125-r10461): org.eclipse.persistence.exceptions.DatabaseException


I'm using maven and put persistance.xml under src/main/resources/META-INF

why it says eclipselink ?!


thanks,
Amr Khaled
James Boswell
Bartender

Joined: Nov 09, 2011
Posts: 1030
    
    5

Amr

Can you post the full stack trace of the exception please?
Amr k. Saleh
Ranch Hand

Joined: Aug 23, 2010
Posts: 41
Just know it was working before i move to maven, and what i noticed is it says eclipselink

Dieter Quickfend
Bartender

Joined: Aug 06, 2010
Posts: 543
    
    4

EclipseLink basically IS TopLink open sourced. I think your issue is more data-related. Check if the merchant_id FK in the record you're trying to insert has a corresponding id in the Merchant table.


Oracle Certified Professional: Java SE 6 Programmer && Oracle Certified Expert: (JEE 6 Web Component Developer && JEE 6 EJB Developer)
Amr k. Saleh
Ranch Hand

Joined: Aug 23, 2010
Posts: 41
aha, i see

what i'm doing is inserting new merchant and new store at the same time, it was working before i don't know what happened !!
Dieter Quickfend
Bartender

Joined: Aug 06, 2010
Posts: 543
    
    4

When mavenizing, did you make sure to specify all the same versions you were using before you mavenized?
James Boswell
Bartender

Joined: Nov 09, 2011
Posts: 1030
    
    5

I can't see how this is an issue with Maven.

As stated previously, it is to do with the data being inserted into the database violating a foreign key constraint.
Dieter Quickfend
Bartender

Joined: Aug 06, 2010
Posts: 543
    
    4

James, it's definitely not a Maven issue... But it might be related to different versions of TopLink... I seem to remember there used to be a bug with TopLink not allowing automatic FK generation, and he's pretty adamant that nothing has changed apparently...

Even so, Amr, first thing I would try is check if you have cascade=PERSIST or ALL set on your relationship. If not, set it. In this case, it cannot have worked before. If it is there, persist the Merchant, flush the EntityManager, and then persist the Store. That ought to work. Your merchant will be in the database, and your FK constraint will not fail. If this fixes it, it might be due to TopLink. If it still doesn't work, you'll definitely have a different error message.

And please, next time post all the relevant code and configs, not just the error message.
Amr k. Saleh
Ranch Hand

Joined: Aug 23, 2010
Posts: 41
ok, i have a Merchant entity that extend User entity

User entity



Merchant entity



and Merchant entity has a list of store entity





and that is the code that inserts Merchant entity




i logged the generated queries and i found out that it inserts User then Store and that is why it voilate the FK constraint because there is no merchant yet, how can i solve this ?

Amr k. Saleh
Ranch Hand

Joined: Aug 23, 2010
Posts: 41
here the maven dependencies

James Boswell
Bartender

Joined: Nov 09, 2011
Posts: 1030
    
    5

The actual code that persists the merchant entity is

userService.registerMerchant

Can you post this code please?
Amr k. Saleh
Ranch Hand

Joined: Aug 23, 2010
Posts: 41
It worked when i changed the provider to Hibernate !
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JPA Provider issue