Java 无法从@ElementCollection中删除

Java 无法从@ElementCollection中删除,java,hibernate,Java,Hibernate,在User.java中,我得到了一张地图: @Entity public class User{ ... @ElementCollection private Map<Competency,Float> competenciesValue = new HashMap<Competency,Float>(); } 这是一种多对多的关系。许多用户可以拥有许多能力 现在,无论我在哪里尝试删除我的任何能力,我都会得到一个外键错误。如何处理 Stacktrace: Hiberna

在User.java中,我得到了一张地图:

@Entity
public class User{
...
@ElementCollection
private Map<Competency,Float> competenciesValue = new HashMap<Competency,Float>();
}
这是一种多对多的关系。许多用户可以拥有许多能力

现在,无论我在哪里尝试删除我的任何能力,我都会得到一个外键错误。如何处理

Stacktrace:

Hibernate: delete from Competency where id=?
WARN : org.hibernate.engine.jdbc.spi.SqlExceptionHelper - SQL Error: 1451, SQLState: 23000
ERROR: org.hibernate.engine.jdbc.spi.SqlExceptionHelper - Cannot delete or update a parent row: a foreign key constraint fails (`CT2_szet`.`User_competenciesValue`, CONSTRAINT `FK_887tayi9xe3w6xw8jv2cui829` FOREIGN KEY (`competenciesValue_KEY`) REFERENCES `Competency` (`id`))
Jun 05, 2014 4:13:27 PM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet [appServlet] in context with path [/CompetenceTool] threw exception [Request processing failed; nested exception is org.springframework.dao.DataIntegrityViolationException: could not execute statement; SQL [n/a]; constraint [null]; nested exception is org.hibernate.exception.ConstraintViolationException: could not execute statement] with root cause
com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Cannot delete or update a parent row: a foreign key constraint fails (`CT2_szet`.`User_competenciesValue`, CONSTRAINT `FK_887tayi9xe3w6xw8jv2cui829` FOREIGN KEY (`competenciesValue_KEY`) REFERENCES `Competency` (`id`))
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
    at com.mysql.jdbc.Util.handleNewInstance(Util.java:406)
    at com.mysql.jdbc.Util.getInstance(Util.java:381)
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1015)
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:956)
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3491)
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3423)

以下是问题所在

Cannot delete or update a parent row: a foreign key constraint fails 
(CT2_szet.User_competenciesValue, CONSTRAINT FK_887tayi9xe3w6xw8jv2cui829 FOREIGN KEY (competenciesValue_KEY) REFERENCES Competency (id))

首先删除
父行
行,然后删除
合规性中相应的行

请提供完整的堆栈跟踪,以便我们可以帮助您当然我需要删除父行,但如何做到这一点,因为只提供了一个能力实体?我可以做丑陋的jpa查询,但如何在hibernate中做得好呢?然后使用主管实体读取其父级,然后首先删除父级。
Cannot delete or update a parent row: a foreign key constraint fails 
(CT2_szet.User_competenciesValue, CONSTRAINT FK_887tayi9xe3w6xw8jv2cui829 FOREIGN KEY (competenciesValue_KEY) REFERENCES Competency (id))