我目前正在尝试使用@OneToMany(cascade = CascadeType.ALL)为对象的简单列表持久化集合。 Parent_Child的表在MySQL中创建,但每个对象的键在使用SaveOrUpdate时不会更新。任何想法是什么问题? (我的父母的关键是定义和孩子生成)。在保存saveOrUpdate之前,我将这些子项添加到父对象的集合中。我使用MySQL与休眠3和我的自动属性设置为创建 - 下降。OneToMany带注释的集合不会通过Hibernate持久化
测试类:
public class Tester {
public static void main(String[] args) {
VideoChannel testChannel = new VideoChannel("Test Channel");
VideoChannelMap v = new VideoChannelMap(testChannel, "Test Map");
VideoSource sc2Vid = new VideoSource("starcraft-ii-ghost-of-the-past.mp4", "EinghersStreamingBucket");
testChannel.add(sc2Vid);
Session s = HibernateSessionFactory.getSession();
s.beginTransaction();
s.saveOrUpdate(v);
s.close();
}
}
的实体:
@Entity
public class VideoChannelMap {
@Id
String name;
@OneToMany(cascade=CascadeType.ALL)
List<VideoChannel> channelMap;
public VideoChannelMap(VideoChannel initialVid, String name)
{
this.name = name;
channelMap = new ArrayList<VideoChannel>();
channelMap.add(initialVid);
initialVid.setParent(this);
}
}
@Entity
public class VideoChannel {
@Id @GeneratedValue
Long id;
...
}
实际的代码不工作将是缩小了数十非常有帮助潜在的原因。 – Affe 2010-08-27 17:39:36