Specifying a list index when using a list in sleep mode

I used a set, but now due to the widget's limitation I need to use list.a a sample of my mapping file using A SET and List looks like this. Can someone help me post the list index. I get 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> <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> 

Matching categories using a list without a 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 a List Without Index 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> 
+4
source share
3 answers

Read the Hibernate Help: 6.2.3. Indexed Collections

Example:

  <list name="whatEver"> <key column="whatEver_fk"/> <index column="idx"/> <one-to-many class="WhatEver"/> </list> 
+5
source

I think you should specify the index property in the POJO for which you are creating a one-to-many relationship

 <list name="whatEver"> <key column="whatEver_fk"/> <index column="idx"/> <one-to-many class="WhatEver_Class"/> </list> 

In the “WhatEver_Class” example above, the POJO must have an index property, and the hbm file must have a property tag.

 <property name="index" type="long" insert="false" update="false"> <column name="idx" /> </property> 
+2
source

The Hibernate 3.3 reference says: “The index of an array or list always has an integer type ...” as well as “If your table does not have an index column, and you still want to use list as a property type, you can map the property as Hibernate <bag> . "

Bag example:

 <bag name="options" table="ATTRIBUTEOPTION" order-by="column_name asc|desc" inverse="true" lazy="true" fetch="select"> <key column="ATTRIBUTEID" /> <one-to-many class="h.AttributeOption" /> </bag> 
+2
source

Source: https://habr.com/ru/post/1332479/


All Articles