-->
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.  [ 3 posts ] 
Author Message
 Post subject: Auto update bidir. rel. between POJO : best practises?
PostPosted: Thu Dec 18, 2003 8:18 am 
Newbie

Joined: Thu Dec 18, 2003 7:24 am
Posts: 4
Location: Belgium
I have read the Parent/Child documention, the article "Inside explanation of inverse=true", etc.. but could not find any hint about hte best practises to update automatically links between POJOs.

With a bidirectional relation, your code must update both ends, even if one end is enough to update correctly the database.

Suppose we have the following bidirectional relation
Organization 1----* Division

A proper way to "link" a Division to an Organization is as described below:
Code:
Organization o = .... /* code to retrieve the Organization */
Division d = new Division();
o.setDivisions(new HashSet());
o.getDivisions().add(d);
d.setOrganization(o);

session.save(o);
session.save(d);
session.flush();


My question is: could we not add the division automatically to the Organization when we call d.setOrganization() ?

Code:
   public void setOrganization(Organization organization)
    {
        if (this.organization != organization) {
            if (organization != null) organization.addDivision(this);
            else this.organization.removeDivision(this);
            this.organization = organization;
        }   
    }


I tried but got an exception "Failed to lazily initialize a collection". I have enclosed the code and trace.

Could someone tell me what is happening? In the trace, how can we have the NullPointerException, meaning that tempList in net.sf.hibernate.collection.ODMGCollection is null when the trace shows that two rows have been retrieved?

Here is the Code
Code:
/**
*
* @hibernate.class
*     table="ORGANIZATION_T"
*
* @hibernate.discriminator
*     column="CLASS"
*
*
*
*/

public class Organization  {

    // --------------- attributes ---------------------

    private java.lang.String name;
   
   /**
    *
    * @hibernate.property
    *     column="NAME"
    *
    * @hibernate.column
    *     name="NAME"
    *     sql-type="VARCHAR(10)"
    *
    */
    public java.lang.String getName()
    {
        return this.name;
    }
   
    public void setName(java.lang.String newValue)
    {
        this.name = newValue;
    }


    // ------------- relations ------------------

   /**
    *
    * @hibernate.set
    *     role="division"
    *     lazy="true"
    *     cascade="all"
    * @hibernate.collection-key
    *     column="ORGANIZATION_FK"
    * @hibernate.collection-one-to-many
    *     class="be.aubay.qms.model.division.Division"
    */
    public java.util.Collection getDivisions()
    {
        return this.divisions;
    }

    public void setDivisions(java.util.Collection divisions)
    {
        this.divisions = divisions;
    }

    public void addDivision(Object division)
    {
        this.divisions.add(division);
    }

    public void removeDivision(Object division)
    {
        this.divisions.remove(division);
    }

    private java.util.Collection divisions = new java.util.HashSet();   

}


/**
*
* @hibernate.class
*     table="DIVISION_T"
*
* @hibernate.discriminator
*     column="CLASS"
*
*
*
*/

public class Division  {

    // --------------- attributes ---------------------

    private java.lang.String name;
   
   /**
    *
    * @hibernate.property
    *     column="NAME"
    *
    * @hibernate.column
    *     name="NAME"
    *     sql-type="VARCHAR(10)"
    *
    */
    public java.lang.String getName()
    {
        return this.name;
    }
   
    public void setName(java.lang.String newValue)
    {
        this.name = newValue;
    }

    // ------------- relations ------------------

   /**
    *

    *   @hibernate.many-to-one
    *     cascade="all"
    *       column="ORGANIZATION_FK"
    */
    public Organization getOrganization()
    {
        return this.organization;
    }
   
    public void setOrganization(Organization organization)
    {
        if (this.organization != organization) {
            if (organization != null) organization.addDivision(this);
            else this.organization.removeDivision(this);
            this.organization = organization;
        }   
    }

    private be.aubay.qms.model.organization.Organization organization;
}

/**
* <p>
* Factory class.
* Is able to find and create objects of type Organization.
*
*/

public abstract class OrganizationFactory  {
   // ---------------- create method --------------------

   /**
    * Creates a(n) Organization object.
    *
    * @param name
    * @return Organization the created object
    */
    public static Organization create (java.lang.String name)
    {
        Organization object = new Organization();
       
        object.setName (name);

        return object;
    }

    // ---------------- finder methods  ----------------------

    /**
     *
     * Finds Organization object by its primary key.
     *
     */
    public static Organization findByPrimaryKey (net.sf.hibernate.Session sess, int id)
        throws net.sf.hibernate.HibernateException
    {

   Organization object = (Organization) sess.load(Organization.class, new Integer(id));

   return object;
    }


