I have already changed my mapping having read the
http://forum.hibernate.org/viewtopic.php?t=984049. But i still having problems.
Here are my classes:
Code:
public class Etapa extends A {
private Set<EtapaTarefa> relacoesEtapaTarefa;
public Set<EtapaTarefa> getRelacoesEtapaTarefa() {
return this.relacoesEtapaTarefa;
}
public void setRelacoesEtapaTarefa(Set<EtapaTarefa> relacoesEtapaTarefa) {
this.relacoesEtapaTarefa = relacoesEtapaTarefa;
}
}
Code:
public class Tarefa extends A {
private Set<EtapaTarefa> relacoesEtapaTarefa;
public Set<EtapaTarefa> getRelacoesEtapaTarefa() {
return this.relacoesEtapaTarefa;
}
public void setRelacoesEtapaTarefa(Set<EtapaTarefa> relacoesEtapaTarefa) {
this.relacoesEtapaTarefa = relacoesEtapaTarefa;
}
}
Code:
public class EtapaTarefa implements Serializable {
public static class Id implements Serializable {
private Etapa etapa;
private Tarefa tarefa;
public Id() {
}
public Id(Etapa etapa, Tarefa tarefa) {
this.etapa = etapa;
this.tarefa = tarefa;
}
@Override
public boolean equals(Object obj) {
if (obj instanceof Id) {
Id objId = (Id) obj;
EqualsBuilder equals = new EqualsBuilder();
equals.append(this.etapa, objId.getEtapa());
equals.append(this.tarefa, objId.getTarefa());
return equals.isEquals();
}
return false;
}
@Override
public int hashCode() {
HashCodeBuilder builder = new HashCodeBuilder();
builder.append(this.etapa.hashCode());
builder.append(this.tarefa.hashCode());
return builder.toHashCode();
}
@Override
public String toString() {
return this.etapa.toString() + " - " + this.tarefa.toString();
}
public Etapa getEtapa() {
return etapa;
}
public void setEtapa(Etapa etapa) {
this.etapa = etapa;
}
public Tarefa getTarefa() {
return tarefa;
}
public void setTarefa(Tarefa tarefa) {
this.tarefa = tarefa;
}
}
// primary key
private Id id;
// fields
private String tipo;
public EtapaTarefa() {
this.id = new Id();
}
public EtapaTarefa(Id id) {
this.id = id;
}
public String getTipo() {
return this.tipo;
}
public void setTipo(String tipo) {
this.tipo = tipo;
}
public Id getId() {
return this.id;
}
public void setId(Id id) {
this.id = id;
}
@Override
public boolean equals(Object obj) {
if (obj instanceof EtapaTarefa && this.getId() != null) {
return this.getId().equals(((EtapaTarefa) obj).getId());
}
return false;
}
@Override
public int hashCode() {
if (this.getId() != null) {
return this.getId().hashCode();
}
return 0;
}
}
When i'm saving a Etapa, two strange things happen:
1. The etapatarefa entry is inserted before etapa (that gives a contraint violation)
2. After the insert, occurs a update to null!
Se sql output:
Code:
Hibernate: insert into ETAPATAREFA (TIPO, NUMEROCONTEUDOETAPA, VERSAOCONTEUDOETAPA, NUMEROCONTEUDOTAREFA, VERSAOCONTEUDOTAREFA) values (?, ?, ?, ?, ?)
Hibernate: insert into ETAPATAREFA (TIPO, NUMEROCONTEUDOETAPA, VERSAOCONTEUDOETAPA, NUMEROCONTEUDOTAREFA, VERSAOCONTEUDOTAREFA) values (?, ?, ?, ?, ?)
Hibernate: insert into A (numeroConteudo, versaoConteudo) values (?, ?)
Hibernate: insert into ETAPA (NUMEROCONTEUDO, VERSAOCONTEUDO) values (?, ?)
Hibernate: update ETAPATAREFA set NUMEROCONTEUDOETAPA=null, VERSAOCONTEUDOETAPA=null where NUMEROCONTEUDOETAPA=? and VERSAOCONTEUDOETAPA=?
IPDMS[2008-02-22 17:56:36] WARN (JDBCExceptionReporter.java:77) SQL Error: 1407, SQLState: 72000
IPDMS[2008-02-22 17:56:36] ERROR (JDBCExceptionReporter.java:78) ORA-01407: cannot update ("TESTE"."ETAPATAREFA"."NUMEROCONTEUDOETAPA") to NULL
IPDMS[2008-02-22 17:56:36] WARN (JDBCExceptionReporter.java:77) SQL Error: 1407, SQLState: 72000
IPDMS[2008-02-22 17:56:36] ERROR (JDBCExceptionReporter.java:78) ORA-01407: cannot update ("TESTE"."ETAPATAREFA"."NUMEROCONTEUDOETAPA") to NULL
IPDMS[2008-02-22 17:56:36] ERROR (AbstractFlushingEventListener.java:301) Could not synchronize database state with session
org.hibernate.exception.GenericJDBCException: Could not execute JDBC batch update
at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:103)
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:91)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:253)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:266)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:169)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:298)
Can anyone help me.