Bom Dia.
Estou com seguinte problema, tenho que realizar uma Anotação de classe Mestre e Detalhe onde tenho as Classe PAI e FILHO, sendo que nas duas classes eu utilizo chave composta e na classe PAI eu tenho um Generator na chave composta. Meu codigo esta da seguinte forma.
@Entity
public class PAI {
@Id
private PAIPK chave;
@Column(name="NOME",length=75,nullable=false)
private String NOME;
@OneToMany(mappedBy="pai",fetch=FetchType.LAZY)
@Cascade(org.hibernate.annotations.CascadeType.ALL)
private Collection<FILHO> filho;
public PAI(){
}
— get e set
@Embeddable
public class PAIPK implements Serializable {
@Column(name="EMPCOD",nullable=false)
private Integer EMPCOD;
@SequenceGenerator(name="GENID",sequenceName="GEN_PAI_ID",allocationSize=1)
@GeneratedValue(strategy=GenerationType.AUTO,generator="GENID")
@Column(name = "ID",nullable=false)
private Integer Id;
public PAIPK(){
}
— get e set
@Entity
public class FILHO {
@Id
private FILHOPK chave;
@Column(name="NOME",length=75,nullable=false)
private String NOME;
@ManyToOne(fetch=FetchType.LAZY)
@JoinColumns({@JoinColumn(name="ID_PAI",referencedColumnName="ID",insertable=false,updatable=false,nullable=false),
@JoinColumn(name="EMPCO",referencedColumnName="EMPCOD",insertable=false,updatable=false,nullable=false)})
@Fetch(FetchMode.JOIN)
@Cascade(CascadeType.ALL)
private PAI pai;
public FILHO(){
}
— get e set
@Embeddable
public class FILHOPK implements Serializable {
@Column(name="EMPCO",nullable=false)
private Integer EMPCO;
@Column(name="ID_PAI",nullable=false)
private Integer ID_PAI;
public FILHOPK(){
}
— get e set
public class Inicia {
public static void main(String[]agrs){
CRUD crud = new CRUD(“hibernate”);
crud.beginSession();
crud.beginTrans();
PAI pai = new PAI();
PAIPK pk = new PAIPK();
pk.setEMPCOD(1);
pai.setChave(pk);
pai.setNOME("HAMSES");
FILHO fl = new FILHO();
FILHOPK flPk = new FILHOPK();
fl.setNOME("DUDA");
fl.setPai(pai);
flPk.setEMPCOD(1);
fl.setChave(flPk);
pai.setFilho(new HashSet<FILHO>());
pai.getFilho().add(fl);
crud.create(pai);
crud.commit();
}
}
na hora que eu tento inserir da o seguinte erro
Exception in thread “main” org.hibernate.exception.GenericJDBCException: could not insert: [br.com.transporte.Tabelas.FILHO]
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.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2272)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2665)
at org.hibernate.action.EntityInsertAction.execute(EntityInsertAction.java:60)
at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:279)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:263)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:167)
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 br.com.transporte.Factory.CRUD.commit(CRUD.java:102)
at br.com.transporte.Tabelas.Inicia.main(Inicia.java:33)
Caused by: org.firebirdsql.jdbc.FBSQLException: GDS Exception. validation error for column ID_PAI, value “*** null ***”
at org.firebirdsql.jdbc.FBPreparedStatement.internalExecute(FBPreparedStatement.java:425)
at org.firebirdsql.jdbc.FBPreparedStatement.executeUpdate(FBPreparedStatement.java:136)
at org.hibernate.jdbc.NonBatchingBatcher.addToBatch(NonBatchingBatcher.java:23)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2252)
… 12 more
Alguem teria alguma tica para que eu possa resolver meu problema.
Obrigado