-
hibernate一对多关联存储0
设备类和小组类是多对一的关系,我是使用的annotation.
设备表Device类关联如下:private Group group; @ManyToOne @JoinColumn(name="GROUP_ID",referencedColumnName="ID") public Group getGroup() { return group; } public void setGroup(Group group) { this.group = group; }
小组表Group类关联如下:private List<Device> devices; @OneToMany(mappedBy="group",cascade={CascadeType.ALL}) public List<Device> getDevices() { return devices; } public void setDevices(List<Device> devices) { this.devices = devices; }
我想存储一个新的group,和已经在数据库中存在的Device关联,但是当我存储Group的时候,Device表中的groupId一直为null
Action代码:List<Device> devices = new ArrayList<Device>(); Device device = deviceManager.get(did);//did是从前台传过来的deviceId,能取到值,数据库中也存在 devices.add(device); model.setDevices(devices); group.setDevices(devices); manager.save(group); //manager中就直接是session.save(group)
希望大家能帮我解决一下困惑我好几天的问题,万分感谢
问题补充:刚才的action代码写错了,应该是下面
List<Device> devices = new ArrayList<Device>();
Device device = deviceManager.get(did);//did是从前台传过来的deviceId,能取到值,数据库中也存在
device.setGroup(group); //group是前台传过来的数据,封装成的Group对象,因为没有存储,所以id是为null的
devices.add(device);
group.setDevices(devices);
manager.save(group); //manager中就直接是session.save(group)
2013年9月10日 07:50
目前还没有答案
相关推荐
6.2.5. 一对多关联(One-to-many Associations) 6.3. 高级集合映射(Advanced collection mappings) 6.3.1. 有序集合(Sorted collections) 6.3.2. 双向关联(Bidirectional associations) 6.3.3. 双向关联...
6.2.5. 一对多关联(One-to-many Associations) 6.3. 高级集合映射(Advanced collection mappings) 6.3.1. 有序集合(Sorted collections) 6.3.2. 双向关联(Bidirectional associations) 6.3.3. 双向关联...
6.2.5. 一对多关联(One-to-many Associations) 6.3. 高级集合映射(Advanced collection mappings) 6.3.1. 有序集合(Sorted collections) 6.3.2. 双向关联(Bidirectional associations) 6.3.3. 双向关联...
6.2.5. 一对多关联(One-to-many Associations) 6.3. 高级集合映射(Advanced collection mappings) 6.3.1. 有序集合(Sorted collections) 6.3.2. 双向关联(Bidirectional associations) 6.3.3. 双向关联...
6.2.5. 一对多关联(One-to-many Associations) 6.3. 高级集合映射(Advanced collection mappings) 6.3.1. 有序集合(Sorted collections) 6.3.2. 双向关联(Bidirectional associations) 6.3.3. 双向关联,...
6.2.5. 一对多关联(One-to-many Associations) 6.3. 高级集合映射(Advanced collection mappings) 6.3.1. 有序集合(Sorted collections) 6.3.2. 双向关联(Bidirectional associations) 6.3.3. 三重关联...
7.2.5. 一对多关联(One-to-many Associations) 7.3. 高级集合映射(Advanced collection mappings) 7.3.1. 有序集合(Sorted collections) 7.3.2. 双向关联(Bidirectional associations) 7.3.3. 三重关联...
一对多关联(One-to-many Associations) 6.3. 高级集合映射(Advanced collection mappings) 6.3.1. 有序集合(Sorted collections) 6.3.2. 双向关联(Bidirectional associations) 6.3.3. 双向关联,涉及...
15.3.4 把多对多关联分解为两个一对多关联 15.4 小结 15.5 思考题 第16章 Hibernate的检索策略 16.1 Hibernate的检索策略简介 16.2 类级别的检索策略 16.2.1 立即检索 16.2.2 延迟检索 16.3 一对多...
6.2.5. 一对多关联(One-to-many Associations) 6.3. 高级集合映射(Advanced collection mappings) 6.3.1. 有序集合(Sorted collections) 6.3.2. 双向关联(Bidirectional associations) 6.3.3. 双向关联...
7.2.1 一对多关联 7.2.2 多对多关联 7.2.3 把列添加到联结表 7.2.4 映射map 7.3 多态关联 7.3.1 多态的多对一关联 7.3.2 多态集合 7.3.3 对联合的多态关联 7.3.4 每个具体类一张...
7.2.5. 一对多关联(One-to-many Associations) 7.3. 高级集合映射(Advanced collection mappings) 7.3.1. 有序集合(Sorted collections) 7.3.2. 双向关联(Bidirectional associations) 7.3.3. 三重关联...
7.2.5. 一对多关联(One-to-many Associations) 7.3. 高级集合映射(Advanced collection mappings) 7.3.1. 有序集合(Sorted collections) 7.3.2. 双向关联(Bidirectional associations) 7.3.3. 三重关联...
6.2.5. 一对多关联(One-to-many Associations) 6.3. 高级集合映射(Advanced collection mappings) 6.3.1. 有序集合(Sorted collections) 6.3.2. 双向关联(Bidirectional associations) 6.3.3. 三重关联...
一对多关联(One-to-many Associations) 7.3. 高级集合映射(Advanced collection mappings) 7.3.1. 有序集合(Sorted collections) 7.3.2. 双向关联(Bidirectional associations) 7.3.3. 三重关联...
6.2.5. 一对多关联(One-to-many Associations) 6.3. 高级集合映射(Advanced collection mappings) 6.3.1. 有序集合(Sorted collections) 6.3.2. 双向关联(Bidirectional associations) 6.3.3. 双向关联,...
15.3.4 把多对多关联分解为两个一对多关联 15.4 小结 15.5 思考题 第16章 Hibernate的检索策略 16.1 Hibernate的检索策略简介 16.2 类级别的检索策略 16.2.1 立即检索 16.2.2 延迟检索 16.3 一对多...
15.3.4 把多对多关联分解为两个一对多关联 15.4 小结 15.5 思考题 第16章 Hibernate的检索策略 16.1 Hibernate的检索策略简介 16.2 类级别的检索策略 16.2.1 立即检索 16.2.2 延迟检索 16.3 一对多...
15.3.4 把多对多关联分解为两个一对多关联 15.4 小结 15.5 思考题 第16章 Hibernate的检索策略 16.1 Hibernate的检索策略简介 16.2 类级别的检索策略 16.2.1 立即检索 16.2.2 延迟检索 16.3 一对多...