我遇到了与Hibernate存储OneToMany关系的问题。
我得到的是AdvertisementData实体,如下所示:
@Entity
@Table(name = "advertisement_data")
public class AdvertisementData {
@Id
@Column(name = "order_id", unique = true, nullable = false)
@GeneratedValue(generator = "gen")
@GenericGenerator(name = "gen", strategy = "foreign", parameters = @Parameter(name = "property", value = "order"))
private Long id;
@OneToMany(fetch = FetchType.EAGER, cascade = CascadeType.MERGE, mappedBy = "advertisementData")
private List<KRPData> krpData;
//setters and getters
}
和KRPData定义如下:
@Entity
public class KRPData {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
private String description;
@Type(type = "org.hibernate.type.SerializableToBlobType")
private List<String> images;
private String section;
@Type(type = "org.hibernate.type.SerializableToBlobType")
private List<String> filenames;
@ManyToOne
private AdvertisementData advertisementData;
//getters and setters
}
我可以看到两个实体都存储了,但每次我获取AdvertisementData时,结果如下:
KRPData作为PersistentBag返回,没有任何数据。
Hibernate版本:4.2.2.Final
任何想法可能是什么情况?
提前谢谢你!