• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

OneToOne Relation Exception

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
I guess everyone has an angle. Fine, what do you want? Just know that you cannot have this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic