Java 无法使用复合键持久化实体
我正在尝试持久化具有合成主键的实体。。 这是我的员工实体 这是EvaluationEvaluatorsId类:Java 无法使用复合键持久化实体,java,hibernate,jpa,ejb,conversation-scope,Java,Hibernate,Jpa,Ejb,Conversation Scope,我正在尝试持久化具有合成主键的实体。。 这是我的员工实体 这是EvaluationEvaluatorsId类: public class EvaluationEvaluatorsId implements Serializable { private Long employeeID; private Long evaluationID; 这是我保存的方法 public String save() { Iterator<Employee> iterator =
public class EvaluationEvaluatorsId implements Serializable {
private Long employeeID;
private Long evaluationID;
这是我保存的方法
public String save() {
Iterator<Employee> iterator = evaluators.getTarget().iterator();
while(iterator.hasNext()){
EvaluationEvaluator ev = new EvaluationEvaluator();
ev.setEmployee(iterator.next());
ev.setEvaluation(evaluation);
ev.setStatus("COMPLETED");
evaluation.getEvaluationEvaluators().add(ev);
}
if (evaluation.getId() == null) {
em.persist(evaluation);
} else {
em.merge(evaluation);
}
if (!conversation.isTransient()) {
conversation.end();
}
return "/evaluation/evaluationsAsig.xhtml";
Iterator Iterator=evaluators.getTarget().Iterator()中的求值器是如何工作的代码>检索?请共享实际的stacktrace。我通过DualList检索,因为在我的网页中我使用pick list,它需要这个组件来处理它。我已从数据库中检索到员工列表,但我想保存EvaluationEvator列表。我会发布完整的stacktrace。我调试了应用程序,显然一切正常。谢谢。我编辑了我的问题并添加了stacktrace,提前谢谢。我在这里遇到了同样的问题,你解决了吗?
@Entity
@Table(name="EVALUATION_EVALUATOR")
@IdClass(EvaluationEvaluatorsId.class)
public class EvaluationEvaluator implements Serializable {
@Id
@Column(name="EMPLOYEE_ID", insertable= false, updatable = false)
private Long employeeID;
@Id
@Column(name="EVALUATION_ID" ,insertable= false , updatable = false)
private Long evaluationID;
//@NotNull
@ManyToOne
@JoinColumn(name="EMPLOYEE_ID")
private Employee employee;
@ManyToOne
@JoinColumn(name="EVALUATION_ID")
private Evaluation evaluation;
@NotNull
private String status;
//SOME GETTER AND SETTERS HERE
public class EvaluationEvaluatorsId implements Serializable {
private Long employeeID;
private Long evaluationID;
public String save() {
Iterator<Employee> iterator = evaluators.getTarget().iterator();
while(iterator.hasNext()){
EvaluationEvaluator ev = new EvaluationEvaluator();
ev.setEmployee(iterator.next());
ev.setEvaluation(evaluation);
ev.setStatus("COMPLETED");
evaluation.getEvaluationEvaluators().add(ev);
}
if (evaluation.getId() == null) {
em.persist(evaluation);
} else {
em.merge(evaluation);
}
if (!conversation.isTransient()) {
conversation.end();
}
return "/evaluation/evaluationsAsig.xhtml";
07:52:27,368 INFO [stdout] (http-/127.0.0.1:8080-5) insert
07:52:27,369 INFO [stdout] (http-/127.0.0.1:8080-5) into
07:52:27,369 INFO [stdout] (http-/127.0.0.1:8080-5) Evaluacion
07:52:27,369 INFO [stdout] (http-/127.0.0.1:8080-5) (evaluado_id,
fechaAsignacion, observacion, id)
07:52:27,369 INFO [stdout] (http-/127.0.0.1:8080-5) values
07:52:27,369 INFO [stdout] (http-/127.0.0.1:8080-5) (?, ?, ?, ?)
07:52:27,397 INFO [stdout] (http-/127.0.0.1:8080-5) Hibernate:
07:52:27,397 INFO [stdout] (http-/127.0.0.1:8080-5) insert
07:52:27,397 INFO [stdout] (http-/127.0.0.1:8080-5) into
07:52:27,398 INFO [stdout] (http-/127.0.0.1:8080-5) EVALUACION_EVALUADORES
07:52:27,398 INFO [stdout] (http-/127.0.0.1:8080-5) (EMPLEADO_ID,
EVALUACION_ID, status)
07:52:27,398 INFO [stdout] (http-/127.0.0.1:8080-5) values
07:52:27,398 INFO [stdout] (http-/127.0.0.1:8080-5) (?, ?, ?)
07:52:27,399 INFO [org.hibernate.engine.jdbc.batch.internal.AbstractBatchImpl]
(http-/127.0.0.1:8080-5) HHH000010: On release of batch it still contained JDBC
statements
07:52:27,412 WARN [org.hibernate.engine.jdbc.spi.SqlExceptionHelper]
(http-/127.0.0.1:8080-5) SQL Error: 0, SQLState: S1009
07:52:27,413 ERROR [org.hibernate.engine.jdbc.spi.SqlExceptionHelper]
(http-/127.0.0.1:8080-5) Parameter index out of range (4 > number of parameters, which
is 3).
Caused by: org.hibernate.exception.GenericJDBCException: could not insert:
[py.com.test.bpartnerevaluator.model.evaluacion.EvaluacionEvaluadores]
at org.hibernate.exception.internal.StandardSQLExceptionConverter.
convert(StandardSQLExceptionConverter.java:54)
[hibernate-core-4.2.7.SP1-redhat-3.jar:4.2.7.SP1-redhat-3]
at
org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:125)
[hibernate-core-4.2.7.SP1-redhat-3.jar:4.2.7.SP1-redhat-3]
at
org.hibernate.persister.entity.AbstractEntityPersister.insert
(AbstractEntityPersister.java:3101) [hibernate-core-4.2.7.SP1-redhat-3.jar:4.2.7.SP1-
redhat-3]
at
org.hibernate.persister.entity.AbstractEntityPersister.
insert(AbstractEntityPersister.java:3523) [hibernate-core-4.2.7.SP1-redhat-
3.jar:4.2.7.SP1-redhat-3]
at
org.hibernate.action.internal.EntityInsertAction.execute(EntityInsertAction.java:88)
[hibernate-core-4.2.7.SP1-redhat-3.jar:4.2.7.SP1-redhat-3]
at org.hibernate.engine.spi.ActionQueue.execute(ActionQueue.java:393)
[hibernate-core-4.2.7.SP1-redhat-3.jar:4.2.7.SP1-redhat-3]
at org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:385)
[hibernate-core-4.2.7.SP1-redhat-3.jar:4.2.7.SP1-redhat-3]
at org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:301)
[hibernate-core-4.2.7.SP1-redhat-3.jar:4.2.7.SP1-redhat-3]
at
rg.hibernate.event.internal.AbstractFlushingEventListener.
performExecutions(AbstractFlushingEventListener.java:339) [hibernate-core-4.2.7.SP1-
redhat-3.jar:4.2.7.SP1-redhat-3]
at
org.hibernate.event.internal.DefaultFlushEventListener.onFlush
(DefaultFlushEventListener.java:52) [hibernate-core-4.2.7.SP1-redhat-3.jar:4.2.7.SP1-
redhat-3]
at org.hibernate.internal.SessionImpl.flush(SessionImpl.java:1240) [hibernate-
core-4.2.7.SP1-redhat-3.jar:4.2.7.SP1-redhat-3]
at org.hibernate.internal.SessionImpl.managedFlush(SessionImpl.java:404)
[hibernate-core-4.2.7.SP1-redhat-3.jar:4.2.7.SP1-redhat-3]
at
org.hibernate.engine.transaction.synchronization.internal.
SynchronizationCallbackCoordinatorImpl.beforeCompletion
(SynchronizationCallbackCoordinatorImpl.java:113) [hibernate-core-4.2.7.SP1-redhat-
3.jar:4.2.7.SP1-redhat-3]
... 81 more