facebook

Newbie Question involving Hibernate

  1. MyEclipse Archived
  2.  > 
  3. Database Tools (DB Explorer, Hibernate, etc.)
Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #283413 Reply

    Russ
    Member

    Okay, first let me apologize for such a basic question…..

    What I have done is created a MYSQL database. I have used ME to reverse engineer the source code for Hibernate and Spring (DAOs). I have been trying to follow the ME Hibernate and Spring Tutorial as an example. I think I am getting pass the Spring errors and now I am trying to get pass the Hibernate errors.

    I am getting the following error when I attempt to persist data in the datbase

    
    
    Exception in thread "main" org.springframework.orm.hibernate3.HibernateSystemException: reassociated object has dirty collection reference (or an array); nested exception is org.hibernate.HibernateException: reassociated object has dirty collection reference (or an array)
    Caused by: org.hibernate.HibernateException: reassociated object has dirty collection reference (or an array)
        at org.hibernate.event.def.OnLockVisitor.processCollection(OnLockVisitor.java:66)
    

    The line of code that is failing is:

    
    getHibernateTemplate().lock(instance, LockMode.NONE);
    

    Can anyone explain what I am missing? Any suggestions would be appreciated.

    Russ

    #283434 Reply

    Loyal Water
    Member

    Russ,
    I’m not sure what this error suggests. You should cross post on the hibernate forums as well.

    #283489 Reply

    Russ
    Member

    I am so new I am at a lost on how to fix this simple issue.

    What I have done is created a MYSQL database with all the relationships. There are 3 Xref tables (Many to Many). One table uses a composite for the primary key. All the other tables are very simple relationships. I have used MyEclipse to reverse engineer the source code for Hibernate and Spring (DAOs). I used the Toutorial on how this should be accomplished.

    I corrected all the Spring errors and now I am onto the Hibernate error. I have updated the hbm.xml file adding the cascade styles for each class and changed the generator for each primary key to native (except for the composite key). That’s all the changes for the hbm.xl files

    I made the first trial as simple as possible by only persisting one object with NO relationships (empty HashSet). I have turned on all logging in hopes of discovering any hidden errors. This action did not highlight any additional errors. I am still getting this error:

    
    
    --attach failed 
    
    org.springframework.orm.hibernate3.HibernateSystemException: reassociated object has dirty collection reference (or an array); nested exception is org.hibernate.HibernateException: reassociated object has dirty collection reference (or an array) Caused by:  org.hibernate.HibernateException: reassociated object has dirty collection reference (or an array)             at org.hibernate.event.def.OnLockVisitor.processCollection(OnLockVisitor.java:66)             at org.hibernate.event.def.AbstractVisitor.processValue(AbstractVisitor.java:101)             at org.hibernate.event.def.AbstractVisitor.processValue(AbstractVisitor.java:61)             at org.hibernate.event.def.AbstractVisitor.processEntityPropertyValues(AbstractVisitor.java:55)             at org.hibernate.event.def.AbstractVisitor.process(AbstractVisitor.java:123)             at org.hibernate.event.def.AbstractReassociateEventListener.reassociate(AbstractReassociateEventListener.java:78)             at org.hibernate.event.def.DefaultLockEventListener.onLock(DefaultLockEventListener.java:59)             at org.hibernate.impl.SessionImpl.fireLock(SessionImpl.java:579)             at org.hibernate.impl.SessionImpl.lock(SessionImpl.java:571)             at org.springframework.orm.hibernate3.HibernateTemplate$10.doInHibernate(HibernateTemplate.java:614)             at org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:372)             at org.springframework.orm.hibernate3.HibernateTemplate.lock(HibernateTemplate.java:612)             at jtdi.metadata.orm.dao.JtdiDocumentDAO.attachClean(JtdiDocumentDAO.java:167)             at jtdi.metadata.persistence.bean.JtdiDocumentBean.addJtdiDocument(JtdiDocumentBean.java:19)             at jtdi.metadata.business.helper.JtdiDocumentBusinessHelper.persistJtdiDocument(JtdiDocumentBusinessHelper.java:76)             at jtdi.metadata.business.helper.JtdiDocumentBusinessHelper.main(JtdiDocumentBusinessHelper.java:131) 
    

    When I go looking at the Hibernate source code, I see this information concerning Hibernate’s OnLockVisitor

    
    
     if ( collection == null ) {
          //do nothing 
    } else if ( collection instanceof PersistentCollection ) { 
    ....... // Do something 
    } else {
     * // brand new collection
        //TODO: or an array!! we can't lock objects with arrays now?? 
    throw new HibernateException( "reassociated object has dirty collection reference (or an array)" );* } 
    

    As you can see for yourself this situation occurs if your collection is not a PersistentCollection (i.e. if you have replaced the collection completely after obtaining the object from the DB) or is you use array (not very likely). Because I have not replaced or created any collections, I am at a lost on how this could be. Therefore, I opine the reverse engineering (bottom-up approach) is faulty when it comes to dealing with XRef tables or Composite Primary Keys.

    Any suggestions would be greatly appreciated.

    Russ

    #283493 Reply

    Russ
    Member

    The tool I am using (MyEclipse) generates all the code for the DAOs. This is the Spring portion of ME. The DocumentDAO extends the HibernateSupportDAO. Code generation handles most of the required method implementation.

    I changed my code to use different aspects of the DAO. One change cause the SQL generated call for UPDATE of the table. It returned zero record updated because no record was in the database with the id of 1. Actually the table is empty. When I tried the save function the SQL generated was an INSERT statement. In both cases no data was stored in the database.

    The lock method obtains the specific lock level upon the given object, implicitly checking whether the corresponding database entry still exist. In my case, the lock mode is none. The database is empty so there is no corresponding database entry.

    I have troubleshot the Hibernate connection within the IDE; I have no problem working with the database.

    Any suggestions would be appreciated.

    Russ

Viewing 4 posts - 1 through 4 (of 4 total)
Reply To: Newbie Question involving Hibernate

You must be logged in to post in the forum log in