@Entity public class A{
@Id long id;
@ElementCollection
@CollectionTable(name = "xx_b")
private List<B> bs;
}
@Embeddable public class B implements Serializable{
private String name;
}
如上A,B两个类,现在我想实现的效果是 根据 B.name和A.id 查出B,
如果A和B写成一对多关系, HQL只需要写成 From B b where b.name=? and b.A.id=?, 就行了。
现在现在A类和B类使用的是ElementCollection, Embeddable 我就不知道怎么弄了。
1,需要在B类中怎么写?
2,查询语句怎么写?
@Id long id;
@ElementCollection
@CollectionTable(name = "xx_b")
private List<B> bs;
}
@Embeddable public class B implements Serializable{
private String name;
}
如上A,B两个类,现在我想实现的效果是 根据 B.name和A.id 查出B,
如果A和B写成一对多关系, HQL只需要写成 From B b where b.name=? and b.A.id=?, 就行了。
现在现在A类和B类使用的是ElementCollection, Embeddable 我就不知道怎么弄了。
1,需要在B类中怎么写?
2,查询语句怎么写?