-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 9 posts ] 
Author Message
 Post subject: Problem update Parent with collection, add a children, bug ?
PostPosted: Fri Apr 23, 2004 6:22 am 
Newbie

Joined: Thu Oct 09, 2003 6:57 am
Posts: 17
Location: France
Hi all,

Firstly, I use Hibernate 2.1 and Java 1.4.2.

I have forum which contains a collection of forumMessages


<set name="forummessages" lazy="true" inverse="false" cascade="all-delete-orphan" order-by="date_message" >
<key>
<column name="ref_forum" />
</key>
<one-to-many class="com.newcompany.business.Forummessage"/>
</set>


My code for find a forum is :

Code:
public Forum findForum(Conflict conflict, String type) throws Exception {
Forum forum = null;
try {
   Session session = HibernateSession.currentSession();
   HibernateSession.beginTransaction();
   session.flush();

   if (!session.contains(conflict))
      session.load(conflict,conflict.getId());
   
   Query query = session.createQuery("from forum in class Forum where forum.name= ? and forum.conflict.id=?");
   query.setString(0,type);
   query.setString(1,conflict.getId().toString());
   forum = (Forum) query.uniqueResult();
   if(forum!=null)
      Hibernate.initialize(forum.getForummessages());
   HibernateSession.endTransaction(false);
} catch (HibernateException e) {
   try {
      HibernateSession.closeSession();
   } catch (HibernateException e1) {
   throw new DataAccessException(e1.getMessage(), e1.getCause());
   }
   throw new DataAccessException(e.getMessage(), e.getCause());
}
   return forum;
}


So when I get my forum I initialize the collection.
Now, my code for save a forum is :

Code:
public void saveOrUpdateForum(Forum forum) throws Exception{
try {
  Session session = HibernateSession.currentSession();
  HibernateSession.beginTransaction();
  //session.flush();
  session.saveOrUpdate(forum);
  HibernateSession.endTransaction(true);
} catch (HibernateException e) {
  try {
     HibernateSession.closeSession();
  } catch (HibernateException e1) {
     throw new DataAccessException(e1.getMessage(), e1.getCause());
  }
     throw new DataAccessException(e.getMessage(), e.getCause());
  }
}


And now the code of my test class :

Code:
HibernateSession.setHibernateConfigFile("/hibernateTest.cfg.xml");

  //get my DAO and retrieve conflict
  ConflictHibernateDAO conflictDao = (ConflictHibernateDAO) DAOFactory.createFactory().getDao(Constants.CONFLICT_DAO);
  Conflict conflict = new Conflict();
  conflict.setId(new Integer(43));
  conflict = conflictDao.getConflict(conflict);

  HibernateSession.closeSession();   //Close the session

  //Retrieve the forum
  forumDao = (ForumHibernateDAO) DAOFactory.createFactory().getDao(Constants.FORUM_DAO);
  forum = forumDao.findForum(conflict, Tokens.CLAIMANT);
  System.out.println("Forum number "+forum.getId());

  HibernateSession.closeSession();  //Close the session

  Forummessage message;
  message = new Forummessage();
  message.setAttach("att");
  message.setMessage("message1");
  message.setSubject("subject1");
  message.setDateMessage(new Date());
  message.setForummessages(new TreeSet());
  forum.getForummessages().add(message);
  forumDao.saveOrUpdateForum(forum);
 
  HibernateSession.closeSession();  //Close the session

  Forummessage message2 = new Forummessage();
  message2.setAttach("att");
  message2.setMessage("message2");
  message2.setSubject("subject2");
  message2.setDateMessage(new Date());
  forum.getForummessages().add(message2);
  forumDao.saveOrUpdateForum(forum);

  HibernateSession.closeSession();  //Close the session



It does not work.
Indeed, the first message is properly saved with the good reference to the Forum.
But when it saves the second message, this one is properly saved (with good reference to the forum) but the first message is updated and the reference to the forum is setted to null.

To summarize,
In my database I have the Forum with id 4.
The first message is saved :
attach : att
message : message1
blblbla
ref_forum : 4

After when it save the second message I have :
First message :
attach : att
message : message1
blblbla
ref_forum : NULL Why ?

The secondmessage is saved :
attach : att
message : message2
blblbla
ref_forum : 4

