Hi.
In my classI have two lists with elements of the same type.
Code:
/**
* Objects of the following type(s) are allowed in the list
* {@link my.MultilingualType}
*/
java.util.List getDescription();
/**
* Objects of the following type(s) are allowed in the list
* {@link my.MultilingualType}
*/
java.util.List getName();
I would entries of these lists to be stored in one table. What is the preferred way to do it?
I've tried the following mapping:
Code:
/**
*
* @hibernate.list cascade="all"
* @hibernate.collection-key column="ServicePImpl_id"
* @hibernate.collection-index column="index"
* @hibernate.collection-one-to-many class="my.impl.MultilingualTypeImpl"
*
*/
public java.util.List getDescriptionInternal() {
return _DescriptionInternal;
}
/**
*
* @hibernate.list cascade="all"
* @hibernate.collection-key column="ServicePImpl_id"
* @hibernate.collection-index column="index"
* @hibernate.collection-one-to-many class="my.impl.MultilingualTypeImpl"
*
*/
public java.util.List getNameInternal() {
return _NameInternal;
}
This failed, since first elements of both lists have the same index (it's 0). After loading, I have the same element as the first element of both lists.
Code:
INSERT INTO MULTILINGUALTYPEIMPL VALUES('id1','Cool','eng','id0',0)
INSERT INTO MULTILINGUALTYPEIMPL VALUES('id2','MyName','eng','id0',0)
I have two ideas:
1) Use different index columns and a filtering sql expression in where attribute of the list mapping.
2) Use many-to-many mappings with a separate intermediate tables for each of the collections.
However, I'm a bit lost with this (seemingly) simple mapping task.
I would be gratefult for any help/comments/ideas.
Thank you for your time.