我有两个模型:
@Entity
public class Documento implements java.io.Serializable {
@Id
@GeneratedValue(strategy = IDENTITY)
@Column(name = "id", unique = true, nullable = false)
private Integer id;
@ManyToMany(fetch = FetchType.LAZY)
@JoinTable(name = "appc_contenido_documento", catalog = "appcope",
joinColumns = {
@JoinColumn(name = "id_documento", nullable = false, updatable =
false)}, inverseJoinColumns = {
@JoinColumn(name = "id_contenido", nullable = false, updatable =
false)})
private Set<Contenido> contenidos = new HashSet<Contenido>(0);
}
和
@Entity
public class Contenido implements java.io.Serializable {
@Id
@GeneratedValue(strategy = IDENTITY)
@Column(name = "id", unique = true, nullable = false)
private Integer id;
@ManyToMany(fetch = FetchType.LAZY)
@JoinTable(name = "appc_contenido_documento", catalog = "appcope",
joinColumns = {
@JoinColumn(name = "id_contenido", nullable = false, updatable =
false)}, inverseJoinColumns = {
@JoinColumn(name = "id_documento", nullable = false, updatable =
false)})
private Set<Documento> documentos = new HashSet<Documento>(0);
}
我没有找到这样的例子,只有我找到关系一对多的例子
如何使用CriteriaQuery选择内容的所有文档?
答案 0 :(得分:0)
将你的多对多关系减少到一对多是一个好主意。这通常可以通过引入桥接实体来完成。也许值得在这里添加这样的表格。