-->
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.  [ 2 posts ] 
Author Message
 Post subject: hashCode called before properties are initialized
PostPosted: Tue May 10, 2005 4:24 am 
Newbie

Joined: Tue May 10, 2005 3:57 am
Posts: 5
Hibernate version: 3.0.2

Hi,

When I fetch an object from the database using


Code:

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
   "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
   "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping package="com.dialog.listserv.model" >
  <class name="ItemGroup" lazy="false">
    <id name="id"><generator class="native"/></id>
      
    <property name="title" length="255">
      <column name="title" not-null="true" unique-key="BUSINESS_KEY"/>         
      <column name="title" not-null="true" unique-key="UNIQUE_TITLE_AT_LEVEL"/>
    </property>
      
    <property name="description" length="512"/>
    <property name="emailConfirmAtSubscrip" not-null="true"/>
    <property name="creationDate" update="false">
      <column name="creationDate" not-null="true" sql-type="TIMESTAMP" unique-key="BUSINESS_KEY"/>
    </property>
      
    <many-to-one name="parentItemGroup" cascade="none" fetch="join">
      <column name="PARENT_GROUP_ID" not-null="false" unique-key="UNIQUE_TITLE_AT_LEVEL"/>
    </many-to-one>

    <set    name="childItemGroups" cascade="all-delete-orphan" inverse="true" fetch="join">
      <key column="PARENT_GROUP_ID"/>
      <one-to-many class="ItemGroup"/>
    </set>

    <many-to-one name="publisher" class="Publisher"   update="false" cascade="none"   fetch="join">
      <column name="PUBLISHER_ID" not-null="true" unique-key="UNIQUE_TITLE_AT_LEVEL"/>
    </many-to-one>
   
    <set name="invitedForeigners" table="ACCOUNT_ITEMGROUP" fetch="join" cascade="save-update">
      <key column="GROUP_ID"/>
      <many-to-many class="Account" column="ACCOUNT_ID"/>
    </set>

    <set name="itemRefs" table="ITEMREF" cascade="all-delete-orphan" fetch="join" outer-join="false" >
      <key column="GROUP_ID"/>
      <one-to-many class="ItemRef"/>
    </set>
    <property name="availableForSubscribers" not-null="true"/>      
  </class>   
</hibernate-mapping>

....
return (ItemGroup) session.get(ItemGroup.class, itemId, LockMode.UPGRADE);
....



I can see the select being done with all the properties returned. I see that my class empty constructor is being called, and the method hashCode is called before any of my class' setters method had a chance to be called.

This provokes a NullPointerException in my hashCode method!

Can someone please help me?

Thanks


Top
 Profile  
 
 Post subject: Found a solution!
PostPosted: Tue May 10, 2005 10:38 am 
Newbie

Joined: Tue May 10, 2005 3:57 am
Posts: 5
After quite a while isolating the problem, I noticed that if I replace fetch="join" by fetch="select" in a related configuration file it solves my problem.

I don't understand why!

Code:
...
      <set    name="itemGroups"
            cascade="all-delete-orphan"
            inverse="true"
            where="PARENT_GROUP_ID is null"
            fetch="select"
            >
         <key>
            <column name="PUBLISHER_ID" not-null="true"/>
         </key>
         <one-to-many class="ItemGroup"/>
      </set>

...


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