• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Instances in memory and in DB

 
Sharon Adar
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey,
Although it looks like a real simple question, I want to ensure I�ve chosen the best solution.

I�ve two Classes A and B and which has reference to the same(!) instance of class C.
The cascade type of C in both A and B, includes cascade.persist.
In my test, I�ve created instance of A and an instance of B, as commented before-
Both instances reference the same instance of C.
I�ve saved A and B�s instances, and of course although A and B were referencing the same C,
The C instance got two different orm-id (one in A�s hierarchy, and on in B�s).

My solution was to persist C first and then set A�s C and B�s C to be my instance.
Any better idea?
 
James Sutherland
Ranch Hand
Posts: 553
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you persisting A and B in the same transaction/entitymanager? If so, then it sounds like a bug, what JPA provider and version are you using?

Perhaps include your code as well.

If the cascade does not work with your provider, then you will have to persist them separately, or use a different provider.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic