java.lang.NullPointerException

Hibernate JIRA | Keith Mashinter | 1 decade ago
tip
Click on the to mark the solution that helps you, Samebug will learn from it.
As a community member, you’ll be rewarded for you help.
  1. 0

    First, thank you for all the effort you put into Hibernate. I hope you're able to find time to enjoy the success. We seem to be hitting the AssertionFailure area of the code commented out from Loader.readCollectionElement: Object owner = optionalOwner; if (owner==null) { owner = session.getCollectionOwner(collectionRowKey, collectionPersister); if (owner==null) { //TODO: This is assertion is disabled because there is a bug that means the // original owner of a transient, uninitialized collection is not known // if the collection is re-referenced by a different object associated // with the current Session //throw new AssertionFailure("bug loading unowned collection"); } } How we got here: Our UserData class has an userId, name, and pass. 1. We find a unique UserData class by querying the name/pass on login. 2. From that UserData class we map a collection containing UserLocaleData keyed by (userId, countryCode). This collection is fine with lazy or nonLazy loading. 3. From that UserLocaleData we map a collection containing UserBrandData keyed by (userId, countryCode, brandCode). 4. References such as brandSet = userData.getLocales().getBrands() are OK, but then brandSet.size() fails to read() / initialize(), resulting in a NPE show below. We traced the problem back to Loader.readCollectionElement above. This may not be related, but the getCollectionOwner() always returns -1 since it's defined that way in Loader and neither overridden in OuterJoinLoader nor in CollectionLoader. ----- Root Cause ----- java.lang.NullPointerException at net.sf.hibernate.collection.Set.size(Set.java:107) Here is our mapping: <class name="com.wcna.calms.data.UserData" schema="CALMS30_APP" table="USERS"> <id column="USER_ID" name="id" type="long" unsaved-value="0"> <generator class="sequence"> <param name="sequence">seq_users</param> </generator> </id> <property column="LANGUAGE_CODE" length="2" name="languageCode" not-null="true" type="java.lang.String"/> <property column="ROLE_ID" length="22" name="roleId" not-null="true" type="java.lang.Long"/> <property column="GUID" length="20" name="guid" type="java.lang.String"/> <property column="STAFF_ID" length="20" name="staffId" type="java.lang.String"/> <property column="PASSWORD" length="20" name="password" type="java.lang.String"/> <property column="FULL_NAME" length="50" name="fullName" type="java.lang.String"/> <property column="DISABLED" length="1" name="disabled" not-null="true" type="java.lang.String"/> <property column="CREDIT_LIMIT" length="15" name="creditLimit" type="java.lang.Double"/> <property column="VISIBILITY" length="1" name="visibility" type="java.lang.String"/> <set name="userLocales" lazy="true" inverse="true" cascade="all"> <key> <column name="USER_ID"/> </key> <one-to-many class="com.wcna.calms.data.UserLocaleData"/> </set> <many-to-one column="DAG_ID" name="dag" class="com.wcna.calms.data.DagData" /> </class> <class name="com.wcna.calms.data.UserLocaleData" schema="CALMS30_APP" table="USER_LOCALE"> <composite-id> <key-property column="USER_ID" length="22" name="userId" type="long"/> <key-property column="COUNTRY_CODE" length="2" name="countryCode" type="string"/> </composite-id> <property column="LANGUAGE_CODE" length="2" name="languageCode" type="string"/> <set name="userBrands" lazy="true" inverse="true" cascade="all"> <key> <column name="USER_ID"/> <column name="COUNTRY_CODE"/> </key> <one-to-many class="com.wcna.calms.data.UserBrandData"/> </set> </class> <class name="com.wcna.calms.data.UserBrandData" schema="CALMS30_APP" table="USER_BRAND"> <composite-id> <key-property column="USER_ID" length="22" name="userId" type="long"/> <key-property column="COUNTRY_CODE" length="2" name="countryCode" type="string"/> <key-property column="BRAND_CODE" length="2" name="brandCode" type="string"/> </composite-id> </class> Our workaround is to get(UserData.class, queryData.getId()) in step 1 after we find it from the query and then it seems to initialize properly. Thanks, kmashint at yahoo dot com.

    Hibernate JIRA | 1 decade ago | Keith Mashinter
    java.lang.NullPointerException
  2. 0

    First, thank you for all the effort you put into Hibernate. I hope you're able to find time to enjoy the success. We seem to be hitting the AssertionFailure area of the code commented out from Loader.readCollectionElement: Object owner = optionalOwner; if (owner==null) { owner = session.getCollectionOwner(collectionRowKey, collectionPersister); if (owner==null) { //TODO: This is assertion is disabled because there is a bug that means the // original owner of a transient, uninitialized collection is not known // if the collection is re-referenced by a different object associated // with the current Session //throw new AssertionFailure("bug loading unowned collection"); } } How we got here: Our UserData class has an userId, name, and pass. 1. We find a unique UserData class by querying the name/pass on login. 2. From that UserData class we map a collection containing UserLocaleData keyed by (userId, countryCode). This collection is fine with lazy or nonLazy loading. 3. From that UserLocaleData we map a collection containing UserBrandData keyed by (userId, countryCode, brandCode). 4. References such as brandSet = userData.getLocales().getBrands() are OK, but then brandSet.size() fails to read() / initialize(), resulting in a NPE show below. We traced the problem back to Loader.readCollectionElement above. This may not be related, but the getCollectionOwner() always returns -1 since it's defined that way in Loader and neither overridden in OuterJoinLoader nor in CollectionLoader. ----- Root Cause ----- java.lang.NullPointerException at net.sf.hibernate.collection.Set.size(Set.java:107) Here is our mapping: <class name="com.wcna.calms.data.UserData" schema="CALMS30_APP" table="USERS"> <id column="USER_ID" name="id" type="long" unsaved-value="0"> <generator class="sequence"> <param name="sequence">seq_users</param> </generator> </id> <property column="LANGUAGE_CODE" length="2" name="languageCode" not-null="true" type="java.lang.String"/> <property column="ROLE_ID" length="22" name="roleId" not-null="true" type="java.lang.Long"/> <property column="GUID" length="20" name="guid" type="java.lang.String"/> <property column="STAFF_ID" length="20" name="staffId" type="java.lang.String"/> <property column="PASSWORD" length="20" name="password" type="java.lang.String"/> <property column="FULL_NAME" length="50" name="fullName" type="java.lang.String"/> <property column="DISABLED" length="1" name="disabled" not-null="true" type="java.lang.String"/> <property column="CREDIT_LIMIT" length="15" name="creditLimit" type="java.lang.Double"/> <property column="VISIBILITY" length="1" name="visibility" type="java.lang.String"/> <set name="userLocales" lazy="true" inverse="true" cascade="all"> <key> <column name="USER_ID"/> </key> <one-to-many class="com.wcna.calms.data.UserLocaleData"/> </set> <many-to-one column="DAG_ID" name="dag" class="com.wcna.calms.data.DagData" /> </class> <class name="com.wcna.calms.data.UserLocaleData" schema="CALMS30_APP" table="USER_LOCALE"> <composite-id> <key-property column="USER_ID" length="22" name="userId" type="long"/> <key-property column="COUNTRY_CODE" length="2" name="countryCode" type="string"/> </composite-id> <property column="LANGUAGE_CODE" length="2" name="languageCode" type="string"/> <set name="userBrands" lazy="true" inverse="true" cascade="all"> <key> <column name="USER_ID"/> <column name="COUNTRY_CODE"/> </key> <one-to-many class="com.wcna.calms.data.UserBrandData"/> </set> </class> <class name="com.wcna.calms.data.UserBrandData" schema="CALMS30_APP" table="USER_BRAND"> <composite-id> <key-property column="USER_ID" length="22" name="userId" type="long"/> <key-property column="COUNTRY_CODE" length="2" name="countryCode" type="string"/> <key-property column="BRAND_CODE" length="2" name="brandCode" type="string"/> </composite-id> </class> Our workaround is to get(UserData.class, queryData.getId()) in step 1 after we find it from the query and then it seems to initialize properly. Thanks, kmashint at yahoo dot com.

    Hibernate JIRA | 1 decade ago | Keith Mashinter
    java.lang.NullPointerException

    Root Cause Analysis

    1. java.lang.NullPointerException

      No message provided

      at net.sf.hibernate.collection.Set.size()
    2. net.sf.hibernate
      Set.size
      1. net.sf.hibernate.collection.Set.size(Set.java:107)
      1 frame