Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

OneToOne Relation Exception

 
Gabriele Fain
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 553
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic