仅使用Hibernate

时间:2016-07-26 15:43:32

标签: java hibernate

我有一个模型,它在Hibernate的帮助下保存到数据库中。该模型包括List(List)。每当我尝试获取此列表时,我只会收到第一个元素。

简化模型:

@Entity 
@Table(name="evaluation_preferences")
@XmlAccessorType(XmlAccessType.NONE)
public class SomeModel implements Serializable{

    private static final long serialVersionUID = 1L;

    @Id
    @GeneratedValue
    private long id;

    @ElementCollection(fetch = FetchType.EAGER)
    @Cache(usage = CacheConcurrencyStrategy.NONE) 
    private List<Byte> entries;

    public long getId() {return id;}

    public void setId(long Id) {this.id = id;}

    public List<Byte> getEntries() {return entries;}

    public void setEntries(List<Byte> entries) {this.entries = entries;}

    public boolean save() throws HibernateException { HibernateSupport.commit(this);}

    public ExerciseUnit refetch() {
        return HibernateSupport.readOneObjectById(this.getClass(), this.id);
    }
}

我尝试修改列表:

    Transaction tx = null;
    try {
        tx = HibernateSupport.beginTransaction();
        List<Criterion> criterions = new ArrayList<Criterion>();
        criterions.add(Restrictions.eq("id", id));
        SomeModel model = HibernateSupport.readOneObject(SomeModel.class, criterions);
        List<Byte> entries = model.getEntries();
        ratings.add(entry);
        model.setEntries(entries);
        model.save();
        HibernateSupport.commitTransaction(tx);
    } catch (Throwable e) {
        HibernateSupport.rollbackTransaction(tx);
    }

有谁知道可能导致问题的原因?

0 个答案:

没有答案