-->
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.  [ 12 posts ] 
Author Message
 Post subject: Parent / child retrieval of object tree not working?
PostPosted: Wed Oct 22, 2003 3:32 pm 
Newbie

Joined: Sun Oct 05, 2003 5:43 pm
Posts: 10
Location: Atlanta
After reading the parent child section of the manual several times, and trying several different iterations I am at loss how what is wrong. If anyone can shed some light on the problem it would be great !!!

Real simply we want to create a parent, with a set of children, and then retrieve the parent and iterate through the children. When we attempt this the parent and children are persisted properly, however upon retrieving the parent, the children are not retrieved as well.

----------------------------

I have simplified the problem down to two classes a parent and child class. The parent has a set of children, each child has a name, and each parent has a refId. Both Parents and Children are idenfied by BigDecimals, and we created our own class to create the ids (which works fine).

In our real example these objects are more complex representing purchase orders, line items etc.

The following is the hibernate configuration:

<hibernate-mapping default-cascade="all">

<class name="com.pts.ietms.data.om.Parent" table="Parent">
<id name="id" type="big_decimal" unsaved-value="null">
<column name="id" sql-type="NUMBER(38)"/>
<generator class="testHibernate.HKeyGenerator"/>
</id>
<property name="refId" type="string" />
<set name="children" table="children" inverse="true" cascade="all-delete-orphan">
<key >
<column name="id" sql-type="NUMBER(38)" />
</key>
<one-to-many class="com.pts.ietms.data.om.Child"/>
</set>
</class>

<class name="com.pts.ietms.data.om.Child" table="Child">
<id name="id" type="big_decimal" unsaved-value="null">
<column name="id" sql-type="NUMBER(38)"/>
<generator class="testHibernate.HKeyGenerator"/>
</id>

<many-to-one name="parent" >
<column name="parent_id" sql-type="NUMBER(38)" not-null="true" />
</many-to-one>

<property name="name" type="string" />
</class>


Our quick Test code excluding set up etc is:


Set children = new HashSet();
Parent p = new Parent("Parent1",children);

Child c = new Child("Child1");
p.addChild(c);
c = new Child("Child2");
p.addChild(c);


System.out.println("Saving parent");
session.save(p);
session.flush();


session.connection().commit();
session.close();

session = null;
p=null;
c=null;


System.out.println("Retrieving Parent");
session = sessions.openSession();
Query q = session.createQuery("from Parent p where p.refId = ?");
q.setString(0, "Parent1");
p = (Parent) q.uniqueResult();

if (p != null)
{
System.out.println("Got Parent:" + p.getRefId());
System.out.println("With " + p.getChildren().size() + " children");

Iterator it = p.getChildren().iterator();

while (it.hasNext())
{
System.out.println("Child:" + ((Child)(it.next())).getName());
}
}


session.close();
session= null;


... the output from hibernate is:

Saving parent
Hibernate: insert into Parent (refId, id) values (?, ?)
Hibernate: insert into Child (parent_id, name, id) values (?, ?, ?)
Retrieving Parent
Hibernate: select parent0_.id as id, parent0_.refId as refId from Parent parent0_ where (parent0_.refId=? )
Hibernate: select child0_.id as id__, parent1_.id as id0_, parent1_.refId as refId0_, child0_.id as id1_, child0_.parent_id as parent_id1_, child0_.name as name1_ from Child child0_, Parent parent1_ where child0_.id=? and child0_.parent_id=parent1_.id(+)
Got Parent:Parent1
With 0 children


As you can see ... two select statements are actually executed, and one would suspect that we would be able to simply iterate through the children... but instead the size is zero?

Any ideas?


Here is the simple parent and child classes:

public class Child
{

private BigDecimal id;
private String name;
private Parent parent;

public Child()
{
}

public Child(String name)
{
this.name = name;
}

public String getName()
{
return name;
}

public Parent getParent()
{
return parent;
}

public void setName(String string)
{
name = string;
}

public void setParent(Parent parent)
{
this.parent = parent;
}

public BigDecimal getId()
{
return id;
}

public void setId(BigDecimal decimal)
{
id = decimal;
}

}



public class Parent
{
private String refId;
private Set children;
private BigDecimal id;


public Parent()
{
}


public Parent(String refId,Set children)
{
this.children = children;
this.refId = refId;
}


public void addChild(Child child)
{
child.setParent(this);
children.add(child);
}


public Set getChildren()
{
return children;
}

public void setChildren(Set children)
{
this.children = children;
}


public BigDecimal getId()
{
return id;
}


public void setId(BigDecimal decimal)
{
id = decimal;
}

public String getRefId()
{
return refId;
}

public void setRefId(String string)
{
refId = string;
}

}


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 22, 2003 4:48 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Does your HKeyGenerator works fine ?
Is parent id and child fk to parent properly set on DB after flush ?

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 22, 2003 4:54 pm 
Newbie

Joined: Sun Oct 05, 2003 5:43 pm
Posts: 10
Location: Atlanta
Yes the objects all persist properly, keys are generated properly, and match. Database schema insured through FK relationship between parent and child


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 22, 2003 11:08 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
Is there really an association table named 'children' in your schema?

If so, the elements of the set need to be defined using the many-to-many mapping, not one-to-many.

The reason I ask if this table exists, is because the generated sql you pasted shows the query referencing a column PARENT_ID on the CHILD table, but your database does not complain.


Top
 Profile  
 
 Post subject: generated sql
PostPosted: Thu Oct 23, 2003 11:29 am 
Newbie

Joined: Sun Oct 05, 2003 5:43 pm
Posts: 10
Location: Atlanta
Ok, some more trail and error testing...
We tried getting rid of our BigDecimal generator and got the same results with Integer values using the hilo generator. (we put it back since it had no effect). Here is all the code our results should be easy to reproduce given this information. We have been working on this now for a few days and are about to abandon hibernate for JDO as this issue is effecting every class relationship we pretty much have, and we have made no progress... short of bringing down the source for hibernate and tracing through the code to find the issue (would take us a long time) I am not sure where else to go.

Generated SQL for Tables:

Code:
create table Parent (
   id NUMBER(38) not null,
   refId VARCHAR2(255),
   primary key (id)
)

create table Child (
   id NUMBER(38) not null,
   parent_id NUMBER(38) not null,
   name VARCHAR2(255),
   primary key (id)
)


Parent Class
Code:
package com.pts.ietms.data.om;

import java.util.*;
import java.math.BigDecimal;
import java.io.Serializable;

import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.ToStringBuilder;


/**
* Parent
*/
public class Parent implements Serializable
{
    private String refId;
    private Set children;
    private BigDecimal id;


    public Parent()
    {
    }


    public Parent(String refId,Set children)
    {
   this.children = children;
   this.refId = refId;
    }


    public void addChild(Child child)
    {
   child.setParent(this);
   children.add(child);
    }


    public Set getChildren()
    {
   return Collections.unmodifiableSet(children);
     }

    public void setChildren(Set children)
    {
   this.children = children;
    }


    public BigDecimal getId()
    {
   return id;
    }


    public void setId(BigDecimal id)
    {
   this.id = id;
    }

    /**
     * @return
    */
    public String getRefId()
        {
       return refId;
        }

    /**
     * @param string
    */
    public void setRefId(String string)
        {
       refId = string;
        }

    public String toString()
    {
   return "Parent:" + refId;
    }

    public boolean equals(Object other) {
   if ( !(other instanceof Parent) ) return false;
   Parent castOther = (Parent) other;
   return new EqualsBuilder()
       .append(this.getId(), castOther.getId())
       .isEquals();
    }

    public int hashCode() {
   return new HashCodeBuilder()
       .append(getId())
       .toHashCode();
    }


}


Child Class:

Code:
package com.pts.ietms.data.om;

import java.math.BigDecimal;
import java.io.Serializable;

import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.ToStringBuilder;


public class Child implements Serializable
{

   private BigDecimal id;
   private String name;
   private Parent parent;

   public Child()
   {
   }

   public Child(String name)
   {
      this.name = name;
   }

   public String getName()
   {
      return name;
   }

   public Parent getParent()
   {
      return parent;
   }

   public void setName(String string)
   {
      name = string;
   }

   public void setParent(Parent parent)
   {
      this.parent = parent;
   }

   public BigDecimal getId()
   {
      return id;
   }

   public void setId(BigDecimal decimal)
   {
      id = decimal;
   }

   public String toString()
   {
       return "Child:" + name;
   }

   public boolean equals(Object other) {
       if ( !(other instanceof Child) ) return false;
       Child castOther = (Child) other;
       return new EqualsBuilder()
      .append(this.getId(), castOther.getId())
      .isEquals();
   }

   public int hashCode() {
       return new HashCodeBuilder()
      .append(getId())
      .toHashCode();
   }
}



Code:
metadata

        <class name="com.pts.ietms.data.om.Child" table="Child">
            <id name="id" type="big_decimal" unsaved-value="null">
                    <column name="id" sql-type="NUMBER(38)"/>
                    <generator class="com.pts.ietms.data.tools.HKeyGenerator"/>
            </id>

            <many-to-one name="parent" class="com.pts.ietms.data.om.Parent">
                <column name="parent_id"  sql-type="NUMBER(38)" not-null="true" />
            </many-to-one>

            <property name="name" type="string" />
        </class>

        <class name="com.pts.ietms.data.om.Parent" table="Parent">
            <id name="id" type="big_decimal" unsaved-value="null">
                    <column name="id" sql-type="NUMBER(38)"/>
                    <generator class="com.pts.ietms.data.tools.HKeyGenerator"/>
            </id>
            <property name="refId" type="string" />
            <set name="children" table="children" inverse="true"  cascade="all-delete-orphan">
                    <key >
                            <column name="id" sql-type="NUMBER(38)" />
                    </key>
                    <one-to-many class="com.pts.ietms.data.om.Child" />
            </set>
        </class>


Generater class:
Code:
package com.pts.ietms.data.tools;

import java.io.Serializable;
import java.sql.SQLException;
import java.util.Properties;

import java.math.BigDecimal;

import net.sf.hibernate.dialect.Dialect;
import net.sf.hibernate.HibernateException;
import net.sf.hibernate.engine.SessionImplementor;
import net.sf.hibernate.id.IdentifierGenerator;
import net.sf.hibernate.id.TableGenerator;
import net.sf.hibernate.type.Type;
import net.sf.hibernate.util.PropertiesHelper;

/**
* HKeyGenerator
*
*/
public class HKeyGenerator  extends TableGenerator implements IdentifierGenerator
{

       BigDecimal key=null;

   /**
    * The max_lo parameter
    */
   public static final String MAX_LO = "max_lo";
   
   private long hi;
   private int lo;
   private int maxLo;
   private Class returnClass;
   
   public void configure(Type type, Properties params, Dialect d) {
      super.configure(type, params, d);
      maxLo = PropertiesHelper.getInt(MAX_LO, params, Short.MAX_VALUE);
      lo = maxLo + 1; // so we "clock over" on the first invocation
      returnClass = type.getReturnedClass();
   }