    /**
     *
     * Finds all entities of this type.
     *
     */
    public static java.util.Collection findAll (net.sf.hibernate.Session sess)
        throws net.sf.hibernate.HibernateException
    {
        net.sf.hibernate.Query q = sess.createQuery("from c in class Organization");
        return q.list();
    }
}


/**
* <p>
* Factory class.
* Is able to find and create objects of type Division.
* </p>
*
*/

public abstract class DivisionFactory extends EntityFactory {
   // ---------------- create method --------------------

   /**
    * Creates a(n) Division object.
    *
    * @param name
    * @return Division the created object
    */
    public static Division create (java.lang.String name)
    {
        Division object = new Division();
       
        object.setName (name);

        return object;
    }


    // ---------------- finder methods  ----------------------

    /**
     *
     * Finds Division object by its primary key.
     *
     */
    public static Division findByPrimaryKey (net.sf.hibernate.Session sess, int id)
        throws net.sf.hibernate.HibernateException
    {

   Division object = (Division) sess.load(Division.class, new Integer(id));

   return object;
    }


    /**
     *
     * Finds all entities of this type.
     *
     */
    public static java.util.Collection findAll (net.sf.hibernate.Session sess)
        throws net.sf.hibernate.HibernateException
    {
        net.sf.hibernate.Query q = sess.createQuery("from c in class Division");
        return q.list();
    }

}

import net.sf.hibernate.cfg.Configuration;
import net.sf.hibernate.Session;
import net.sf.hibernate.SessionFactory;
import net.sf.hibernate.HibernateException;

import java.sql.SQLException;
import java.util.Collection;

public class Main {
    private Configuration configuration = null;
    private SessionFactory sessionFactory = null;
    private Session session = null;

    public Main() throws HibernateException {
        init();
    }

    public void init() throws HibernateException {
        configuration = new Configuration().configure();
        sessionFactory = configuration.buildSessionFactory();
        session = sessionFactory.openSession();
    }

    public void close() throws HibernateException {
        session.close();
        session = null;
        sessionFactory.close();
        sessionFactory = null;
        configuration = null;
    }

    private Session getSession() throws HibernateException {
        if (session == null) {
            init();
        }
        return session;
    }

    private void commit() throws HibernateException, SQLException{
         getSession().flush();
         getSession().connection().commit();
    }

    private void rollback() throws HibernateException, SQLException{
        getSession().connection().rollback();
    }

    private void test() throws HibernateException {
        Organization organization1 = OrganizationFactory.findByPrimaryKey(getSession(), 0);

        Division division1 = DivisionFactory.findByPrimaryKey(getSession(), 0);
        Division division2 = DivisionFactory.findByPrimaryKey(getSession(), 1);

        Collection divisions = organization1.getDivisions();
        division1.setOrganization(null);

    }

    private void populate() throws HibernateException, SQLException {

            Organization organization1 = OrganizationFactory.create("Aubay");
            getSession().save(organization1);

            Division division1 = DivisionFactory.create("Dev", "Development");
            division1.setOrganization(organization1);
            getSession().save(division1);

            Division division2 = DivisionFactory.create("HR", "Human Resources");
            division2.setOrganization(organization1);
            getSession().save(division2);
    }


/**
* Call the main once with populate() and then a second time with test() to
* reproduce the error.
*/

    public static void main(String[] args) throws Exception {
        Main main = new Main();

        try {
            //main.populate();
            main.test();
            main.commit();
            main.getSession().connection().commit();
        } catch (Exception e) {
            main.rollback();
            throw e;
        } finally {
            main.close();
        }
    }
}




Trace
Code:
C:\j2sdk1.4.2_02\bin\javaw.exe -classpath C:\_ela\projects\model\build\classes;C:\j2sdk1.4.2_02\jre\lib\charsets.jar;C:\j2sdk1.4.2_02\jre\lib\jce.jar;C:\j2sdk1.4.2_02\jre\lib\jsse.jar;C:\j2sdk1.4.2_02\jre\lib\plugin.jar;C:\j2sdk1.4.2_02\jre\lib\rt.jar;C:\j2sdk1.4.2_02\jre\lib\sunrsasign.jar;C:\j2sdk1.4.2_02\jre\lib\ext\dnsns.jar;C:\j2sdk1.4.2_02\jre\lib\ext\ldapsec.jar;C:\j2sdk1.4.2_02\jre\lib\ext\localedata.jar;C:\j2sdk1.4.2_02\jre\lib\ext\sunjce_provider.jar;C:\_ela\projects\lib\hibernate\cglib-asm.jar;C:\_ela\projects\lib\hibernate\commons-beanutils.jar;C:\_ela\projects\lib\hibernate\commons-collections.jar;C:\_ela\projects\lib\hibernate\commons-lang.jar;C:\_ela\projects\lib\hibernate\commons-logging.jar;C:\_ela\projects\lib\hibernate\dom4j.jar;C:\_ela\projects\lib\hibernate\hibernate2.jar;C:\_ela\projects\lib\hibernate\odmg.jar;C:\_ela\projects\lib\hibernate\xalan.jar;C:\_ela\projects\lib\hsqldb\hsqldb.jar;C:\_ela\projects\lib\andromda\commons-beanutils.jar;C:\_ela\projects\lib\andromda\commons-collections.jar;C:\_ela\projects\lib\andromda\commons-digester.jar;C:\_ela\projects\lib\andromda\commons-logging.jar;C:\_ela\projects\lib\andromda\velocity-dep-1.2.jar;C:\_ela\projects\lib\andromda\jmiuml14di.jar;C:\_ela\projects\lib\andromda\jmiutils.jar;C:\_ela\projects\lib\andromda\andromda.jar;C:\_ela\projects\lib\andromda\log4j.jar;C:\_ela\projects\lib\andromda\jmi.jar Main
log4j:WARN No appenders could be found for logger (net.sf.hibernate.cfg.Environment).
log4j:WARN Please initialize the log4j system properly.
4838 [main] DEBUG net.sf.hibernate.impl.SessionImpl  - loading [be.aubay.qms.model.organization.OrganizationImpl#0]
4848 [main] DEBUG net.sf.hibernate.impl.SessionImpl  - attempting to resolve [be.aubay.qms.model.organization.OrganizationImpl#0]
4848 [main] DEBUG net.sf.hibernate.impl.SessionImpl  - object not resolved in any cache [be.aubay.qms.model.organization.OrganizationImpl#0]
4848 [main] DEBUG net.sf.hibernate.persister.EntityPersister  - Materializing entity: be.aubay.qms.model.organization.OrganizationImpl#0
4858 [main] DEBUG net.sf.hibernate.impl.BatcherImpl  - about to open: 0 open PreparedStatements, 0 open ResultSets
4858 [main] DEBUG net.sf.hibernate.connection.DriverManagerConnectionProvider  - total checked-out connections: 0
4858 [main] DEBUG net.sf.hibernate.connection.DriverManagerConnectionProvider  - using pooled JDBC connection, pool size: 0
4858 [main] DEBUG net.sf.hibernate.impl.SessionFactoryImpl  - prepared statement get: select organiza0_.ID as ID, organiza0_.NAME as NAME, organiza0_.ADDRESS as ADDRESS, organiza0_.CITY as CITY, organiza0_.ZIPCODE as ZIPCODE, organiza0_.COUNTRY as COUNTRY, organiza0_.MAILTO as MAILTO from ORGANIZATION_T organiza0_ where organiza0_.ID=?
Hibernate: select organiza0_.ID as ID, organiza0_.NAME as NAME, organiza0_.ADDRESS as ADDRESS, organiza0_.CITY as CITY, organiza0_.ZIPCODE as ZIPCODE, organiza0_.COUNTRY as COUNTRY, organiza0_.MAILTO as MAILTO from ORGANIZATION_T organiza0_ where organiza0_.ID=?
4878 [main] DEBUG net.sf.hibernate.impl.SessionFactoryImpl  - preparing statement
4888 [main] DEBUG net.sf.hibernate.type.IntegerType  - binding '0' to parameter: 1
5188 [main] DEBUG net.sf.hibernate.loader.Loader  - processing result set
5188 [main] DEBUG net.sf.hibernate.loader.Loader  - result row: 0
5188 [main] DEBUG net.sf.hibernate.loader.Loader  - Initializing object from ResultSet: 0
5198 [main] DEBUG net.sf.hibernate.loader.Loader  - Hydrating entity: be.aubay.qms.model.organization.OrganizationImpl#0
5198 [main] DEBUG net.sf.hibernate.type.StringType  - returning 'Aubay' as column: NAME
5198 [main] DEBUG net.sf.hibernate.type.StringType  - returning '145 rue Gatti de Gamond' as column: ADDRESS
5198 [main] DEBUG net.sf.hibernate.type.StringType  - returning 'Bruxelles' as column: CITY
5198 [main] DEBUG net.sf.hibernate.type.StringType  - returning '1180' as column: ZIPCODE
5198 [main] DEBUG net.sf.hibernate.type.StringType  - returning 'Belgique' as column: COUNTRY
5198 [main] DEBUG net.sf.hibernate.type.StringType  - returning 'aubay@aubay.be' as column: MAILTO
5208 [main] DEBUG net.sf.hibernate.loader.Loader  - done processing result set (1 rows)
5208 [main] DEBUG net.sf.hibernate.impl.BatcherImpl  - done closing: 0 open PreparedStatements, 0 open ResultSets
5208 [main] DEBUG net.sf.hibernate.impl.SessionFactoryImpl  - closing statement
5208 [main] DEBUG net.sf.hibernate.loader.Loader  - total objects hydrated: 1
5208 [main] DEBUG net.sf.hibernate.impl.SessionImpl  - resolving associations for [be.aubay.qms.model.organization.OrganizationImpl#0]
5218 [main] DEBUG net.sf.hibernate.impl.SessionImpl  - done materializing entity [be.aubay.qms.model.organization.OrganizationImpl#0]
5228 [main] DEBUG net.sf.hibernate.impl.SessionImpl  - loading [be.aubay.qms.model.division.DivisionImpl#0]
5228 [main] DEBUG net.sf.hibernate.impl.SessionImpl  - attempting to resolve [be.aubay.qms.model.division.DivisionImpl#0]
5228 [main] DEBUG net.sf.hibernate.impl.SessionImpl  - object not resolved in any cache [be.aubay.qms.model.division.DivisionImpl#0]
5228 [main] DEBUG net.sf.hibernate.persister.EntityPersister  - Materializing entity: be.aubay.qms.model.division.DivisionImpl#0
5228 [main] DEBUG net.sf.hibernate.impl.BatcherImpl  - about to open: 0 open PreparedStatements, 0 open ResultSets
5228 [main] DEBUG net.sf.hibernate.impl.SessionFactoryImpl  - prepared statement get: select division0_.ID as ID, division0_.NAME as NAME, division0_.DESCRIPTION as DESCRIPT4_, division0_.ORGANIZATION_FK as ORGANIZA5_ from DIVISION_T division0_ where division0_.ID=?
Hibernate: select division0_.ID as ID, division0_.NAME as NAME, division0_.DESCRIPTION as DESCRIPT4_, division0_.ORGANIZATION_FK as ORGANIZA5_ from DIVISION_T division0_ where division0_.ID=?
5238 [main] DEBUG net.sf.hibernate.impl.SessionFactoryImpl  - preparing statement
5238 [main] DEBUG net.sf.hibernate.type.IntegerType  - binding '0' to parameter: 1
5248 [main] DEBUG net.sf.hibernate.loader.Loader  - processing result set
5248 [main] DEBUG net.sf.hibernate.loader.Loader  - result row: 0
5248 [main] DEBUG net.sf.hibernate.loader.Loader  - Initializing object from ResultSet: 0
5258 [main] DEBUG net.sf.hibernate.loader.Loader  - Hydrating entity: be.aubay.qms.model.division.DivisionImpl#0
5258 [main] DEBUG net.sf.hibernate.type.StringType  - returning 'Dev' as column: NAME
5258 [main] DEBUG net.sf.hibernate.type.StringType  - returning 'Development' as column: DESCRIPT4_
5258 [main] DEBUG net.sf.hibernate.type.IntegerType  - returning '0' as column: ORGANIZA5_
5258 [main] DEBUG net.sf.hibernate.loader.Loader  - done processing result set (1 rows)
5258 [main] DEBUG net.sf.hibernate.impl.BatcherImpl  - done closing: 0 open PreparedStatements, 0 open ResultSets
5258 [main] DEBUG net.sf.hibernate.impl.SessionFactoryImpl  - closing statement
5258 [main] DEBUG net.sf.hibernate.loader.Loader  - total objects hydrated: 1
5258 [main] DEBUG net.sf.hibernate.impl.SessionImpl  - resolving associations for [be.aubay.qms.model.division.DivisionImpl#0]
5258 [main] DEBUG net.sf.hibernate.impl.SessionImpl  - loading [be.aubay.qms.model.organization.Organization#0]
5268 [main] DEBUG net.sf.hibernate.impl.SessionImpl  - attempting to resolve [be.aubay.qms.model.organization.Organization#0]
5268 [main] DEBUG net.sf.hibernate.impl.SessionImpl  - resolved object in session cache [be.aubay.qms.model.organization.Organization#0]
5268 [main] DEBUG net.sf.hibernate.impl.SessionImpl  - initializing collection [be.aubay.qms.model.organization.Organization.divisions#0]
5268 [main] DEBUG net.sf.hibernate.impl.BatcherImpl  - about to open: 0 open PreparedStatements, 0 open ResultSets
5268 [main] DEBUG net.sf.hibernate.impl.SessionFactoryImpl  - prepared statement get: select division0_.ID as ID__, division0_.ID as ID, division0_.CLASS as CLASS, division0_.NAME as NAME, division0_.DESCRIPTION as DESCRIPT4_, division0_.ORGANIZATION_FK as ORGANIZA5_ from DIVISION_T division0_ where division0_.ORGANIZATION_FK=?
Hibernate: select division0_.ID as ID__, division0_.ID as ID, division0_.CLASS as CLASS, division0_.NAME as NAME, division0_.DESCRIPTION as DESCRIPT4_, division0_.ORGANIZATION_FK as ORGANIZA5_ from DIVISION_T division0_ where division0_.ORGANIZATION_FK=?
5268 [main] DEBUG net.sf.hibernate.impl.SessionFactoryImpl  - preparing statement
5278 [main] DEBUG net.sf.hibernate.type.IntegerType  - binding '0' to parameter: 1
5288 [main] DEBUG net.sf.hibernate.loader.Loader  - processing result set
5288 [main] DEBUG net.sf.hibernate.type.IntegerType  - returning '0' as column: ID
5288 [main] DEBUG net.sf.hibernate.loader.Loader  - result row: 0
5298 [main] DEBUG net.sf.hibernate.type.IntegerType  - returning '0' as column: ID__
5298 [main] DEBUG net.sf.hibernate.impl.SessionImpl  - loading [be.aubay.qms.model.division.Division#0]
5298 [main] DEBUG net.sf.hibernate.impl.SessionImpl  - attempting to resolve [be.aubay.qms.model.division.Division#0]
5298 [main] DEBUG net.sf.hibernate.impl.SessionImpl  - resolved object in session cache [be.aubay.qms.model.division.Division#0]
5298 [main] DEBUG net.sf.hibernate.type.IntegerType  - returning '1' as column: ID
5298 [main] DEBUG net.sf.hibernate.loader.Loader  - result row: 1
5298 [main] DEBUG net.sf.hibernate.type.StringType  - returning 'DivisionImpl' as column: CLASS
5298 [main] DEBUG net.sf.hibernate.loader.Loader  - Initializing object from ResultSet: 1
5298 [main] DEBUG net.sf.hibernate.loader.Loader  - Hydrating entity: be.aubay.qms.model.division.DivisionImpl#1
5308 [main] DEBUG net.sf.hibernate.type.StringType  - returning 'HR' as column: NAME
5308 [main] DEBUG net.sf.hibernate.type.StringType  - returning 'Human Resources' as column: DESCRIPT4_
5308 [main] DEBUG net.sf.hibernate.type.IntegerType  - returning '0' as column: ORGANIZA5_
5308 [main] DEBUG net.sf.hibernate.type.IntegerType  - returning '1' as column: ID__
5308 [main] DEBUG net.sf.hibernate.impl.SessionImpl  - loading [be.aubay.qms.model.division.Division#1]
5308 [main] DEBUG net.sf.hibernate.impl.SessionImpl  - attempting to resolve [be.aubay.qms.model.division.Division#1]
5308 [main] DEBUG net.sf.hibernate.impl.SessionImpl  - resolved object in session cache [be.aubay.qms.model.division.Division#1]
5308 [main] DEBUG net.sf.hibernate.loader.Loader  - done processing result set (2 rows)
5308 [main] DEBUG net.sf.hibernate.impl.BatcherImpl  - done closing: 0 open PreparedStatements, 0 open ResultSets
5308 [main] DEBUG net.sf.hibernate.impl.SessionFactoryImpl  - closing statement
5308 [main] DEBUG net.sf.hibernate.loader.Loader  - total objects hydrated: 1
5308 [main] DEBUG net.sf.hibernate.impl.SessionImpl  - resolving associations for [be.aubay.qms.model.division.DivisionImpl#1]
5318 [main] DEBUG net.sf.hibernate.impl.SessionImpl  - loading [be.aubay.qms.model.organization.Organization#0]
5318 [main] DEBUG net.sf.hibernate.impl.SessionImpl  - attempting to resolve [be.aubay.qms.model.organization.Organization#0]
5318 [main] DEBUG net.sf.hibernate.impl.SessionImpl  - resolved object in session cache [be.aubay.qms.model.organization.Organization#0]
5318 [main] DEBUG net.sf.hibernate.impl.SessionImpl  - initializing collection [be.aubay.qms.model.organization.Organization.divisions#0]
5318 [main] DEBUG net.sf.hibernate.impl.BatcherImpl  - about to open: 0 open PreparedStatements, 0 open ResultSets
5318 [main] DEBUG net.sf.hibernate.impl.SessionFactoryImpl  - prepared statement get: select division0_.ID as ID__, division0_.ID as ID, division0_.CLASS as CLASS, division0_.NAME as NAME, division0_.DESCRIPTION as DESCRIPT4_, division0_.ORGANIZATION_FK as ORGANIZA5_ from DIVISION_T division0_ where division0_.ORGANIZATION_FK=?
Hibernate: select division0_.ID as ID__, division0_.ID as ID, division0_.CLASS as CLASS, division0_.NAME as NAME, division0_.DESCRIPTION as DESCRIPT4_, division0_.ORGANIZATION_FK as ORGANIZA5_ from DIVISION_T division0_ where division0_.ORGANIZATION_FK=?
5318 [main] DEBUG net.sf.hibernate.impl.SessionFactoryImpl  - preparing statement
5328 [main] DEBUG net.sf.hibernate.type.IntegerType  - binding '0' to parameter: 1
5348 [main] DEBUG net.sf.hibernate.loader.Loader  - processing result set
5358 [main] DEBUG net.sf.hibernate.type.IntegerType  - returning '0' as column: ID
5358 [main] DEBUG net.sf.hibernate.loader.Loader  - result row: 0
5358 [main] DEBUG net.sf.hibernate.type.IntegerType  - returning '0' as column: ID__
5358 [main] DEBUG net.sf.hibernate.impl.SessionImpl  - loading [be.aubay.qms.model.division.Division#0]
5358 [main] DEBUG net.sf.hibernate.impl.SessionImpl  - attempting to resolve [be.aubay.qms.model.division.Division#0]
5358 [main] DEBUG net.sf.hibernate.impl.SessionImpl  - resolved object in session cache [be.aubay.qms.model.division.Division#0]
5358 [main] DEBUG net.sf.hibernate.type.IntegerType  - returning '1' as column: ID
5358 [main] DEBUG net.sf.hibernate.loader.Loader  - result row: 1
5358 [main] DEBUG net.sf.hibernate.type.IntegerType  - returning '1' as column: ID__
5358 [main] DEBUG net.sf.hibernate.impl.SessionImpl  - loading [be.aubay.qms.model.division.Division#1]
5358 [main] DEBUG net.sf.hibernate.impl.SessionImpl  - attempting to resolve [be.aubay.qms.model.division.Division#1]
5358 [main] DEBUG net.sf.hibernate.impl.SessionImpl  - resolved object in session cache [be.aubay.qms.model.division.Division#1]
5369 [main] DEBUG net.sf.hibernate.loader.Loader  - done processing result set (2 rows)
5369 [main] DEBUG net.sf.hibernate.impl.BatcherImpl  - done closing: 0 open PreparedStatements, 0 open ResultSets
5369 [main] DEBUG net.sf.hibernate.impl.SessionFactoryImpl  - closing statement
5369 [main] DEBUG net.sf.hibernate.loader.Loader  - total objects hydrated: 0
5369 [main] DEBUG net.sf.hibernate.impl.SessionImpl  - done materializing entity [be.aubay.qms.model.division.DivisionImpl#1]
5369 [main] ERROR net.sf.hibernate.collection.PersistentCollection  - Failed to lazily initialize a collection
java.lang.NullPointerException
   at java.util.AbstractCollection.addAll(AbstractCollection.java:317)
   at net.sf.hibernate.collection.Set.endRead(Set.java:252)
   at net.sf.hibernate.loader.Loader.doFind(Loader.java:200)
   at net.sf.hibernate.loader.Loader.loadCollection(Loader.java:602)
   at net.sf.hibernate.loader.OneToManyLoader.initialize(OneToManyLoader.java:102)
   at net.sf.hibernate.impl.SessionImpl.initialize(SessionImpl.java:2897)
   at net.sf.hibernate.collection.PersistentCollection.initialize(PersistentCollection.java:151)
   at net.sf.hibernate.collection.PersistentCollection.write(PersistentCollection.java:72)
   at net.sf.hibernate.collection.Set.add(Set.java:162)
   at be.aubay.qms.model.organization.Organization.addDivision(Organization.java:196)
   at be.aubay.qms.model.division.Division.setOrganization(Division.java:92)
   at be.aubay.qms.model.division.DivisionImplMetaClass13.setPropertyValues(<generated>)
   at net.sf.hibernate.persister.AbstractEntityPersister.setPropertyValues(AbstractEntityPersister.java:162)
   at net.sf.hibernate.impl.SessionImpl.initializeEntity(SessionImpl.java:1961)
   at net.sf.hibernate.loader.Loader.doFind(Loader.java:196)
   at net.sf.hibernate.loader.Loader.loadEntity(Loader.java:587)
   at net.sf.hibernate.loader.EntityLoader.load(EntityLoader.java:42)
   at net.sf.hibernate.persister.EntityPersister.load(EntityPersister.java:396)
   at net.sf.hibernate.impl.SessionImpl.doLoad(SessionImpl.java:1889)
   at net.sf.hibernate.impl.SessionImpl.doLoadByClass(SessionImpl.java:1757)
   at net.sf.hibernate.impl.SessionImpl.load(SessionImpl.java:1688)
   at be.aubay.qms.model.division.DivisionFactory.findByPrimaryKey(DivisionFactory.java:53)
   at Main.test(Main.java:70)
   at Main.main(Main.java:126)
5399 [main] DEBUG net.sf.hibernate.impl.SessionImpl  - closing session
5409 [main] DEBUG net.sf.hibernate.impl.SessionImpl  - disconnecting session
5409 [main] DEBUG net.sf.hibernate.connection.DriverManagerConnectionProvider  - returning connection to pool, pool size: 1
5409 [main] DEBUG net.sf.hibernate.impl.SessionImpl  - transaction completion
5409 [main] INFO net.sf.hibernate.impl.SessionFactoryImpl  - closing
5899 [main] INFO net.sf.hibernate.connection.DriverManagerConnectionProvider  - cleaning up connection pool: jdbc:hsqldb:hsql://localhost
java.lang.NullPointerException
   at java.util.AbstractCollection.addAll(AbstractCollection.java:317)
   at net.sf.hibernate.collection.Set.endRead(Set.java:252)
   at net.sf.hibernate.loader.Loader.doFind(Loader.java:200)
   at net.sf.hibernate.loader.Loader.loadCollection(Loader.java:602)
   at net.sf.hibernate.loader.OneToManyLoader.initialize(OneToManyLoader.java:102)
   at net.sf.hibernate.impl.SessionImpl.initialize(SessionImpl.java:2897)
   at net.sf.hibernate.collection.PersistentCollection.initialize(PersistentCollection.java:151)
   at net.sf.hibernate.collection.PersistentCollection.write(PersistentCollection.java:72)
   at net.sf.hibernate.collection.Set.add(Set.java:162)
   at be.aubay.qms.model.organization.Organization.addDivision(Organization.java:196)
   at be.aubay.qms.model.division.Division.setOrganization(Division.java:92)
   at be.aubay.qms.model.division.DivisionImplMetaClass13.setPropertyValues(<generated>)
   at net.sf.hibernate.persister.AbstractEntityPersister.setPropertyValues(AbstractEntityPersister.java:162)
   at net.sf.hibernate.impl.SessionImpl.initializeEntity(SessionImpl.java:1961)
   at net.sf.hibernate.loader.Loader.doFind(Loader.java:196)
   at net.sf.hibernate.loader.Loader.loadEntity(Loader.java:587)
   at net.sf.hibernate.loader.EntityLoader.load(EntityLoader.java:42)
   at net.sf.hibernate.persister.EntityPersister.load(EntityPersister.java:396)
   at net.sf.hibernate.impl.SessionImpl.doLoad(SessionImpl.java:1889)
   at net.sf.hibernate.impl.SessionImpl.doLoadByClass(SessionImpl.java:1757)
   at net.sf.hibernate.impl.SessionImpl.load(SessionImpl.java:1688)
   at be.aubay.qms.model.division.DivisionFactory.findByPrimaryKey(DivisionFactory.java:53)
   at Main.test(Main.java:70)
   at Main.main(Main.java:126)
rethrown as net.sf.hibernate.LazyInitializationException: [color=red]Failed to lazily initialize a collection[/color]
   at net.sf.hibernate.collection.PersistentCollection.initialize(PersistentCollection.java:163)
   at net.sf.hibernate.collection.PersistentCollection.write(PersistentCollection.java:72)
   at net.sf.hibernate.collection.Set.add(Set.java:162)
   at be.aubay.qms.model.organization.Organization.addDivision(Organization.java:196)
   at be.aubay.qms.model.division.Division.setOrganization(Division.java:92)
   at be.aubay.qms.model.division.DivisionImplMetaClass13.setPropertyValues(<generated>)
   at net.sf.hibernate.persister.AbstractEntityPersister.setPropertyValues(AbstractEntityPersister.java:162)
   at net.sf.hibernate.impl.SessionImpl.initializeEntity(SessionImpl.java:1961)
   at net.sf.hibernate.loader.Loader.doFind(Loader.java:196)
   at net.sf.hibernate.loader.Loader.loadEntity(Loader.java:587)
   at net.sf.hibernate.loader.EntityLoader.load(EntityLoader.java:42)
   at net.sf.hibernate.persister.EntityPersister.load(EntityPersister.java:396)
   at net.sf.hibernate.impl.SessionImpl.doLoad(SessionImpl.java:1889)
   at net.sf.hibernate.impl.SessionImpl.doLoadByClass(SessionImpl.java:1757)
   at net.sf.hibernate.impl.SessionImpl.load(SessionImpl.java:1688)
   at be.aubay.qms.model.division.DivisionFactory.findByPrimaryKey(DivisionFactory.java:53)
   at Main.test(Main.java:70)
   at Main.main(Main.java:126)
Caused by: java.lang.NullPointerException
   at java.util.AbstractCollection.addAll(AbstractCollection.java:317)
   at net.sf.hibernate.collection.Set.endRead(Set.java:252)
   at net.sf.hibernate.loader.Loader.doFind(Loader.java:200)
   at net.sf.hibernate.loader.Loader.loadCollection(Loader.java:602)
   at net.sf.hibernate.loader.OneToManyLoader.initialize(OneToManyLoader.java:102)
   at net.sf.hibernate.impl.SessionImpl.initialize(SessionImpl.java:2897)
   at net.sf.hibernate.collection.PersistentCollection.initialize(PersistentCollection.java:151)
   ... 17 more
rethrown as net.sf.hibernate.PropertyAccessException: exception setting property value with CGLIB (set hibernate.cglib.use_reflection_optimizer=false for more info): Failed to lazily initialize a collection setter of be.aubay.qms.model.division.DivisionImpl.?
   at net.sf.hibernate.persister.AbstractEntityPersister.setPropertyValues(AbstractEntityPersister.java:167)
   at net.sf.hibernate.impl.SessionImpl.initializeEntity(SessionImpl.java:1961)
   at net.sf.hibernate.loader.Loader.doFind(Loader.java:196)
   at net.sf.hibernate.loader.Loader.loadEntity(Loader.java:587)
   at net.sf.hibernate.loader.EntityLoader.load(EntityLoader.java:42)
   at net.sf.hibernate.persister.EntityPersister.load(EntityPersister.java:396)
   at net.sf.hibernate.impl.SessionImpl.doLoad(SessionImpl.java:1889)
   at net.sf.hibernate.impl.SessionImpl.doLoadByClass(SessionImpl.java:1757)
   at net.sf.hibernate.impl.SessionImpl.load(SessionImpl.java:1688)
   at be.aubay.qms.model.division.DivisionFactory.findByPrimaryKey(DivisionFactory.java:53)
   at Main.test(Main.java:70)
   at Main.main(Main.java:126)
Caused by: net.sf.hibernate.LazyInitializationException: Failed to lazily initialize a collection
   at net.sf.hibernate.collection.PersistentCollection.initialize(PersistentCollection.java:163)
   at net.sf.hibernate.collection.PersistentCollection.write(PersistentCollection.java:72)
   at net.sf.hibernate.collection.Set.add(Set.java:162)
   at be.aubay.qms.model.organization.Organization.addDivision(Organization.java:196)
   at be.aubay.qms.model.division.Division.setOrganization(Division.java:92)
   at be.aubay.qms.model.division.DivisionImplMetaClass13.setPropertyValues(<generated>)
   at net.sf.hibernate.persister.AbstractEntityPersister.setPropertyValues(AbstractEntityPersister.java:162)
   ... 11 more
Caused by: java.lang.NullPointerException
   at java.util.AbstractCollection.addAll(AbstractCollection.java:317)
   at net.sf.hibernate.collection.Set.endRead(Set.java:252)
   at net.sf.hibernate.loader.Loader.doFind(Loader.java:200)
   at net.sf.hibernate.loader.Loader.loadCollection(Loader.java:602)
   at net.sf.hibernate.loader.OneToManyLoader.initialize(OneToManyLoader.java:102)
   at net.sf.hibernate.impl.SessionImpl.initialize(SessionImpl.java:2897)
   at net.sf.hibernate.collection.PersistentCollection.initialize(PersistentCollection.java:151)
   ... 17 more
Exception in thread "main" Process terminated with exit code 1


_________________
Eric.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 18, 2003 8:31 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Have a look at http://www.hibernate.org/Documentation/InsideExplanationOfInverseTrue

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 22, 2003 6:26 am 
Newbie

Joined: Thu Dec 18, 2003 7:24 am
Posts: 4
Location: Belgium
Thanks Emmanuel, but I already read this article as mentionned in my previous post. I opened a new topic that explains more clearly the problem I am facing (http://forum.hibernate.org/viewtopic.php?t=926613).

This topic can then be closed.

_________________
Eric.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.