Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
Win a copy of Learning Java by Building Android Games this week in the Android forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • Devaka Cooray
Saloon Keepers:
  • Ganesh Patekar
  • Tim Moores
  • Carey Brown
  • Stephan van Hulst
  • salvin francis
Bartenders:
  • Ron McLeod
  • Frits Walraven
  • Pete Letkeman

OneToOne Relation Exception  RSS feed

 
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.





 
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
Boost this thread!