File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Am I persisting a detached Entity?

 
Cainiao Zou
Ranch Hand
Posts: 36
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a entity "User", and i just create it and try to persist it, but I got a error message, something like i was persisting a detached Entity.
I checked the code of "User", i found there was no auto generated id property like other entities, the identity is the "name" property, which must be initialed by creating. Then I added the "dummy" id property just like normal, all work fine!

So I just wonder, why JPA/Hibernate said it was a detached Entity at all? I guess, it just checks the identity property of the entity, if it's not NULL (dummy ids are almost always null by creating and will be auto generated), and there is no copy in PersistenceContext with the same identity, then it will be considered as detached?

Am I right? But what about the situation, when i don't want to use the auto generated identity? How can I persist them?

thanks
 
Vijitha Kumara
Bartender
Posts: 3909
9
Chrome Fedora Hibernate
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
...when i don't want to use the auto generated identity? How can I persist them?

You should have set the application-assigned key value before calling the persist() method since it is not auto-generated in this case.

 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic