Java Hibernate映射抛出约束冲突
我有一个需要多对多映射的数据库结构。我使用@ManyToMany注释实现了它,如下所示:Java Hibernate映射抛出约束冲突,java,sql-server,hibernate,Java,Sql Server,Hibernate,我有一个需要多对多映射的数据库结构。我使用@ManyToMany注释实现了它,如下所示: @Entity @Table(name="trans.documentfiles") public class DocumentFile extends GenericEntity { private DocumentType documentType; private DocumentFormat documentFormat; private Set<DocumentGro
@Entity
@Table(name="trans.documentfiles")
public class DocumentFile extends GenericEntity
{
private DocumentType documentType;
private DocumentFormat documentFormat;
private Set<DocumentGroup> docgroups;
/**
* @return the documentType
*/
@ManyToOne(fetch = FetchType.LAZY, cascade=CascadeType.ALL)
@JoinColumn(name = "filetypeid", nullable = false)
public DocumentType getDocumentType()
{
return documentType;
}
/**
* @param documentType the documentType to set
*/
public void setDocumentType(DocumentType documentType)
{
this.documentType = documentType;
}
/**
* @return the docgroups
*/
@ManyToMany(mappedBy = "files")
public Set<DocumentGroup> getDocgroups()
{
return docgroups;
}
/**
* @param docgroups the docgroups to set
*/
public void setDocgroups(Set<DocumentGroup> docgroups)
{
this.docgroups = docgroups;
}
}
请让我知道怎么做
谢谢
编辑::
1:35:11.706 E|SqlExceptionHelper |The DELETE statement conflicted with the REFERENCE constraint "FK_documentfiles_documenttype". The conflict occurred in database "DMS", table "trans.documentfiles", column 'filetypeid'.
什么是堆栈跟踪?有指针吗??任何提示??抛出异常是因为您试图删除受外键约束的记录,根据我的说法,这是不好的行为。
@Override
public boolean deleteOnlyLinks(long documentId, String nodeId)
{
Criteria docFile = null;
try
{
docFile = getCriteria(DocumentGroup.class);
docFile.createAlias("files", "file");
docFile.add(Restrictions.eq("file.id", documentId));
docFile.add(Restrictions.eq("nodeId", nodeId));
List<DocumentObjectLink> lst = docFile.list();
/*for (DocumentObjectLink documentObjectLink : lst)
{*/
getCrntSession().delete(lst.get(0));
//}
} catch (Exception e)
{
logger.debug("Error while deleting" + documentId);
throw new DMSException("Error while deleting" + documentId,ErrorCode.DELETE,e);
}
return true;
}
1:35:11.706 E|SqlExceptionHelper |The DELETE statement conflicted with the REFERENCE constraint "FK_documentfiles_documenttype". The conflict occurred in database "DMS", table "trans.documentfiles", column 'filetypeid'.