   /* (non-Javadoc)
    * @see net.sf.hibernate.id.IdentifierGenerator#generate(net.sf.hibernate.engine.SessionImplementor, java.lang.Object)
    */
   public Serializable generate(SessionImplementor session, Object obj)
      throws SQLException, HibernateException
   {

      if (lo>maxLo) {
         int hival = ( (Integer) super.generate(session, obj) ).intValue();
         lo = 1;
         hi = hival * (maxLo+1);
      }

      double bigvalue = hi + lo++;

      return new BigDecimal(bigvalue);
   }

}


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 23, 2003 1:04 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Parent Child relationship works in Hibernate, for sure.

Try 2 things (no env available, my side) :

Avoid use of Collections.unmodifiableSet. Return the proper children set (return children). Might be an issue but I'm not aware enough of hibernate set implementation.

If fails, execute the hib request, 1 child should have been returned (you said to me that DB insert had worked properly).

select child0_.id as id__, parent1_.id as id0_, parent1_.refId as refId0_, child0_.id as id1_, child0_.parent_id as parent_id1_, child0_.name as name1_ from Child child0_, Parent parent1_ where child0_.id=? and child0_.parent_id=parent1_.id(+)

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 23, 2003 1:42 pm 
Newbie

Joined: Sun Oct 05, 2003 5:43 pm
Posts: 10
Location: Atlanta
Using unmodified set vs not makes no difference.

Yes as you can see hibernate is doing the correct sql, meain upon retrieval both sql statements as expected are being executed ie one for parent one for child. However the set is still empty and thus the problem.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 23, 2003 1:56 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Turn on logging.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 23, 2003 4:14 pm 
Newbie

Joined: Sun Oct 05, 2003 5:43 pm
Posts: 10
Location: Atlanta
Here is the results after turning debug on:

15:48:58,782 DEBUG BatcherImpl:226 - prepared statement get: select child0_.id as id__, parent1_.id as id0_, parent1_.refId as refId0_, child0_.id as id1_, child0_.parent_id as parent_id1_, child0_.name as name1_ from Child child0_, Parent parent1_ where child0_.id=? and child0_.parent_id=parent1_.id(+)
Hibernate: select child0_.id as id__, parent1_.id as id0_, parent1_.refId as refId0_, child0_.id as id1_, child0_.parent_id as parent_id1_, child0_.name as name1_ from Child child0_, Parent parent1_ where child0_.id=? and child0_.parent_id=parent1_.id(+)
15:48:58,782 DEBUG BatcherImpl:232 - preparing statement
15:48:58,792 DEBUG Loader:263 - result set contains (possibly empty) collection: [com.pts.ietms.data.om.Parent.children#393217]
15:48:58,792 DEBUG SessionImpl:3039 - uninitialized collection: initializing
15:48:58,802 DEBUG Loader:174 - processing result set
15:48:58,802 DEBUG Loader:202 - done processing result set (0 rows)

As you can see the sql generated takes a child id as a parameter. I would have thought it should take a parent id as a parameter (ie this is reveresed) the resulting sql returns nothing ... I can't be sure what is being passed to the prepared statement but if you assume its the parent id then of course it would return no results...

Below is the entire detail I tried to bold the relevant sections. The first bold shows three inserts occuring as expected one for the parent, and one for each child (there are two). The retrieval is the interesting part it shows the sql creation of the parent, and the fact that it gets no rows returned for the children collection:

For Reference here is the metadata that was run with this:

Code:
<class name="com.pts.ietms.data.om.Parent" table="Parent">
            <id name="id" type="big_decimal" unsaved-value="null">
                    <column name="id" sql-type="NUMBER(38)"/>
                    <generator class="com.pts.ietms.data.tools.HKeyGenerator"/>
            </id>
            <property name="refId" type="string" />
            <set name="children" table="children" inverse="true"  cascade="all-delete-orphan">
                    <key >
                            <column name="id" sql-type="NUMBER(38)" />
                    </key>
                    <one-to-many class="com.pts.ietms.data.om.Child" />
            </set>
        </class>

        <class name="com.pts.ietms.data.om.Child" table="Child">
            <id name="id" type="big_decimal" unsaved-value="null">
                    <column name="id" sql-type="NUMBER(38)"/>
                    <generator class="com.pts.ietms.data.tools.HKeyGenerator"/>
            </id>

            <many-to-one name="parent" class="com.pts.ietms.data.om.Parent">
                <column name="parent_id"  sql-type="NUMBER(38)" not-null="true" />
            </many-to-one>

            <property name="name" type="string" />
        </class>




Changed Test Code to include verification step which lead to changing child hash code and equals to include child name as a parameter .. so now child code equals and hash code are:

Code:
  public boolean equals(Object other) {
       if ( !(other instanceof Child) ) return false;
       Child castOther = (Child) other;
       return new EqualsBuilder()
      .append(this.getId(), castOther.getId())
           .append(this.getName(), castOther.getName())
      .isEquals();
   }

   public int hashCode()
   {
       return new HashCodeBuilder()
      .append(getId())
           .append(getName())
      .toHashCode();
   }
}



Added verification step in test program to print parent before saving...

Code:
Child c = new Child("Child1");
       p.addChild(c);
       c = new Child("Child2");
       p.addChild(c);

       System.out.println(">>> Verify parent <<< ");
       System.out.println("Parent" + p.getRefId());
       System.out.println("With " + p.getChildren().size() + " children");
       Iterator it = p.getChildren().iterator();

       while (it.hasNext())
       {
      System.out.println("Child:" + ((Child)(it.next())).getName());
       }


       System.out.println("Saving parent");


Log File:

