[hibernate-issues] [Hibernate-JIRA] Commented: (HHH-1716) Orphaned identities

James Carman (JIRA) noreply at atlassian.com
Thu Jul 17 09:22:46 EDT 2008


    [ http://opensource.atlassian.com/projects/hibernate/browse/HHH-1716?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_30683 ] 

James Carman commented on HHH-1716:
-----------------------------------

For what it's worth, we decided to go with UUIDs for our ids to solve this (and other) problems.  However, it helps performance if you use a version field (with an appropriate unsaved value) along with your UUID-based entity so that hibernate knows when an object is new (it needs to save) vs. existing (needs to update).

> Orphaned identities
> -------------------
>
>                 Key: HHH-1716
>                 URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-1716
>             Project: Hibernate3
>          Issue Type: Bug
>          Components: core
>            Reporter: James Carman
>
> When saving an object, its identity is set (for generated identities of course), even if the transaction is rolled back.  This can cause some nasty problems in webapps when using an entity object to store data entered by the user on a form (and displaying back the data if there are errors).  Hibernate will think this object is persistent even though it's not when using saveOrUpdate().  Is there a way that the identity values can be set back to what they were originally (nulled out) or can you not set the identity values until transaction completion?  Here's some code:
> final Foo foo = new Foo();
> foo.setName( "Hello, Foo!" );
> final SessionFactory sf = getSessionFactory();
> Session session = sf.openSession();
> Transaction tx = session.beginTransaction();
> session.save( foo );
> tx.rollback();
> session.close();
> session = sf.openSession();
> tx = session.beginTransaction();
> session.saveOrUpdate( foo );
> tx.commit(); // Exception here!
> session.close();
> sf.close();

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://opensource.atlassian.com/projects/hibernate/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        



More information about the hibernate-issues mailing list