See bellow the hibernate log :

11:39:30,312 DEBUG Cascades:274 - unsaved-value strategy NULL
11:39:30,312 DEBUG SessionImpl:1285 - saveOrUpdate() previously saved instance with id: 4
11:39:30,312 DEBUG SessionImpl:1338 - updating [com.newcompany.business.Forum#4]
11:39:30,312 DEBUG Cascades:356 - processing cascades for: com.newcompany.business.Forum
11:39:30,312 DEBUG Cascades:381 - cascading to collection: com.newcompany.business.Forum.forummessages
11:39:30,312 DEBUG Cascades:105 - cascading to saveOrUpdate()
11:39:30,312 DEBUG Cascades:274 - unsaved-value strategy NULL
11:39:30,312 DEBUG SessionImpl:1285 - saveOrUpdate() previously saved instance with id: 127
11:39:30,312 DEBUG SessionImpl:1338 - updating [com.newcompany.business.Forummessage#127]
11:39:30,312 DEBUG Cascades:356 - processing cascades for: com.newcompany.business.Forummessage
11:39:30,312 DEBUG Cascades:364 - done processing cascades for: com.newcompany.business.Forummessage
11:39:30,312 DEBUG Cascades:105 - cascading to saveOrUpdate()
11:39:30,328 DEBUG Cascades:274 - unsaved-value strategy NULL
11:39:30,328 DEBUG SessionImpl:1285 - saveOrUpdate() previously saved instance with id: 128
11:39:30,328 DEBUG SessionImpl:1338 - updating [com.newcompany.business.Forummessage#128]
11:39:30,328 DEBUG Cascades:356 - processing cascades for: com.newcompany.business.Forummessage
11:39:30,328 DEBUG Cascades:364 - done processing cascades for: com.newcompany.business.Forummessage
11:39:30,328 DEBUG Cascades:105 - cascading to saveOrUpdate()
11:39:30,328 DEBUG Cascades:274 - unsaved-value strategy NULL
11:39:30,328 DEBUG SessionImpl:1280 - saveOrUpdate() unsaved instance
11:39:30,328 DEBUG BatcherImpl:192 - about to open: 0 open PreparedStatements, 0 open ResultSets
11:39:30,328 DEBUG BatcherImpl:226 - prepared statement get: select nextval ('seq_forummessage')
11:39:30,328 DEBUG BatcherImpl:232 - preparing statement
11:39:30,328 DEBUG SequenceGenerator:72 - Sequence identifier generated: 129
11:39:30,328 DEBUG BatcherImpl:199 - done closing: 0 open PreparedStatements, 0 open ResultSets
11:39:30,328 DEBUG BatcherImpl:245 - closing statement
11:39:30,328 DEBUG SessionImpl:734 - saving [com.newcompany.business.Forummessage#129]
11:39:30,328 DEBUG Cascades:356 - processing cascades for: com.newcompany.business.Forummessage
11:39:30,328 DEBUG Cascades:364 - done processing cascades for: com.newcompany.business.Forummessage
11:39:30,328 DEBUG SessionImpl:2775 - Wrapped collection in role: com.newcompany.business.Forummessage.forummessages
11:39:30,343 DEBUG Cascades:356 - processing cascades for: com.newcompany.business.Forummessage
11:39:30,343 DEBUG Cascades:381 - cascading to collection: com.newcompany.business.Forummessage.forummessages
11:39:30,343 DEBUG Cascades:364 - done processing cascades for: com.newcompany.business.Forummessage
11:39:30,343 DEBUG Cascades:364 - done processing cascades for: com.newcompany.business.Forum
11:39:30,343 DEBUG JDBCTransaction:54 - commit
11:39:30,343 DEBUG SessionImpl:2219 - flushing session
11:39:30,343 DEBUG Cascades:356 - processing cascades for: com.newcompany.business.Forum
11:39:30,343 DEBUG Cascades:381 - cascading to collection: com.newcompany.business.Forum.forummessages
11:39:30,343 DEBUG Cascades:105 - cascading to saveOrUpdate()
11:39:30,343 DEBUG SessionImpl:1266 - saveOrUpdate() persistent instance
11:39:30,343 DEBUG Cascades:105 - cascading to saveOrUpdate()
11:39:30,343 DEBUG SessionImpl:1266 - saveOrUpdate() persistent instance
11:39:30,359 DEBUG Cascades:105 - cascading to saveOrUpdate()
11:39:30,359 DEBUG SessionImpl:1266 - saveOrUpdate() persistent instance
11:39:30,359 DEBUG Cascades:364 - done processing cascades for: com.newcompany.business.Forum
11:39:30,359 DEBUG Cascades:356 - processing cascades for: com.newcompany.business.Forummessage
11:39:30,359 DEBUG Cascades:364 - done processing cascades for: com.newcompany.business.Forummessage
11:39:30,359 DEBUG Cascades:356 - processing cascades for: com.newcompany.business.Forummessage
11:39:30,359 DEBUG Cascades:364 - done processing cascades for: com.newcompany.business.Forummessage
11:39:30,359 DEBUG Cascades:356 - processing cascades for: com.newcompany.business.Forummessage
11:39:30,359 DEBUG Cascades:381 - cascading to collection: com.newcompany.business.Forummessage.forummessages
11:39:30,359 DEBUG Cascades:364 - done processing cascades for: com.newcompany.business.Forummessage
11:39:30,359 DEBUG SessionImpl:299 - Collection dirty: [com.newcompany.business.Forum.forummessages#4]
11:39:30,359 DEBUG SessionImpl:2328 - Flushing entities and processing referenced collections
11:39:30,359 DEBUG SessionImpl:2424 - Updating entity: [com.newcompany.business.Forum#4]
11:39:30,359 DEBUG SessionImpl:2805 - Collection found: [com.newcompany.business.Forum.forummessages#4], was: [com.newcompany.business.Forum.forummessages#4]
11:39:30,359 DEBUG SessionImpl:2424 - Updating entity: [com.newcompany.business.Forummessage#127]
11:39:30,375 DEBUG SessionImpl:2805 - Collection found: [com.newcompany.business.Forummessage.forummessages#127], was: [com.newcompany.business.Forummessage.forummessages#127]
11:39:30,375 DEBUG SessionImpl:2424 - Updating entity: [com.newcompany.business.Forummessage#128]
11:39:30,375 DEBUG SessionImpl:2805 - Collection found: [com.newcompany.business.Forummessage.forummessages#128], was: [com.newcompany.business.Forummessage.forummessages#128] My note : save the first message
11:39:30,375 DEBUG SessionImpl:2805 - Collection found: [com.newcompany.business.Forummessage.forummessages#129], was: [<unreferenced>]
11:39:30,375 DEBUG SessionImpl:2647 - Processing unreferenced collections
11:39:30,375 DEBUG SessionImpl:2658 - Scheduling collection removes/(re)creates/updates
11:39:30,390 DEBUG SessionImpl:2231 - Flushed: 1 insertions, 3 updates, 0 deletions to 4 objects
11:39:30,390 DEBUG SessionImpl:2236 - Flushed: 1 (re)creations, 1 updates, 0 removals to 4 collections
11:39:30,390 DEBUG SessionImpl:2266 - executing flush
11:39:30,390 DEBUG EntityPersister:503 - Inserting entity: [com.newcompany.business.Forummessage#129]
11:39:30,390 DEBUG BatcherImpl:192 - about to open: 0 open PreparedStatements, 0 open ResultSets
11:39:30,390 DEBUG BatcherImpl:226 - prepared statement get: insert into forummessage (message, subject, date_message, notifiy, attach, ref_author, id) values (?, ?, ?, ?, ?, ?, ?)
11:39:30,390 DEBUG BatcherImpl:232 - preparing statement
11:39:30,390 DEBUG EntityPersister:393 - Dehydrating entity: [com.newcompany.business.Forummessage#129]
11:39:30,390 DEBUG BatcherImpl:199 - done closing: 0 open PreparedStatements, 0 open ResultSets
11:39:30,390 DEBUG BatcherImpl:245 - closing statement
11:39:30,390 DEBUG EntityPersister:676 - Updating entity: [com.newcompany.business.Forum#4]
11:39:30,390 DEBUG BatcherImpl:192 - about to open: 0 open PreparedStatements, 0 open ResultSets
11:39:30,390 DEBUG BatcherImpl:226 - prepared statement get: update forum set name=?, ref_conflict=? where id=?
11:39:30,390 DEBUG BatcherImpl:232 - preparing statement
11:39:30,390 DEBUG EntityPersister:393 - Dehydrating entity: [com.newcompany.business.Forum#4]
11:39:30,406 DEBUG Cascades:245 - unsaved-value: 0
11:39:30,406 DEBUG EntityPersister:676 - Updating entity: [com.newcompany.business.Forummessage#127]
11:39:30,406 DEBUG BatcherImpl:199 - done closing: 0 open PreparedStatements, 0 open ResultSets
11:39:30,406 DEBUG BatcherImpl:245 - closing statement
11:39:30,406 DEBUG BatcherImpl:192 - about to open: 0 open PreparedStatements, 0 open ResultSets
11:39:30,406 DEBUG BatcherImpl:226 - prepared statement get: update forummessage set message=?, subject=?, date_message=?, notifiy=?, attach=?, ref_author=? where id=?
11:39:30,406 DEBUG BatcherImpl:232 - preparing statement
11:39:30,406 DEBUG EntityPersister:393 - Dehydrating entity: [com.newcompany.business.Forummessage#127]
11:39:30,406 DEBUG EntityPersister:676 - Updating entity: [com.newcompany.business.Forummessage#128]
11:39:30,406 DEBUG EntityPersister:393 - Dehydrating entity: [com.newcompany.business.Forummessage#128]
11:39:30,406 DEBUG BatcherImpl:199 - done closing: 0 open PreparedStatements, 0 open ResultSets
11:39:30,406 DEBUG BatcherImpl:245 - closing statement
11:39:30,406 DEBUG BasicCollectionPersister:587 - Deleting rows of collection: [com.newcompany.business.Forum.forummessages#4]
11:39:30,421 DEBUG BasicCollectionPersister:611 - no rows to delete
11:39:30,421 DEBUG BasicCollectionPersister:756 - Updating rows of collection: com.newcompany.business.Forum.forummessages#4
11:39:30,421 DEBUG BasicCollectionPersister:761 - done updating rows
11:39:30,421 DEBUG BasicCollectionPersister:625 - Inserting rows of collection: [com.newcompany.business.Forum.forummessages#4]
11:39:30,421 DEBUG BatcherImpl:192 - about to open: 0 open PreparedStatements, 0 open ResultSets
11:39:30,421 DEBUG BatcherImpl:226 - prepared statement get: update forummessage set ref_forum=? where id=?
11:39:30,421 DEBUG BatcherImpl:232 - preparing statement
11:39:30,421 DEBUG BasicCollectionPersister:654 - done inserting rows
11:39:30,421 DEBUG BatcherImpl:199 - done closing: 0 open PreparedStatements, 0 open ResultSets
11:39:30,421 DEBUG BatcherImpl:245 - closing statement
11:39:30,421 DEBUG BasicCollectionPersister:544 - Inserting collection: [com.newcompany.business.Forummessage.forummessages#129]
11:39:30,421 DEBUG BasicCollectionPersister:573 - collection was empty
11:39:30,421 DEBUG SessionImpl:2678 - post flush
11:39:30,421 DEBUG SessionImpl:507 - transaction completion
11:39:30,421 DEBUG SessionImpl:3250 - disconnecting session
11:39:30,421 DEBUG DriverManagerConnectionProvider:121 - returning connection to pool, pool size: 1
11:39:30,421 DEBUG DriverManagerConnectionProvider:121 - returning connection to pool, pool size: 1
11:39:30,421 DEBUG SessionImpl:507 - transaction completion
11:39:30,437 DEBUG SessionImpl:495 - closing session
11:39:30,437 DEBUG SessionImpl:477 - opened session
11:39:30,437 DEBUG JDBCTransaction:36 - begin
11:39:30,437 DEBUG DriverManagerConnectionProvider:78 - total checked-out connections: 0
11:39:30,437 DEBUG DriverManagerConnectionProvider:78 - total checked-out connections: 0
11:39:30,437 DEBUG DriverManagerConnectionProvider:84 - using pooled JDBC connection, pool size: 0
11:39:30,437 DEBUG DriverManagerConnectionProvider:84 - using pooled JDBC connection, pool size: 0
11:39:30,437 DEBUG SessionImpl:2219 - flushing session
11:39:30,437 DEBUG SessionImpl:2328 - Flushing entities and processing referenced collections
11:39:30,437 DEBUG SessionImpl:2647 - Processing unreferenced collections
11:39:30,437 DEBUG SessionImpl:2658 - Scheduling collection removes/(re)creates/updates
11:39:30,437 DEBUG SessionImpl:2231 - Flushed: 0 insertions, 0 updates, 0 deletions to 0 objects
11:39:30,453 DEBUG SessionImpl:2236 - Flushed: 0 (re)creations, 0 updates, 0 removals to 0 collections
11:39:30,453 DEBUG SessionImpl:2266 - executing flush
11:39:30,453 DEBUG SessionImpl:2678 - post flush
11:39:30,453 DEBUG Cascades:274 - unsaved-value strategy NULL
11:39:30,453 DEBUG SessionImpl:1285 - saveOrUpdate() previously saved instance with id: 4
11:39:30,453 DEBUG SessionImpl:1338 - updating [com.newcompany.business.Forum#4]
11:39:30,453 DEBUG Cascades:356 - processing cascades for: com.newcompany.business.Forum
11:39:30,453 DEBUG Cascades:381 - cascading to collection: com.newcompany.business.Forum.forummessages
11:39:30,453 DEBUG Cascades:105 - cascading to saveOrUpdate()
11:39:30,453 DEBUG Cascades:274 - unsaved-value strategy NULL
11:39:30,453 DEBUG SessionImpl:1285 - saveOrUpdate() previously saved instance with id: 127
11:39:30,453 DEBUG SessionImpl:1338 - updating [com.newcompany.business.Forummessage#127]
11:39:30,453 DEBUG Cascades:356 - processing cascades for: com.newcompany.business.Forummessage
11:39:30,453 DEBUG Cascades:364 - done processing cascades for: com.newcompany.business.Forummessage
11:39:30,453 DEBUG Cascades:105 - cascading to saveOrUpdate()
11:39:30,453 DEBUG Cascades:274 - unsaved-value strategy NULL
11:39:30,453 DEBUG SessionImpl:1285 - saveOrUpdate() previously saved instance with id: 128
11:39:30,453 DEBUG SessionImpl:1338 - updating [com.newcompany.business.Forummessage#128]
11:39:30,453 DEBUG Cascades:356 - processing cascades for: com.newcompany.business.Forummessage
11:39:30,453 DEBUG Cascades:364 - done processing cascades for: com.newcompany.business.Forummessage
11:39:30,453 DEBUG Cascades:105 - cascading to saveOrUpdate()
11:39:30,453 DEBUG Cascades:274 - unsaved-value strategy NULL
11:39:30,453 DEBUG SessionImpl:1285 - saveOrUpdate() previously saved instance with id: 129
11:39:30,453 DEBUG SessionImpl:1338 - updating [com.newcompany.business.Forummessage#129]
11:39:30,468 DEBUG Cascades:356 - processing cascades for: com.newcompany.business.Forummessage
11:39:30,468 DEBUG Cascades:381 - cascading to collection: com.newcompany.business.Forummessage.forummessages
11:39:30,468 DEBUG Cascades:364 - done processing cascades for: com.newcompany.business.Forummessage
11:39:30,468 DEBUG Cascades:105 - cascading to saveOrUpdate()
11:39:30,468 DEBUG Cascades:274 - unsaved-value strategy NULL My note : save the second message
11:39:30,468 DEBUG SessionImpl:1280 - saveOrUpdate() unsaved instance
11:39:30,468 DEBUG BatcherImpl:192 - about to open: 0 open PreparedStatements, 0 open ResultSets
11:39:30,468 DEBUG BatcherImpl:226 - prepared statement get: select nextval ('seq_forummessage')
11:39:30,468 DEBUG SessionImpl:3302 - running Session.finalize()
11:39:30,468 DEBUG BatcherImpl:232 - preparing statement
11:39:30,468 DEBUG SequenceGenerator:72 - Sequence identifier generated: 130
11:39:30,468 DEBUG BatcherImpl:199 - done closing: 0 open PreparedStatements, 0 open ResultSets
11:39:30,468 DEBUG BatcherImpl:245 - closing statement
11:39:30,468 DEBUG SessionImpl:734 - saving [com.newcompany.business.Forummessage#130]
11:39:30,468 DEBUG Cascades:356 - processing cascades for: com.newcompany.business.Forummessage
11:39:30,468 DEBUG Cascades:364 - done processing cascades for: com.newcompany.business.Forummessage
11:39:30,468 DEBUG Cascades:356 - processing cascades for: com.newcompany.business.Forummessage
11:39:30,468 DEBUG Cascades:364 - done processing cascades for: com.newcompany.business.Forummessage
11:39:30,468 DEBUG Cascades:364 - done processing cascades for: com.newcompany.business.Forum
11:39:30,468 DEBUG JDBCTransaction:54 - commit
11:39:30,468 DEBUG SessionImpl:2219 - flushing session
11:39:30,468 DEBUG Cascades:356 - processing cascades for: com.newcompany.business.Forum
11:39:30,484 DEBUG Cascades:381 - cascading to collection: com.newcompany.business.Forum.forummessages
11:39:30,484 DEBUG Cascades:105 - cascading to saveOrUpdate()
11:39:30,484 DEBUG SessionImpl:1266 - saveOrUpdate() persistent instance
11:39:30,484 DEBUG Cascades:105 - cascading to saveOrUpdate()
11:39:30,484 DEBUG SessionImpl:1266 - saveOrUpdate() persistent instance
11:39:30,484 DEBUG Cascades:105 - cascading to saveOrUpdate()
11:39:30,484 DEBUG SessionImpl:1266 - saveOrUpdate() persistent instance
11:39:30,484 DEBUG Cascades:105 - cascading to saveOrUpdate()
11:39:30,484 DEBUG SessionImpl:1266 - saveOrUpdate() persistent instance
11:39:30,484 DEBUG Cascades:364 - done processing cascades for: com.newcompany.business.Forum
11:39:30,484 DEBUG Cascades:356 - processing cascades for: com.newcompany.business.Forummessage
11:39:30,484 DEBUG Cascades:364 - done processing cascades for: com.newcompany.business.Forummessage
11:39:30,484 DEBUG Cascades:356 - processing cascades for: com.newcompany.business.Forummessage
11:39:30,484 DEBUG Cascades:364 - done processing cascades for: com.newcompany.business.Forummessage
11:39:30,484 DEBUG Cascades:356 - processing cascades for: com.newcompany.business.Forummessage
11:39:30,484 DEBUG Cascades:381 - cascading to collection: com.newcompany.business.Forummessage.forummessages
11:39:30,484 DEBUG Cascades:364 - done processing cascades for: com.newcompany.business.Forummessage
11:39:30,484 DEBUG Cascades:356 - processing cascades for: com.newcompany.business.Forummessage
11:39:30,484 DEBUG Cascades:364 - done processing cascades for: com.newcompany.business.Forummessage
11:39:30,484 DEBUG SessionImpl:299 - Collection dirty: [com.newcompany.business.Forum.forummessages#4]
11:39:30,484 DEBUG SessionImpl:2328 - Flushing entities and processing referenced collections
11:39:30,484 DEBUG SessionImpl:2424 - Updating entity: [com.newcompany.business.Forum#4]
11:39:30,484 DEBUG SessionImpl:2805 - Collection found: [com.newcompany.business.Forum.forummessages#4], was: [com.newcompany.business.Forum.forummessages#4]
11:39:30,531 DEBUG SessionImpl:2424 - Updating entity: [com.newcompany.business.Forummessage#127]
11:39:30,531 DEBUG SessionImpl:2805 - Collection found: [com.newcompany.business.Forummessage.forummessages#127], was: [com.newcompany.business.Forummessage.forummessages#127]
11:39:30,531 DEBUG SessionImpl:2424 - Updating entity: [com.newcompany.business.Forummessage#128]
11:39:30,531 DEBUG SessionImpl:2805 - Collection found: [com.newcompany.business.Forummessage.forummessages#128], was: [com.newcompany.business.Forummessage.forummessages#128]
11:39:30,531 DEBUG SessionImpl:2424 - Updating entity: [com.newcompany.business.Forummessage#129]
11:39:30,531 DEBUG SessionImpl:2805 - Collection found: [com.newcompany.business.Forummessage.forummessages#129], was: [com.newcompany.business.Forummessage.forummessages#129]
11:39:30,531 DEBUG SessionImpl:2647 - Processing unreferenced collections
11:39:30,531 DEBUG SessionImpl:2658 - Scheduling collection removes/(re)creates/updates
11:39:30,531 DEBUG SessionImpl:2231 - Flushed: 1 insertions, 4 updates, 0 deletions to 5 objects
11:39:30,531 DEBUG SessionImpl:2236 - Flushed: 0 (re)creations, 1 updates, 0 removals to 4 collections
11:39:30,531 DEBUG SessionImpl:2266 - executing flush
11:39:30,531 DEBUG EntityPersister:503 - Inserting entity: [com.newcompany.business.Forummessage#130]
11:39:30,531 DEBUG BatcherImpl:192 - about to open: 0 open PreparedStatements, 0 open ResultSets
11:39:30,531 DEBUG BatcherImpl:226 - prepared statement get: insert into forummessage (message, subject, date_message, notifiy, attach, ref_author, id) values (?, ?, ?, ?, ?, ?, ?)
11:39:30,531 DEBUG BatcherImpl:232 - preparing statement
11:39:30,531 DEBUG EntityPersister:393 - Dehydrating entity: [com.newcompany.business.Forummessage#130]
11:39:30,546 DEBUG BatcherImpl:199 - done closing: 0 open PreparedStatements, 0 open ResultSets
11:39:30,546 DEBUG BatcherImpl:245 - closing statement
11:39:30,546 DEBUG EntityPersister:676 - Updating entity: [com.newcompany.business.Forum#4]
11:39:30,546 DEBUG BatcherImpl:192 - about to open: 0 open PreparedStatements, 0 open ResultSets
11:39:30,546 DEBUG BatcherImpl:226 - prepared statement get: update forum set name=?, ref_conflict=? where id=?
11:39:30,546 DEBUG BatcherImpl:232 - preparing statement
11:39:30,546 DEBUG EntityPersister:393 - Dehydrating entity: [com.newcompany.business.Forum#4]
11:39:30,546 DEBUG Cascades:245 - unsaved-value: 0
11:39:30,546 DEBUG EntityPersister:676 - Updating entity: [com.newcompany.business.Forummessage#127]
11:39:30,546 DEBUG BatcherImpl:199 - done closing: 0 open PreparedStatements, 0 open ResultSets
11:39:30,546 DEBUG BatcherImpl:245 - closing statement
11:39:30,546 DEBUG BatcherImpl:192 - about to open: 0 open PreparedStatements, 0 open ResultSets
11:39:30,546 DEBUG BatcherImpl:226 - prepared statement get: update forummessage set message=?, subject=?, date_message=?, notifiy=?, attach=?, ref_author=? where id=?
11:39:30,546 DEBUG BatcherImpl:232 - preparing statement
11:39:30,546 DEBUG EntityPersister:393 - Dehydrating entity: [com.newcompany.business.Forummessage#127]
11:39:30,562 DEBUG EntityPersister:676 - Updating entity: [com.newcompany.business.Forummessage#128]
11:39:30,562 DEBUG EntityPersister:393 - Dehydrating entity: [com.newcompany.business.Forummessage#128]
11:39:30,562 DEBUG EntityPersister:676 - Updating entity: [com.newcompany.business.Forummessage#129]
11:39:30,562 DEBUG EntityPersister:393 - Dehydrating entity: [com.newcompany.business.Forummessage#129]
11:39:30,562 DEBUG BatcherImpl:199 - done closing: 0 open PreparedStatements, 0 open ResultSets
11:39:30,562 DEBUG BatcherImpl:245 - closing statement
11:39:30,562 DEBUG BasicCollectionPersister:587 - Deleting rows of collection: [com.newcompany.business.Forum.forummessages#4]
11:39:30,562 DEBUG BatcherImpl:192 - about to open: 0 open PreparedStatements, 0 open ResultSets
11:39:30,562 DEBUG BatcherImpl:226 - prepared statement get: update forummessage set ref_forum=null where ref_forum=? and id=?
11:39:30,578 DEBUG BatcherImpl:232 - preparing statement
11:39:30,578 DEBUG BasicCollectionPersister:608 - done deleting collection rows
11:39:30,578 DEBUG BasicCollectionPersister:756 - Updating rows of collection: com.newcompany.business.Forum.forummessages#4
11:39:30,578 DEBUG BasicCollectionPersister:761 - done updating rows
11:39:30,578 DEBUG BasicCollectionPersister:625 - Inserting rows of collection: [com.newcompany.business.Forum.forummessages#4]
11:39:30,578 DEBUG BatcherImpl:199 - done closing: 0 open PreparedStatements, 0 open ResultSets
11:39:30,578 DEBUG BatcherImpl:245 - closing statement
11:39:30,578 DEBUG BatcherImpl:192 - about to open: 0 open PreparedStatements, 0 open ResultSets
11:39:30,578 DEBUG BatcherImpl:226 - prepared statement get: update forummessage set ref_forum=? where id=?
11:39:30,578 DEBUG BatcherImpl:232 - preparing statement
11:39:30,578 DEBUG BasicCollectionPersister:654 - done inserting rows
11:39:30,578 DEBUG BatcherImpl:199 - done closing: 0 open PreparedStatements, 0 open ResultSets
11:39:30,578 DEBUG BatcherImpl:245 - closing statement
11:39:30,578 DEBUG SessionImpl:2678 - post flush
11:39:30,593 DEBUG SessionImpl:507 - transaction completion
11:39:30,593 DEBUG SessionImpl:3250 - disconnecting session
11:39:30,593 DEBUG DriverManagerConnectionProvider:121 - returning connection to pool, pool size: 1
11:39:30,593 DEBUG DriverManagerConnectionProvider:121 - returning connection to pool, pool size: 1
11:39:30,593 DEBUG SessionImpl:507 - transaction completion
11:39:30,593 DEBUG SessionImpl:495 - closing session


Is this a bug, or anything I don't understand in documentation ?

Thank you

J


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 28, 2004 4:48 am 
Newbie

Joined: Thu Oct 09, 2003 6:57 am
Posts: 17
Location: France
Hello,

nobody for help me ?

Thank you

J


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 30, 2004 12:40 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Is first message retrieved when you load the collection and before adding message2 ?
If yes, seems to be :
- and equals/hashCode error

If no :
- some getter/setter error

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 17, 2004 12:26 pm 
Newbie

Joined: Thu Oct 09, 2003 6:57 am
Posts: 17
Location: France
Quote:
Is first message retrieved when you load the collection and before adding message2 ?


0) Initialize collection
1) I create a new message, add it to collection and save
it's ok
2) close session
3) create a second message, add it to collection and save
the ref from the first message to parent is update to null... why ???

Quote:
If yes, seems to be :
- and equals/hashCode error


In this case, It work fine. The ref is not set to null when save a second message

Quote:
If no :
- some getter/setter error


where ?

I spend 2 days on that :-(
Is it a Bug ??

J


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 18, 2004 10:36 am 
Newbie

Joined: Thu Oct 09, 2003 6:57 am
Posts: 17
Location: France
After my interesting discussion on Jira :
http://opensource.atlassian.com/project ... wse/HB-969

Help me....

J


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 18, 2004 12:13 pm 
Newbie

Joined: Thu Oct 09, 2003 6:57 am
Posts: 17
Location: France
Hi,

News about my problem,

If I save message before add it to parent (and save parent), That work fine.
But for me, after read again documents, it's not normal that hibernate set my message ref to parent at null.

any ideas ?

Christian Bauer said me it's not a bug, but for me it's a bug.

J


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 18, 2004 12:38 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
This is not a bug. Use a bidir relationship to achieve commit ordeer properly.
PS: this is in the ref guide

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 19, 2004 3:58 am 
Newbie

Joined: Thu Oct 09, 2003 6:57 am
Posts: 17
Location: France
Ok thank you very much.
Maybe, I don't understand one thing in the ref guide (I read and read again...).
If I read the chapter "6.11. Collection examples", the first example is my case.
If I read "Chapter 16. Example: Parent/Child", I see :
Quote:
Hibernate would issue two SQL statements:


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 19, 2004 1:22 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Not using a bidir will lead to be very careful with the sessiobn.save order of each object. It will then be important since Hibernate cannot know about your not-null constraint

_________________
Emmanuel


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 9 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.