Two Laptop Bag*
The moose likes Object Relational Mapping and the fly likes OneToOne Relation Exception Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "OneToOne Relation Exception " Watch "OneToOne Relation Exception " New topic
Author

OneToOne Relation Exception

Gabriele Fain
Greenhorn

Joined: Sep 09, 2010
Posts: 2
Hello,
I write a desktop application and it work fine but today a class for insert some values don't work.
I have a class regioni (like a list of states) that in used in OneToOne relations in 3 other tables.
In one of this today it not work .

This are the two classes




and the oder class is




in the code I made


I get this error and I don't understand why
Call: INSERT INTO regioni (id, codtessera, nome) VALUES (?, ?, ?)
bind => [1, 03, abccc]


It seems like it try to insert a record in the regioni table and I dont't understad why.
In other classs that have the same OneToOne join to table regioni I don't have the same problem.

Can someone help me ?
Best regards.


Gabriele Fain
Greenhorn

Joined: Sep 09, 2010
Posts: 2
I Found that the problem come if before the commit I made a rollback operation.
If I don't made any rollback all commits work fine.
If a made a rollback any other commit after this that try to change idregioni field will generate the error.




Gabriele Fain wrote:Hello,
I write a desktop application and it work fine but today a class for insert some values don't work.
I have a class regioni (like a list of states) that in used in OneToOne relations in 3 other tables.
In one of this today it not work .

This are the two classes




and the oder class is




in the code I made


I get this error and I don't understand why
Call: INSERT INTO regioni (id, codtessera, nome) VALUES (?, ?, ?)
bind => [1, 03, abccc]


It seems like it try to insert a record in the regioni table and I dont't understad why.
In other classs that have the same OneToOne join to table regioni I don't have the same problem.

Can someone help me ?
Best regards.





James Sutherland
Ranch Hand

Joined: Oct 01, 2007
Posts: 553
After a rollback() in JPA the persistence context becomes invalid (cleared/detached), this is probably related to your issue.
Normally after a rollback it is best to get a new EntityManager. But either way, you need to re-read or merge and previously managed objects that you want to continue to use.

What is the error you are getting? I assume a pk constraint error. This is most likely occurring because you had a reference to a previously managed object, that has now been detached, so is invalid, and assume to be new from your cascade persist relationship. You need to re-read or merge it.

TopLink : EclipseLink : Book:Java Persistence : Blog:Java Persistence Performance
 
 
subject: OneToOne Relation Exception
 
Similar Threads
Inner join problem
incomplete @JoinColumns
JPA composite key mapping
Problems using GenerationType.IDENTITY for in-memory databases
JPA EclipseLink SEQUENCE table does not exist