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)
|