Pessoal bom dia,
Estou tentando salvar uma tabela A que tem uma tabela de junção com a tabela B.
No console exibe assim:
Hibernate: delete from filter_expense where idFilter=?
Hibernate: insert into filter_expense (idFilter, idExpense) values (?, ?)
Hibernate: insert into filter_expense (idFilter, idExpense) values (?, ?)
Hibernate: insert into filter_expense (idFilter, idExpense) values (?, ?)
org.hibernate.exception.ConstraintViolationException: could not insert collection: [A.tabela_junção#35]
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:71)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.persister.collection.AbstractCollectionPersister.recreate(AbstractCollectionPersister.java:1183)
at org.hibernate.action.CollectionRecreateAction.execute(CollectionRecreateAction.java:26)
at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:250)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:234)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:145)
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)
Caused by: java.sql.SQLException: Violation of PRIMARY KEY constraint 'PK_tabela_junção'. Cannot insert duplicate key in object 'dbo.tabela_junção'.
at net.sourceforge.jtds.jdbc.SQLDiagnostic.addDiagnostic(SQLDiagnostic.java:365)
at net.sourceforge.jtds.jdbc.TdsCore.tdsErrorToken(TdsCore.java:2781)
at net.sourceforge.jtds.jdbc.TdsCore.nextToken(TdsCore.java:2224)
at net.sourceforge.jtds.jdbc.TdsCore.getMoreResults(TdsCore.java:628)
at net.sourceforge.jtds.jdbc.JtdsStatement.processResults(JtdsStatement.java:525)
at net.sourceforge.jtds.jdbc.JtdsStatement.executeSQL(JtdsStatement.java:487)
at net.sourceforge.jtds.jdbc.JtdsPreparedStatement.executeUpdate(JtdsPreparedStatement.java:421)
at com.mchange.v2.c3p0.impl.NewProxyPreparedStatement.executeUpdate(NewProxyPreparedStatement.java:105)
at org.hibernate.jdbc.NonBatchingBatcher.addToBatch(NonBatchingBatcher.java:23)
at org.hibernate.persister.collection.AbstractCollectionPersister.recreate(AbstractCollectionPersister.java:1146)
Minha dúvida é o seguinte se o hibernate esta deletando como exibe acima, porque no ato de salvar ele reclama que está duplicado? alguem ja mecheu com isso?
O relacionamento é ManytoMany como segyue:
@ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
@JoinTable(name = "tabela_junçao", joinColumns = {
@JoinColumn(name = "idFilter", nullable = false, updatable = false)}, inverseJoinColumns = {
@JoinColumn(name = "idExpense", nullable = false, updatable = false)})
public List<TabelaB> getTabelaB() {
return this.expenseses;
}
Fico no aguardo obrigado