From: <one...@us...> - 2003-01-15 10:33:19
|
Update of /cvsroot/hibernate/Hibernate2/src/net/sf/hibernate/impl In directory sc8-pr-cvs1:/tmp/cvs-serv30115/sf/hibernate/impl Modified Files: SessionImpl.java Log Message: fixed bug in TimestampType now possible to delete and re-save an object in same session Index: SessionImpl.java =================================================================== RCS file: /cvsroot/hibernate/Hibernate2/src/net/sf/hibernate/impl/SessionImpl.java,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** SessionImpl.java 14 Jan 2003 13:42:13 -0000 1.8 --- SessionImpl.java 15 Jan 2003 10:33:17 -0000 1.9 *************** *** 493,509 **** EntityEntry e = getEntry(object); if ( e!=null ) { ! log.trace( "object already associated with session" ); ! return e.id; ! } ! else { ! Serializable id; ! try { ! id = getPersister(object).getIdentifierGenerator().generate(this, object); } ! catch (SQLException sqle) { ! throw new JDBCException("Could not save object", sqle); } - return doSave(object, id); } } --- 493,514 ---- EntityEntry e = getEntry(object); if ( e!=null ) { ! if ( e.status==DELETED ) { ! flush(); } ! else { ! log.trace( "object already associated with session" ); ! return e.id; } } + + Serializable id; + try { + id = getPersister(object).getIdentifierGenerator().generate(this, object); + } + catch (SQLException sqle) { + throw new JDBCException("Could not save object", sqle); + } + return doSave(object, id); + } *************** *** 518,530 **** EntityEntry e = getEntry(object); if ( e!=null ) { ! if ( !id.equals(e.id) ) throw new PersistentObjectException( ! "object passed to save() was already persistent: " + ! infoString(e.persister, id) ! ); ! log.trace( "object already associated with session" ); ! } ! else { ! doSave(object, id); } } --- 523,539 ---- EntityEntry e = getEntry(object); if ( e!=null ) { ! if ( e.status==DELETED ) { ! flush(); ! } ! else { ! if ( !id.equals(e.id) ) throw new PersistentObjectException( ! "object passed to save() was already persistent: " + ! infoString(e.persister, id) ! ); ! log.trace( "object already associated with session" ); ! } } + + doSave(object, id); } *************** *** 552,559 **** key = new Key(id, persister); ! if ( getEntity(key) != null ) throw new HibernateException( ! "The generated ID is already in use: " + ! infoString(persister, id) ! ); persister.setIdentifier(object, id); --- 561,576 ---- key = new Key(id, persister); ! Object old = getEntity(key); ! if (old!= null) { ! if ( getEntry(old).status==DELETED ) { ! flush(); ! } ! else { ! throw new HibernateException( ! "The generated identifier is already in use: " + ! infoString(persister, id) ! ); ! } ! } persister.setIdentifier(object, id); *************** *** 954,961 **** Object object = HibernateProxyHelper.unproxy(obj, this); ! if ( isEntryFor(object) ) { // do nothing for persistent instances log.trace("object already associated with session"); } else { --- 971,982 ---- Object object = HibernateProxyHelper.unproxy(obj, this); ! EntityEntry e = getEntry(object); ! if (e!=null && e.status!=DELETED) { // do nothing for persistent instances log.trace("object already associated with session"); } + else if (e!=null) { //e.status==DELETED + save(object); + } else { *************** *** 978,983 **** } ! } ! } --- 999,1003 ---- } ! } } *************** *** 1019,1023 **** ); } ! else if ( old!=null ) { throw new HibernateException( "Another object was associated with this id (the object with the given id was already loaded): " + --- 1039,1043 ---- ); } ! else if (old!=null) { throw new HibernateException( "Another object was associated with this id (the object with the given id was already loaded): " + *************** *** 1737,1741 **** public void postDelete(Object obj) { ! getEntry(obj).existsInDatabase = false; } --- 1757,1765 ---- public void postDelete(Object obj) { ! EntityEntry e = removeEntry(obj); ! Key key = new Key(e.id, e.persister); ! removeEntity(key); ! proxiesByKey.remove(key); ! //getEntry(obj).existsInDatabase = false; } *************** *** 1863,1867 **** if (status==DELETED) { ! entry.status = GONE; //for next time } else { --- 1887,1891 ---- if (status==DELETED) { ! entry.status = GONE; } else { |