我想用LinkedList屬性來堅持一個類,但似乎無法做到正確。這裏是我的代碼和我的映射:在Hibernate中持久LinkedList
import java.util.LinkedList;
public class Stuff implements java.io.Serializable {
private long id;
private LinkedList<Image> images;
public Stuff() {
}
public Stuff(long Id) {
id = Id;
}
public long getId() {
return id;
}
public void setId(long mealId) {
id = mealId;
}
public LinkedList<Image> getNumberImages(int number) {
assert (number >= 0);
return (LinkedList<Image>) images.subList(0, number) ;
}
public LinkedList<Image> getImages() {
return images;
}
public LinkedList<Image> setImages(LinkedList<Image> images) {
this.images = images;
}
public void addImage(Image image) {
if (!images.contains(image)) {
images.add(image);
}
}
Hibernate映射:
<hibernate-mapping>
<class name="data.Stuff" table="Stuff">
<id name="id" type="long" access="field">
<column name="ID" />
<generator class="assigned" />
</id>
<list name="images" inverse="false" table="IMAGE" lazy="true" access="field">
<key>
<column name="ID" />
</key>
<list-index></list-index>
<one-to-many class="data.Image" />
</list>
</class>
</hibernate-mapping>
看來我能堅持類的東西的對象是這樣,但是當我試圖恢復他們下面的錯誤occurres:
Hibernate: select stuff0_.ID as ID0_, stuff0_.NAME as NAME0_, meal0_.GROUPING as GROUPING0_ from MEAL meal0_
org.hibernate.PropertyAccessException: could not set a field value by reflection setter of data.Meal.images
你不會相信你救了我的生命多少先生!你的迷人程度上的+1:D – eclipse