15:48:49,358 INFO Dialect:82 - Using dialect: net.sf.hibernate.dialect.OracleDialect
15:48:49,358 INFO SettingsFactory:62 - Use outer join fetching: true
15:48:49,388 INFO DriverManagerConnectionProvider:41 - Using Hibernate built-in connection pool (not for production use!)
15:48:49,388 INFO DriverManagerConnectionProvider:42 - Hibernate connection pool size: 10
15:48:49,518 INFO DriverManagerConnectionProvider:71 - using driver: oracle.jdbc.driver.OracleDriver at URL: jdbc:oracle:oci8:@MRIDB
15:48:49,528 INFO DriverManagerConnectionProvider:72 - connection properties: {user=apptest, password=apptest, statement_cache=25, driver=oracle.jdbc.driver.OracleDriver}
15:48:49,538 INFO TransactionManagerLookupFactory:33 - No TransactionManagerLookup configured (use of process level read-write cache is not recommended)
15:48:49,538 DEBUG DriverManagerConnectionProvider:78 - total checked-out connections: 0
15:48:49,538 DEBUG DriverManagerConnectionProvider:94 - opening new JDBC connection
15:48:55,327 DEBUG DriverManagerConnectionProvider:107 - created connection to: jdbc:oracle:oci8:@MRIDB, Isolation Level: 2
15:48:55,347 DEBUG DriverManagerConnectionProvider:121 - returning connection to pool, pool size: 1
15:48:55,347 INFO SettingsFactory:89 - Use scrollable result sets: true
15:48:55,347 INFO SettingsFactory:96 - echoing all SQL to stdout
15:48:55,347 INFO SettingsFactory:99 - Query language substitutions: {no=N, true=1, yes=Y, false=0}
15:48:55,347 INFO SettingsFactory:110 - cache provider: net.sf.hibernate.cache.JCSCacheProvider
15:48:55,377 INFO Configuration:930 - instantiating and configuring caches
15:48:55,507 INFO SessionFactoryImpl:112 - building session factory
15:48:55,507 DEBUG SessionFactoryImpl:118 - instantiating session factory with properties: {java.vendor=Sun Microsystems Inc., show_sql=true, hibernate.connection.url=jdbc:oracle:oci8:@MRIDB, os.name=Windows 2000, sun.boot.class.path=c:\java\j2sdk1.4.2\jre\lib\rt.jar;c:\java\j2sdk1.4.2\jre\lib\i18n.jar;c:\java\j2sdk1.4.2\jre\lib\sunrsasign.jar;c:\java\j2sdk1.4.2\jre\lib\jsse.jar;c:\java\j2sdk1.4.2\jre\lib\jce.jar;c:\java\j2sdk1.4.2\jre\lib\charsets.jar;c:\java\j2sdk1.4.2\jre\classes, sun.java2d.fontpath=, java.vm.specification.vendor=Sun Microsystems Inc., java.runtime.version=1.4.2-b28, user.name=Administrator, hibernate.query.imports= com.pts.ietms.data.om, user.language=en, sun.boot.library.path=c:\java\j2sdk1.4.2\jre\bin, dialect=net.sf.hibernate.dialect.OracleDialect, java.version=1.4.2, user.timezone=America/New_York, sun.arch.data.model=32, hibernate.use_outer_join=true, java.endorsed.dirs=c:\java\j2sdk1.4.2\jre\lib\endorsed, sun.cpu.isalist=pentium i486 i386, file.encoding.pkg=sun.io, file.separator=\, java.specification.name=Java Platform API Specification, hibernate.cglib.use_reflection_optimizer=true, java.class.version=48.0, user.country=US, java.home=c:\java\j2sdk1.4.2\jre, java.vm.info=mixed mode, os.version=5.0, path.separator=;, java.vm.version=1.4.2-b28, java.util.prefs.PreferencesFactory=java.util.prefs.WindowsPreferencesFactory, hibernate.connection.password=apptest, user.variant=, hibernate.jdbc.batch_size=0, java.awt.printerjob=sun.awt.windows.WPrinterJob, sun.io.unicode.encoding=UnicodeLittle, awt.toolkit=sun.awt.windows.WToolkit, hibernate.connection.statement_cache=25, hibernate.connection.username=apptest, user.home=C:\Documents and Settings\Administrator, hibernate.query.substitutions=true 1, false 0, yes Y, no N, hibernate.proxool.pool_alais=pool1, java.specification.vendor=Sun Microsystems Inc., hibernate.statement_cache.size=25, hibernate.connection.driver=oracle.jdbc.driver.OracleDriver, java.library.path=c:\java\j2sdk1.4.2\bin;.;C:\WINNT\system32;C:\WINNT;c:\vslickplugin\eclipse\plugins\com.slickedit.eclipse.plugin_8.0.1\win;c:\java\j2sdk1.4.2\bin;c:\vslick\win;C:\oracle\ora92\bin;C:\Program Files\Oracle\jre\1.3.1\bin;C:\Program Files\Oracle\jre\1.1.8\bin;C:\WINNT\system32;C:\WINNT;C:\WINNT\System32\Wbem;C:\Program Files\Symantec\pcAnywhere\;C:\MSSQL7\BINN;c:\mysql\lib\opt;c:\mysql\bin;c:\projects\bin;c:\vslick\win;C:\java\jwsdp-1.2\jwsdp-shared\bin, java.vendor.url=http://java.sun.com/, hibernate.connection.driver_class=oracle.jdbc.driver.OracleDriver, hibernate.proxool.pool_alias=pool1, java.vm.vendor=Sun Microsystems Inc., hibernate.dialect=net.sf.hibernate.dialect.OracleDialect, hibernate.connection.user=apptest, hibernate.jdbc.use_streams_for_binary=true, java.runtime.name=Java(TM) 2 Runtime Environment, Standard Edition, java.class.path=C:\projects\peridyneRepository\ietms-hibernate\build\classes;C:\projects\peridyneRepository\ietms-hibernate\lib\h-2.1\proxool.jar;C:\projects\peridyneRepository\ietms-hibernate\lib\h-2.1\commons-lang.jar;C:\projects\peridyneRepository\ietms-hibernate\lib\h-2.1\jdom.jar;C:\projects\peridyneRepository\ietms-hibernate\lib\h-2.1\optional.jar;C:\projects\peridyneRepository\ietms-hibernate\lib\h-2.1\commons-collections.jar;C:\projects\peridyneRepository\ietms-hibernate\lib\h-2.1\connector.jar;C:\projects\peridyneRepository\ietms-hibernate\lib\h-2.1\commons-dbcp.jar;C:\projects\peridyneRepository\ietms-hibernate\lib\h-2.1\jcs.jar;C:\projects\peridyneRepository\ietms-hibernate\lib\h-2.1\commons-logging.jar;C:\projects\peridyneRepository\ietms-hibernate\lib\h-2.1\commons-pool.jar;C:\projects\peridyneRepository\ietms-hibernate\lib\h-2.1\hibernate-tools.jar;C:\projects\peridyneRepository\ietms-hibernate\lib\h-2.1\commons-beanutils.jar;C:\projects\peridyneRepository\ietms-hibernate\lib\h-2.1\xerces.jar;C:\projects\peridyneRepository\ietms-hibernate\lib\h-2.1\javassist.jar;C:\projects\peridyneRepository\ietms-hibernate\lib\h-2.1\xml-apis.jar;C:\projects\peridyneRepository\ietms-hibernate\lib\h-2.1\cglib-asm.jar;C:\projects\peridyneRepository\ietms-hibernate\lib\h-2.1\dom4j.jar;C:\projects\peridyneRepository\ietms-hibernate\lib\h-2.1\jaas.jar;C:\projects\peridyneRepository\ietms-hibernate\lib\h-2.1\jta.jar;C:\projects\peridyneRepository\ietms-hibernate\lib\h-2.1\xalan.jar;C:\projects\peridyneRepository\ietms-hibernate\lib\h-2.1\c3p0.jar;C:\projects\peridyneRepository\ietms-hibernate\lib\h-2.1\junit.jar;C:\projects\peridyneRepository\ietms-hibernate\lib\h-2.1\odmg.jar;C:\projects\peridyneRepository\ietms-hibernate\lib\h-2.1\classes12.zip;C:\java\hibernate-2.1\hibernate2.jar;C:\projects\peridyneRepository\ietms-hibernate\lib\h-2.1\hibernate2.jar;C:\projects\peridyneRepository\interact-etms\build\classes;C:\java\j2sdk1.4.2\lib\tools.jar;C:\projects\peridyneRepository\ietms-hibernate\build\deploy\ietms-domainModel.jar;C:\java\j2sdk1.4.2\src.zip;C:\java\jboss-3.0.6_tomcat-4.1.18\server\interact-test\lib\jboss-j2ee.jar;C:\java\jboss-3.0.6_tomcat-4.1.18\server\interact-test\lib\hibernate2.jar;C:\projects\peridyneRepository\interact-etms\lib\interact\common\interact-core-common.jar;C:\projects\peridyneRepository\interact-etms\lib\interact\server\interact-core-ejbclient.jar;C:\java\jboss-3.0.6_tomcat-4.1.18\server\interact-test\lib\struts.jar;C:\java\jboss-3.0.6_tomcat-4.1.18\tomcat-4.1.x\common\lib\servlet.jar;C:\java\jboss-3.0.6_tomcat-4.1.18\server\interact-test\lib\log4j.jar;C:\projects\peridyneRepository\interact-etms\lib\3rdParty\client\commons-lang.jar;C:\projects\peridyneRepository\ietms-hibernate\lib\h-2.1\commons-beanutils.jar;C:\projects\peridyneRepository\interact-etms\build\deploy\interact-etms-ui.jar;C:\projects\peridyneRepository\interact-etms\lib\3rdParty\client\batik-awt-util.jar;C:\projects\peridyneRepository\interact-etms\lib\3rdParty\client\batik-dom.jar;C:\projects\peridyneRepository\interact-etms\lib\3rdParty\client\batik-svggen.jar;C:\projects\peridyneRepository\interact-etms\lib\3rdParty\client\batik-util.jar;C:\projects\peridyneRepository\interact-etms\lib\3rdParty\client\batik-xml.jar;C:\projects\peridyneRepository\interact-etms\lib\3rdParty\client\caltag.jar;C:\projects\peridyneRepository\interact-etms\lib\3rdParty\client\cewolf.jar;C:\projects\peridyneRepository\interact-etms\lib\3rdParty\client\commons-dbcp.jar;C:\projects\peridyneRepository\interact-etms\lib\3rdParty\client\commons-fileupload.jar;C:\projects\peridyneRepository\interact-etms\lib\3rdParty\client\commons-pool.jar;C:\projects\peridyneRepository\interact-etms\lib\3rdParty\client\commons-resources.jar;C:\projects\peridyneRepository\interact-etms\lib\3rdParty\client\commons-validator.jar;C:\projects\peridyneRepository\interact-etms\lib\3rdParty\client\jakarta-oro.jar;C:\projects\peridyneRepository\interact-etms\lib\3rdParty\client\jcommon-0.8.6.jar;C:\projects\peridyneRepository\interact-etms\lib\3rdParty\client\jfreechart-0.9.11.jar;C:\projects\peridyneRepository\interact-etms\lib\3rdParty\client\jfreechart-0.9.11-demo.jar;C:\projects\peridyneRepository\interact-etms\lib\3rdParty\client\struts.jar;C:\projects\peridyneRepository\interact-etms\lib\3rdParty\client\tabtag.jar;C:\projects\peridyneRepository\interact-etms\lib\3rdParty\client\treetag.jar, use_outer_join=true, java.vm.specification.name=Java Virtual Machine Specification, java.vm.specification.version=1.0, sun.cpu.endian=little, sun.os.patch.level=Service Pack 3, java.io.tmpdir=C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\, java.vendor.url.bug=http://java.sun.com/cgi-bin/bugreport.cgi, os.arch=x86, java.awt.graphicsenv=sun.awt.Win32GraphicsEnvironment, java.ext.dirs=c:\java\j2sdk1.4.2\jre\lib\ext, user.dir=C:\projects\peridyneRepository\ietms-hibernate\bin, line.separator=
, java.vm.name=Java HotSpot(TM) Client VM, file.encoding=Cp1252, java.specification.version=1.4, hibernate.show_sql=true, hibernate.connection.pool_size=10}
15:48:56,859 INFO ReflectHelper:132 - reflection optimizer disabled for: com.pts.ietms.data.om.Parent, NullPointerException: null
15:48:57,800 DEBUG SessionFactoryObjectFactory:39 - initializing class SessionFactoryObjectFactory
15:48:57,860 DEBUG SessionFactoryObjectFactory:76 - registered: 402881e1f86a7e0e00f86a7e17480000 (unnamed)
15:48:57,860 INFO SessionFactoryObjectFactory:82 - no JNDI name configured
15:48:57,860 DEBUG SessionFactoryImpl:175 - instantiated session factory
15:48:57,980 DEBUG SessionImpl:476 - opened session
>>> Verify parent <<<
ParentParent1
With 2 children
Child:Child2
Child:Child1
Saving parent
15:48:58,001 DEBUG DriverManagerConnectionProvider:78 - total checked-out connections: 0
15:48:58,001 DEBUG DriverManagerConnectionProvider:84 - using pooled JDBC connection, pool size: 0
15:48:58,241 DEBUG DriverManagerConnectionProvider:121 - returning connection to pool, pool size: 1
15:48:58,251 DEBUG SessionImpl:732 - saving [com.pts.ietms.data.om.Parent#393217]
15:48:58,261 DEBUG Cascades:356 - processing cascades for: com.pts.ietms.data.om.Parent
15:48:58,261 DEBUG Cascades:364 - done processing cascades for: com.pts.ietms.data.om.Parent
15:48:58,271 DEBUG SessionImpl:2773 - Wrapped collection in role: com.pts.ietms.data.om.Parent.children
15:48:58,291 DEBUG Cascades:356 - processing cascades for: com.pts.ietms.data.om.Parent
15:48:58,291 DEBUG Cascades:381 - cascading to collection: com.pts.ietms.data.om.Parent.children
15:48:58,301 DEBUG Cascades:105 - cascading to saveOrUpdate()
15:48:58,301 DEBUG Cascades:274 - unsaved-value strategy NULL
15:48:58,301 DEBUG SessionImpl:1278 - saveOrUpdate() unsaved instance
15:48:58,301 DEBUG DriverManagerConnectionProvider:78 - total checked-out connections: 0
15:48:58,301 DEBUG DriverManagerConnectionProvider:84 - using pooled JDBC connection, pool size: 0
15:48:58,311 DEBUG DriverManagerConnectionProvider:121 - returning connection to pool, pool size: 1
15:48:58,321 DEBUG SessionImpl:732 - saving [com.pts.ietms.data.om.Child#425985]
15:48:58,321 DEBUG Cascades:356 - processing cascades for: com.pts.ietms.data.om.Child
15:48:58,321 DEBUG Cascades:105 - cascading to saveOrUpdate()
15:48:58,331 DEBUG SessionImpl:1264 - saveOrUpdate() persistent instance
15:48:58,331 DEBUG Cascades:364 - done processing cascades for: com.pts.ietms.data.om.Child
15:48:58,331 DEBUG Cascades:356 - processing cascades for: com.pts.ietms.data.om.Child
15:48:58,331 DEBUG Cascades:364 - done processing cascades for: com.pts.ietms.data.om.Child
15:48:58,331 DEBUG Cascades:105 - cascading to saveOrUpdate()
15:48:58,331 DEBUG Cascades:274 - unsaved-value strategy NULL
15:48:58,341 DEBUG SessionImpl:1278 - saveOrUpdate() unsaved instance
15:48:58,341 DEBUG SessionImpl:732 - saving [com.pts.ietms.data.om.Child#425986]
15:48:58,341 DEBUG Cascades:356 - processing cascades for: com.pts.ietms.data.om.Child
15:48:58,341 DEBUG Cascades:105 - cascading to saveOrUpdate()
15:48:58,341 DEBUG SessionImpl:1264 - saveOrUpdate() persistent instance
15:48:58,351 DEBUG Cascades:364 - done processing cascades for: com.pts.ietms.data.om.Child
15:48:58,361 DEBUG Cascades:356 - processing cascades for: com.pts.ietms.data.om.Child
15:48:58,361 DEBUG Cascades:364 - done processing cascades for: com.pts.ietms.data.om.Child
15:48:58,361 DEBUG Cascades:364 - done processing cascades for: com.pts.ietms.data.om.Parent
15:48:58,361 DEBUG SessionImpl:2217 - flushing session
15:48:58,371 DEBUG Cascades:356 - processing cascades for: com.pts.ietms.data.om.Parent
15:48:58,371 DEBUG Cascades:381 - cascading to collection: com.pts.ietms.data.om.Parent.children
15:48:58,371 DEBUG Cascades:105 - cascading to saveOrUpdate()
15:48:58,371 DEBUG SessionImpl:1264 - saveOrUpdate() persistent instance
15:48:58,371 DEBUG Cascades:105 - cascading to saveOrUpdate()
15:48:58,371 DEBUG SessionImpl:1264 - saveOrUpdate() persistent instance
15:48:58,371 DEBUG Cascades:364 - done processing cascades for: com.pts.ietms.data.om.Parent
15:48:58,381 DEBUG Cascades:356 - processing cascades for: com.pts.ietms.data.om.Child
15:48:58,381 DEBUG Cascades:105 - cascading to saveOrUpdate()
15:48:58,381 DEBUG SessionImpl:1264 - saveOrUpdate() persistent instance
15:48:58,381 DEBUG Cascades:364 - done processing cascades for: com.pts.ietms.data.om.Child
15:48:58,391 DEBUG Cascades:356 - processing cascades for: com.pts.ietms.data.om.Child
15:48:58,391 DEBUG Cascades:105 - cascading to saveOrUpdate()
15:48:58,391 DEBUG SessionImpl:1264 - saveOrUpdate() persistent instance
15:48:58,391 DEBUG Cascades:364 - done processing cascades for: com.pts.ietms.data.om.Child
15:48:58,391 DEBUG SessionImpl:2326 - Flushing entities and processing referenced collections
15:48:58,401 DEBUG SessionImpl:2773 - Wrapped collection in role: com.pts.ietms.data.om.Parent.children
15:48:58,401 DEBUG SessionImpl:2803 - Collection found: [com.pts.ietms.data.om.Parent.children#393217], was: [<unreferenced>]
15:48:58,401 DEBUG SessionImpl:2645 - Processing unreferenced collections
15:48:58,401 DEBUG SessionImpl:2656 - Scheduling collection removes/(re)creates/updates
15:48:58,411 DEBUG SessionImpl:2229 - Flushed: 3 insertions, 0 updates, 0 deletions to 3 objects
15:48:58,411 DEBUG SessionImpl:2234 - Flushed: 1 (re)creations, 0 updates, 0 removals to 2 collections
15:48:58,411 DEBUG SessionImpl:2264 - executing flush
15:48:58,411 DEBUG EntityPersister:503 - Inserting entity: [com.pts.ietms.data.om.Parent#393217]
15:48:58,421 DEBUG BatcherImpl:192 - about to open: 0 open PreparedStatements, 0 open ResultSets
15:48:58,421 DEBUG DriverManagerConnectionProvider:78 - total checked-out connections: 0
15:48:58,421 DEBUG DriverManagerConnectionProvider:84 - using pooled JDBC connection, pool size: 0
15:48:58,421 DEBUG BatcherImpl:226 - prepared statement get: insert into Parent (refId, id) values (?, ?)
Hibernate: insert into Parent (refId, id) values (?, ?)
15:48:58,431 DEBUG BatcherImpl:232 - preparing statement
15:48:58,431 DEBUG EntityPersister:393 - Dehydrating entity: [com.pts.ietms.data.om.Parent#393217]
15:48:58,431 DEBUG EntityPersister:503 - Inserting entity: [com.pts.ietms.data.om.Child#425985]
15:48:58,431 DEBUG BatcherImpl:199 - done closing: 0 open PreparedStatements, 0 open ResultSets
15:48:58,441 DEBUG BatcherImpl:245 - closing statement
15:48:58,441 DEBUG BatcherImpl:192 - about to open: 0 open PreparedStatements, 0 open ResultSets
15:48:58,441 DEBUG BatcherImpl:226 - prepared statement get: insert into Child (parent_id, name, id) values (?, ?, ?)
Hibernate: insert into Child (parent_id, name, id) values (?, ?, ?)
15:48:58,451 DEBUG BatcherImpl:232 - preparing statement
15:48:58,451 DEBUG EntityPersister:393 - Dehydrating entity: [com.pts.ietms.data.om.Child#425985]
15:48:58,461 DEBUG EntityPersister:503 - Inserting entity: [com.pts.ietms.data.om.Child#425986]
15:48:58,461 DEBUG EntityPersister:393 - Dehydrating entity: [com.pts.ietms.data.om.Child#425986]
15:48:58,471 DEBUG BatcherImpl:199 - done closing: 0 open PreparedStatements, 0 open ResultSets
15:48:58,471 DEBUG BatcherImpl:245 - closing statement
15:48:58,471 DEBUG SessionImpl:2676 - post flush
15:48:58,541 DEBUG SessionImpl:494 - closing session
15:48:58,541 DEBUG SessionImpl:3269 - disconnecting session
15:48:58,541 DEBUG DriverManagerConnectionProvider:121 - returning connection to pool, pool size: 1
15:48:58,541 DEBUG SessionImpl:506 - transaction completion
Retrieving Parent
15:48:58,541 DEBUG SessionImpl:476 - opened session
15:48:58,611 DEBUG SessionImpl:1420 - find: from com.pts.ietms.data.om.Parent p where p.refId = ?
15:48:58,611 DEBUG QueryParameters:82 - parameters: Parent1
15:48:58,611 DEBUG QueryParameters:83 - named parameters: {}
15:48:58,641 DEBUG QueryTranslator:148 - compiling query
15:48:58,702 DEBUG SessionImpl:2217 - flushing session
15:48:58,702 DEBUG SessionImpl:2326 - Flushing entities and processing referenced collections
15:48:58,702 DEBUG SessionImpl:2645 - Processing unreferenced collections
15:48:58,702 DEBUG SessionImpl:2656 - Scheduling collection removes/(re)creates/updates
15:48:58,712 DEBUG SessionImpl:2229 - Flushed: 0 insertions, 0 updates, 0 deletions to 0 objects
15:48:58,712 DEBUG SessionImpl:2234 - Flushed: 0 (re)creations, 0 updates, 0 removals to 0 collections
15:48:58,712 DEBUG SessionImpl:1776 - Dont need to execute flush
15:48:58,712 DEBUG QueryTranslator:200 - HQL: from com.pts.ietms.data.om.Parent p where p.refId = ?
15:48:58,712 DEBUG QueryTranslator:201 - SQL: select parent0_.id as id, parent0_.refId as refId from Parent parent0_ where (parent0_.refId=? )
15:48:58,712 DEBUG BatcherImpl:192 - about to open: 0 open PreparedStatements, 0 open ResultSets
15:48:58,722 DEBUG DriverManagerConnectionProvider:78 - total checked-out connections: 0
15:48:58,722 DEBUG DriverManagerConnectionProvider:84 - using pooled JDBC connection, pool size: 0
15:48:58,722 DEBUG BatcherImpl:226 - prepared statement get: select parent0_.id as id, parent0_.refId as refId from Parent parent0_ where (parent0_.refId=? )
Hibernate: select parent0_.id as id, parent0_.refId as refId from Parent parent0_ where (parent0_.refId=? )
15:48:58,722 DEBUG BatcherImpl:232 - preparing statement
15:48:58,742 DEBUG Loader:174 - processing result set
15:48:58,752 DEBUG Loader:330 - result row: 393217
15:48:58,752 DEBUG Loader:427 - Initializing object from ResultSet: 393217
15:48:58,752 DEBUG Loader:482 - Hydrating entity: com.pts.ietms.data.om.Parent#393217
15:48:58,752 DEBUG Loader:202 - done processing result set (1 rows)
15:48:58,752 DEBUG BatcherImpl:199 - done closing: 0 open PreparedStatements, 0 open ResultSets
15:48:58,762 DEBUG BatcherImpl:245 - closing statement
15:48:58,762 DEBUG Loader:215 - total objects hydrated: 1
15:48:58,762 DEBUG SessionImpl:2158 - resolving associations for [com.pts.ietms.data.om.Parent#393217]
15:48:58,772 DEBUG SessionImpl:2180 - done materializing entity [com.pts.ietms.data.om.Parent#393217]
15:48:58,772 DEBUG SessionImpl:3117 - initializing non-lazy collection: [com.pts.ietms.data.om.Parent.children#393217]
15:48:58,772 DEBUG SessionImpl:3207 - initializing collection [com.pts.ietms.data.om.Parent.children#393217]
15:48:58,782 DEBUG BatcherImpl:192 - about to open: 0 open PreparedStatements, 0 open ResultSets
15:48:58,782 DEBUG BatcherImpl:226 - prepared statement get: select child0_.id as id__, parent1_.id as id0_, parent1_.refId as refId0_, child0_.id as id1_, child0_.parent_id as parent_id1_, child0_.name as name1_ from Child child0_, Parent parent1_ where child0_.id=? and child0_.parent_id=parent1_.id(+)
Hibernate: select child0_.id as id__, parent1_.id as id0_, parent1_.refId as refId0_, child0_.id as id1_, child0_.parent_id as parent_id1_, child0_.name as name1_ from Child child0_, Parent parent1_ where child0_.id=? and child0_.parent_id=parent1_.id(+)
15:48:58,782 DEBUG BatcherImpl:232 - preparing statement
15:48:58,792 DEBUG Loader:263 - result set contains (possibly empty) collection: [com.pts.ietms.data.om.Parent.children#393217]
15:48:58,792 DEBUG SessionImpl:3039 - uninitialized collection: initializing
15:48:58,802 DEBUG Loader:174 - processing result set
15:48:58,802 DEBUG Loader:202 - done processing result set (0 rows)

15:48:58,802 DEBUG BatcherImpl:199 - done closing: 0 open PreparedStatements, 0 open ResultSets
15:48:58,812 DEBUG BatcherImpl:245 - closing statement
15:48:58,822 DEBUG Loader:215 - total objects hydrated: 0
15:48:58,822 DEBUG SessionImpl:3084 - collection fully initialized: [com.pts.ietms.data.om.Parent.children#393217]
15:48:58,822 DEBUG SessionImpl:3087 - 1 collections initialized
Got Parent:Parent1
With 0 children
15:48:58,822 DEBUG SessionImpl:494 - closing session
15:48:58,822 DEBUG SessionImpl:3269 - disconnecting session
15:48:58,832 DEBUG DriverManagerConnectionProvider:121 - returning connection to pool, pool size: 1
15:48:58,832 DEBUG SessionImpl:506 - transaction completion


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 23, 2003 4:36 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
So I dunno. Hibernate is clearly doing the right thing. Maybe you forgot to commit the transaction.


Top
 Profile  
 
 Post subject: Solved the problem
PostPosted: Thu Oct 23, 2003 5:19 pm 
Newbie

Joined: Sun Oct 05, 2003 5:43 pm
Posts: 10
Location: Atlanta
Found the problem...

It appears that the Key property of the Parent set needs to point fk column of the child ie the child's reference to the parent, and not the child's primary key. Changing the parent defition to:


<class name="com.pts.ietms.data.om.Parent" table="Parent">
<id name="id" type="big_decimal" unsaved-value="null">
<column name="id" sql-type="NUMBER(38)"/>
<generator class="com.pts.ietms.data.tools.HKeyGenerator"/>
</id>
<property name="refId" type="string" />
<set name="children" table="children" inverse="true" cascade="all-delete-orphan">
<key >
<column name="parent_id" sql-type="NUMBER(38)" /> </key>
<one-to-many class="com.pts.ietms.data.om.Child" />
</set>
</class>

Solved the problem and retrieved the right result... will test it now in production version of our classes ... thanks for the help.

Any explaination as to WHY this worked would be nice...


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 23, 2003 5:25 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
ummm.....thats what the <key> column is.


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