Code:
@MappedSuperclass
public abstract class AbstractDomainEntry implements DomainEntry {
@Id @GeneratedValue
@Column(name = "ID")
protected int id = 0;
....
}
@Entity
@Table(name = "timeplan")
public class TimePlan extends AbstractDomainEntry {
@ManyToMany(fetch=FetchType.EAGER, cascade={CascadeType.ALL})
@JoinTable(name="timeplan_resourceplan")
@IndexColumn(name = "position")
@org.hibernate.annotations.Cascade(org.hibernate.annotations.CascadeType.DELETE_ORPHAN)
private List<ResourcePlan> plans = new LinkedList<ResourcePlan>();
@ManyToMany(fetch=FetchType.EAGER)
@JoinTable(name="timeplan_name")
@IndexColumn(name = "position")
private List<Category> names = new LinkedList<Category>();
@ManyToMany(fetch=FetchType.EAGER)
@JoinTable(name="timeplan_period")
@IndexColumn(name = "position")
private List<Resource> periods = new LinkedList<Resource>();
@ManyToMany(fetch=FetchType.EAGER)
@JoinTable(name="timeplan_class")
@IndexColumn(name = "position")
private List<Resource> clazzes = new LinkedList<Resource>();
@ManyToMany(fetch=FetchType.EAGER)
@JoinTable(name="timeplan_exportedperiod")
@IndexColumn(name = "position")
private List<Resource> exportedPeriods = new LinkedList<Resource>();
}
@Entity
@Table(name = "resourceplan")
public class ResourcePlan extends AbstractDomainEntry {
@ManyToOne
@JoinTable(name="resourceplan_parent")
private ResourcePlan parent;
@ManyToOne
private Resource resource;
@Column(name="timeentry")
private TimeEntry timeEntry = new TimeEntry();
@OneToMany(fetch=FetchType.EAGER, cascade={CascadeType.ALL})
@JoinTable(name="resourceplan_plan")
@IndexColumn(name = "position")
private List<ResourcePlan> plans = new LinkedList<ResourcePlan>();
}
Code:
Fel core.ResourcePlan[id = 29] 2007-1 45 ändring
enterprise.exceptions.AppRuntimeException: Fel core.ResourcePlan[id = 29] 2007-1 45 ändring
at view.ReportTimeEntry.save(ReportTimeEntry.java:57)
at view.ReportTimeEntry.setEntrylValue(ReportTimeEntry.java:41)
at enterprise.report.ReportElement.setValue(ReportElement.java:135)
at enterprise.report.ReportUpdater.update(ReportUpdater.java:53)
at enterprise.report.ReportUpdater.update(ReportUpdater.java:25)
at enterprise.report.Report.update(Report.java:344)
at servlet.SpreadSheetServlet.updateSheet(SpreadSheetServlet.java:61)
at servlet.SpreadSheetServlet.processRequest(SpreadSheetServlet.java:40)
at servlet.ResourceServlet.doPost(ResourceServlet.java:69)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at filter.LoginFilter.doFilter(LoginFilter.java:49)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at filter.DataAccessFilter.doFilter(DataAccessFilter.java:31)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:869)
at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:664)
at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
at java.lang.Thread.run(Unknown Source)
Caused by: enterprise.exceptions.AppRuntimeException: Fel i transaktion 14 [Duplicate entry '29' for key 1]
at core.DataAccess.commit(DataAccess.java:150)
at core.DataAccess.save(DataAccess.java:89)
at core.DataAccess.save(DataAccess.java:81)
at view.ReportTimeEntry.save(ReportTimeEntry.java:54)
... 30 more
Caused by: javax.persistence.RollbackException: Error while commiting the transaction
at org.hibernate.ejb.TransactionImpl.commit(TransactionImpl.java:71)
at core.DataAccess.commit(DataAccess.java:143)
... 33 more
Caused by: org.hibernate.exception.ConstraintViolationException: could not insert: [core.ResourcePlan]
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:71)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2263)
at org.hibernate.persister.entity.AbstractEntityPersister.updateOrInsert(AbstractEntityPersister.java:2310)
at org.hibernate.persister.entity.AbstractEntityPersister.update(AbstractEntityPersister.java:2603)
at org.hibernate.action.EntityUpdateAction.execute(EntityUpdateAction.java:92)
at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:248)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:232)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:140)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:298)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1000)
at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:338)
at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:106)
at org.hibernate.ejb.TransactionImpl.commit(TransactionImpl.java:54)
... 34 more
Caused by: java.sql.SQLException: Duplicate entry '29' for key 1
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2928)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1571)
at com.mysql.jdbc.ServerPreparedStatement.serverExecute(ServerPreparedStatement.java:1124)
at com.mysql.jdbc.ServerPreparedStatement.executeInternal(ServerPreparedStatement.java:676)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1166)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1082)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1067)
at com.mchange.v2.c3p0.impl.NewProxyPreparedStatement.executeUpdate(NewProxyPreparedStatement.java:105)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2246)
... 46 more
When loading a TimePlan that has a ResourcePlans with child Resourceplans. And then saving the child Resourceplan using:
core.DataAccess.save(DataAccess.java:89) just does: entityManager.merge(resourcePlan);
there is a Exception thrown: Saying [Duplicate entry '29' for key 1]
Im wondering whats wrong with my mapping that cause this problem.
Maybe someone can point me to a page that has solved the bidirectional mapping of Parent<-->Children<-->GrandChilden problem.
(I know I'm using EAGER-loading of all objects cause all objects are displayed to the user directly after loading them in a nice big graph.)
Hibernate does an insert instead of update on resourceplan_parent...
Hibernate:
update
resourceplan
set
resource_ID=?,
timeentry=?
where
ID=?
Hibernate:
insert
into
resourceplan_parent
(parent_ID, ID)
values
(?, ?)