java - Map ArrayList with Hibernate -
i coded first hibernate examples.
the database connection works , understand how can map string pojo database field:
private string firstname;
and in mapping file:
<property name="firstname" type="java.lang.string"> <column name="firstname" /> </property>
but how can map arraylist database? simpl example mapping xml file appreciated.
cheers
update
i switched list instead of arraylist found example. map follows:
<list name="test" inverse="false" table="contact" lazy="true"> <key> <column name="id" /> </key> <list-index></list-index> <element type="java.lang.string"> <column name="test" /> </element> </list>
unfortunately, exception not understand:
exception in thread "main" org.hibernate.mappingexception: foreign key (fk6382b0003257ff7f:contact [id])) must have same number of columns referenced primary key (contact [id,idx])
any ideas?
cheers
i notice using xml map pojos. find information here.
for example:
<list name="myarraylistproperty" cascade="all"> <key column="parent_id"/> <index column="idx"/> <one-to-many class="whatisinthelist"/> </list>
however, using annotations have advantages. this link explain how map collection using annotations.
Comments
Post a Comment