-->
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: Hibernate List Index null problem
PostPosted: Fri Dec 17, 2010 10:43 am 
Newbie

Joined: Tue Dec 14, 2010 3:11 pm
Posts: 2
Hi friends. I was using a Set but now due to a widget restriction, I need to use a list.a a sample of my mapping file using A SET and a List are as follows. Can someone help me to place the list index. I am getting some confusion.

**Attribute Mapping File using Set**
?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated Dec 16, 2010 5:25:09 AM by Hibernate Tools 3.4.0.Beta1 -->
<hibernate-mapping>
<class name="h.Attribute" table="ATTRIBUTE">
<id name="AttributeId" type="long">
<column name="ATTRIBUTEID" />
<generator class="native" />
</id>
<property name="AttributeName" type="java.lang.String">
<column name="ATTRIBUTENAME" />
</property>
<set name="Options" table="ATTRIBUTEOPTION" inverse="false" cascade="all" lazy="true">
<key>
<column name="ATTRIBUTEID" />
</key>
<one-to-many class="h.AttributeOption" />
</set>
</class>
</hibernate-mapping>



**Category Mapping File using Set**
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated Dec 16, 2010 8:37:02 AM by Hibernate Tools 3.4.0.Beta1 -->
<hibernate-mapping>
<class name="h.Category" table="CATEGORY">
<id name="CategoryId" type="long">
<column name="CATEGORYID" />
<generator class="native" />
</id>
<property name="CategoryName" type="java.lang.String">
<column name="CATEGORYNAME" />
</property>

<many-to-one name="ParentCategory" class="h.Category">
<column name="PARENT_CATEGORY_ID" />
</many-to-one>

<set name="SubCategory" lazy="true" cascade="all-delete-orphan" inverse="true">
<key>
<column name="PARENT_CATEGORY_ID" />
</key>
<one-to-many class="h.Category" />
</set>


Category Mapping File using list without the list index

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated Dec 17, 2010 2:10:50 AM by Hibernate Tools 3.4.0.Beta1 -->
<hibernate-mapping>
<class name="h.Category" table="CATEGORY">
<id name="CategoryId" type="long">
<column name="CATEGORYID" />
<generator class="assigned" />
</id>
<property name="CategoryName" type="java.lang.String">
<column name="CATEGORYNAME" />
</property>
<many-to-one name="ParentCategory" class="h.Category" fetch="join">
<column name="PARENTCATEGORY" />
</many-to-one>
<list name="SubCategory" inverse="false" table="CATEGORY" lazy="true">
<key>
<column name="CATEGORYID" />
</key>
<list-index></list-index>
<one-to-many class="h.Category" />
</list>
<list name="AllAttributes" inverse="false" table="ATTRIBUTE" lazy="true" cascade="all">
<key>
<column name="CATEGORYID" />
</key>
<list-index></list-index>
<one-to-many class="h.Attribute" />
</list>
</class>
</hibernate-mapping>

Attribute Mapping File using list with not list index

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated Dec 17, 2010 2:10:50 AM by Hibernate Tools 3.4.0.Beta1 -->
<hibernate-mapping>
<class name="h.Attribute" table="ATTRIBUTE">
<id name="AttributeId" type="long">
<column name="ATTRIBUTEID" />
<generator class="assigned" />
</id>
<property name="AttributeName" type="java.lang.String">
<column name="ATTRIBUTENAME" />
</property>
<list name="Options" inverse="false" table="ATTRIBUTEOPTION" lazy="true" cascade="all">
<key>
<column name="ATTRIBUTEID" />
</key>
<list-index></list-index>
<one-to-many class="h.AttributeOption" />
</list>
</class>
</hibernate-mapping>


<set name="AllAttributes" table="ATTRIBUTE" inverse="false" lazy="true" cascade="all">
<key>
<column name="CATEGORYID" />
</key>
<one-to-many class="h.Attribute" />
</set>

</class>
</hibernate-mapping>

I am trying to place <list-index column="idx"/>
Exception in thread "main" org.hibernate.HibernateException: null index column for collection: h.Category.AllAttributes
at org.hibernate.persister.collection.AbstractCollectionPersister.readIndex(AbstractCollectionPersister.java:598)
at org.hibernate.collection.PersistentList.readFrom(PersistentList.java:297)
at org.hibernate.loader.Loader.readCollectionElement(Loader.java:569)
at org.hibernate.loader.Loader.readCollectionElements(Loader.java:344)
at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:299)
at org.hibernate.loader.Loader.doQuery(Loader.java:384)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:203)
at org.hibernate.loader.Loader.loadCollection(Loader.java:1344)
at org.hibernate.loader.collection.OneToManyLoader.initialize(OneToManyLoader.java:106)
at org.hibernate.persister.collection.AbstractCollectionPersister.initialize(AbstractCollectionPersister.java:484)
at org.hibernate.event.def.DefaultInitializeCollectionEventListener.onInitializeCollection(DefaultInitializeCollectionEventListener.java:60)
at org.hibernate.impl.SessionImpl.initializeCollection(SessionImpl.java:1346)
at org.hibernate.collection.AbstractPersistentCollection.initialize(AbstractPersistentCollection.java:170)
at org.hibernate.collection.AbstractPersistentCollection.read(AbstractPersistentCollection.java:47)
at org.hibernate.collection.PersistentList.size(PersistentList.java:81)
at h.FirstExample.main(FirstExample.java:54)


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.