-->
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.  [ 1 post ] 
Author Message
 Post subject: Null entry in returned List
PostPosted: Wed May 25, 2005 5:57 pm 
Newbie

Joined: Sat Nov 13, 2004 6:03 am
Posts: 3
Hi,

I have a parent / child object (basket and basket item). I have a single row in the BasketItem table. When I retrieve the parent basket instance, the BasketItems list is populated with 2 rows:
1) the single basket item
2) a null entry.

my question is why is the null value in the list rather than just the single entry.

Hibernate 3.0.5, MySQL 4.0.16

hibernate config entries:

from Baket.hbm.xml
<list name="basketItems" lazy="false" outer-join="false" inverse="true" cascade="delete">
<key foreign-key="BASKET_ITEM_BASKET_FKC">
<column name="BASKET_FK"/>
</key>
<index column="id"/>
<one-to-many class="com.codeczar.commerce.basket.BasketItem"/>
</list>

from BasketItem.hbm.xml
<hibernate-mapping default-cascade="none">
<class name="com.codeczar.commerce.basket.BasketItem" table="BASKET_ITEM" dynamic-insert="false" dynamic-update="false">
<id name="id" type="java.lang.Integer" unsaved-value="null">
<column name="ID" sql-type="INTEGER"/>
<generator class="native">
</generator>
</id>
............ snip
<many-to-one name="basket" class="com.codeczar.commerce.basket.Basket" outer-join="auto" foreign-key="BASKET_ITEM_BASKET_FKC">
<column name="BASKET_FK" not-null="true" sql-type="INTEGER"/>
</many-to-one>
</class>
</hibernate-mapping>

Here's the debug which confirms a single basket item returned

Hibernate: select basketitem0_.BASKET_FK as BASKET4_1_, basketitem0_.ID as ID1_, basketitem0_.id as id1_, basketitem0_.ID as ID0_, basketitem0_.QUANTITY as QUANTITY7_0_, basketitem0_.PRODUCT_FK as PRODUCT3_7_0_, basketitem0_.BASKET_FK as BASKET4_7_0_ from BASKET_ITEM basketitem0_ where basketitem0_.BASKET_FK=?
[AbstractBatcher] preparing statement
[xapool] StandardXAConnectionHandle:prepareStatement tx==null
[jta] threadTx.get= java.lang.ThreadLocal@13e754f
[jta] Transaction ret= null
[xapool] StandardXAConnectionHandle:prepareStatement (no transaction found)
[xapool] StandardXAPreparedStatement: Create an XAPreparedStatement with sql='select basketitem0_.BASKET_FK as BASKET4_1_, basketitem0_.ID as ID1_, basketitem0_.id as id1_, basketitem0_.ID as ID0_, basketitem0_.QUANTITY as QUANTITY7_0_, basketitem0_.PRODUCT_FK as PRODUCT3_7_0_, basketitem0_.BASKET_FK as BASKET4_7_0_ from BASKET_ITEM basketitem0_ where basketitem0_.BASKET_FK=?'
[xapool] StandardXAConnectionHandle:checkPreparedCache object is *NOT* found
[xapool] StandardConnectionHandle:createPreparedStatement type ='0'
[xapool] StandardXAConnectionHandle:checkPreparedCache pstmt='com.mysql.jdbc.PreparedStatement@1304043: select basketitem0_.BASKET_FK as BASKET4_1_, basketitem0_.ID as ID1_, basketitem0_.id as id1_, basketitem0_.ID as ID0_, basketitem0_.QUANTITY as QUANTITY7_0_, basketitem0_.PRODUCT_FK as PRODUCT3_7_0_, basketitem0_.BASKET_FK as BASKET4_7_0_ from BASKET_ITEM basketitem0_ where basketitem0_.BASKET_FK=** NOT SPECIFIED **'
[IntegerType] binding '1' to parameter: 1
[AbstractBatcher] about to open ResultSet (open ResultSets: 0, globally: 0)
[Loader] result set contains (possibly empty) collection: [com.codeczar.commerce.basket.Basket.basketItems#1]
[CollectionLoadContext] uninitialized collection: initializing
[Loader] processing result set
[Loader] result set row: 0
[IntegerType] returning '1' as column: ID0_
[Loader] result row: EntityKey[com.codeczar.commerce.basket.BasketItem#1]
[Loader] Initializing object from ResultSet: [com.codeczar.commerce.basket.BasketItem#1]
[BasicEntityPersister] Hydrating entity: [com.codeczar.commerce.basket.BasketItem#1]
[IntegerType] returning '1' as column: QUANTITY7_0_
[IntegerType] returning '1' as column: PRODUCT3_7_0_
[IntegerType] returning '1' as column: BASKET4_7_0_
[IntegerType] returning '1' as column: BASKET4_1_
[Loader] found row of collection: [com.codeczar.commerce.basket.Basket.basketItems#1]
[CollectionLoadContext] reading row
[IntegerType] returning '1' as column: ID1_
[DefaultLoadEventListener] loading entity: [com.codeczar.commerce.basket.BasketItem#1]
[DefaultLoadEventListener] attempting to resolve: [com.codeczar.commerce.basket.BasketItem#1]
[DefaultLoadEventListener] resolved object in session cache: [com.codeczar.commerce.basket.BasketItem#1]
[IntegerType] returning '1' as column: id1_
[Loader] done processing result set (1 rows)

To confirm that a list with two rows is passed to the setBasketItems method, I included a debug statement with a stack.

[Basket] setting basketItems size '2' [null, com.codeczar.commerce.basket.BasketItem................]
java.lang.Exception:
at com.codeczar.commerce.basket.Basket.setBasketItems(Basket.java:69)
at com.codeczar.commerce.basket.Basket$$BulkBeanByCGLIB$$c166c88f.setPropertyValues(<generated>)
at org.hibernate.tuple.PojoTuplizer.setPropertyValuesWithOptimizer(PojoTuplizer.java:200)
at org.hibernate.tuple.PojoTuplizer.setPropertyValues(PojoTuplizer.java:173)
at org.hibernate.persister.entity.BasicEntityPersister.setPropertyValues(BasicEntityPersister.java:2919)
at org.hibernate.engine.TwoPhaseLoad.initializeEntity(TwoPhaseLoad.java:113)
at org.hibernate.loader.Loader.initializeEntitiesAndCollections(Loader.java:530)
at org.hibernate.loader.Loader.doQuery(Loader.java:436)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:218)
at org.hibernate.loader.Loader.loadEntity(Loader.java:1345)
at org.hibernate.loader.entity.EntityLoader.load(EntityLoader.java:116)
at org.hibernate.loader.entity.EntityLoader.load(EntityLoader.java:101)
at org.hibernate.persister.entity.BasicEntityPersister.load(BasicEntityPersister.java:2471)
at org.hibernate.event.def.DefaultLoadEventListener.loadFromDatasource(DefaultLoadEventListener.java:351)
at org.hibernate.event.def.DefaultLoadEventListener.doLoad(DefaultLoadEventListener.java:332)
at org.hibernate.event.def.DefaultLoadEventListener.load(DefaultLoadEventListener.java:113)
at org.hibernate.event.def.DefaultLoadEventListener.proxyOrLoad(DefaultLoadEventListener.java:167)
at org.hibernate.event.def.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:79)
at org.hibernate.impl.SessionImpl.load(SessionImpl.java:592)


Any help greatly appreciated, completely stuck here.

cheers
Nathan


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.