Bonjour à Tous


En ce moment je rencontre un problème assez désagréable concernant l'insert en base de donnée (DB2)

Voici le soucis

Je possède 2 classes qui ont une relation (jointure OneToOne)

il faut savoir que avant la mise en relation de ces 2 tables mon insertion fonctionnait très bien en utilisant le getHibernateTemplate().save(object)

mais depuis l'ajout d'une jointure entre les 2 tables j'ai un soucis

Mon insertion fonction ainsi :

public void createHierachy(Hierarchy hierarchy) {
try {
getHibernateTemplate().save(hierarchy);
} catch (Exception e) {
e.printStackTrace();
}

}

d'où le message d'erreur :

ERROR ["http-bio-8880"-exec-9] AbstractFlushingEventListener.performExecutions(301) | Could not synchronize database state with session
org.hibernate.exception.SQLGrammarException: could not insert: [be.mtb.metier.modele.Hierarchy]
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:67)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
....
Caused by: com.ibm.db2.jcc.am.SqlSyntaxErrorException: DB2 SQL Error: SQLCODE=-206, SQLSTATE=42703, SQLERRMC=CONTRACT, DRIVER=3.59.81
at com.ibm.db2.jcc.am.dd.a(dd.java:676)
at com.ibm.db2.jcc.am.dd.a(dd.java:60)
at com.ibm.db2.jcc.am.dd.a(dd.java:127)
at com.ibm.db2.jcc.am.bn.c(bn.java:2546)
at com.ibm.db2.jcc.am.bn.d(bn.java:2534)
at com.ibm.db2.jcc.am.bn.a(bn.java:2026)
at com.ibm.db2.jcc.t4.cb.g(cb.java:140)
at com.ibm.db2.jcc.t4.cb.a(cb.java:40)
at com.ibm.db2.jcc.t4.q.a(q.java:32)
at com.ibm.db2.jcc.t4.rb.i(rb.java:135)
at com.ibm.db2.jcc.am.bn.gb(bn.java:1997)
at com.ibm.db2.jcc.am.cn.pc(cn.java:3009)
at com.ibm.db2.jcc.am.cn.b(cn.java:3786)
at com.ibm.db2.jcc.am.cn.cc(cn.java:715)
at com.ibm.db2.jcc.am.cn.executeUpdate(cn.java:698)
at org.hibernate.jdbc.NonBatchingBatcher.addToBatch(NonBatchingBatcher.java:23)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2247)

voici mes 2 classes jointe


@Entity
@Table(name = "Hierarchy", catalog = "o")
public class Hierarchy implements java.io.Serializable {

private HierarchyId hierarchyId;
public Hierarchy() {
}

public Hierarchy(HierarchyId id) {
this.hierarchyId = id;
}

@EmbeddedId
@AttributeOverrides({
@AttributeOverride(name = "ehUserCode", column = @Column(name = "EH_USER_CODE", nullable = false, length = 8)),
@AttributeOverride(name = "ehParBuId", column = @Column(name = "EH_PAR_BU_ID", nullable = false, length = 5)),
@AttributeOverride(name = "ehParContrN", column = @Column(name = "EH_PAR_CONTR_N", nullable = false, length = 10)),
@AttributeOverride(name = "ehParExtN", column = @Column(name = "EH_PAR_EXT_N", nullable = false, length = 5)),
@AttributeOverride(name = "ehGroupLvl1Name", column = @Column(name = "EH_GROUP_LVL1_NAME", nullable = false, length = 30)),
@AttributeOverride(name = "ehGroupLvl2Name", column = @Column(name = "EH_GROUP_LVL2_NAME", nullable = false, length = 30)),
@AttributeOverride(name = "ehGroupLvl3Name", column = @Column(name = "EH_GROUP_LVL3_NAME", nullable = false, length = 30)),
@AttributeOverride(name = "ehSubBuId", column = @Column(name = "EH_SUB_BU_ID", nullable = false, length = 5)),
@AttributeOverride(name = "ehSubContrN", column = @Column(name = "EH_SUB_CONTR_N", nullable = false, length = 10)),
@AttributeOverride(name = "ehSubExtN", column = @Column(name = "EH_SUB_EXT_N", nullable = false, length = 5)) })
public HierarchyId getHierarchyId() {
return hierarchyId;
}

public void setHierarchyId(HierarchyId hierarchyId) {
this.hierarchyId = hierarchyId;
}

@OneToOne
@JoinColumns({
@JoinColumn(name = "CR_CONTRACT_BU_ID", referencedColumnName = "EH_SUB_BU_ID"),
@JoinColumn(name = "CR_CONTRACT_N", referencedColumnName = "EH_SUB_CONTR_N"),
@JoinColumn(name = "CR_EXTENSION_N", referencedColumnName = "EH_SUB_EXT_N")


})
protected Contract contract;

public Contract getContract() {
return contract;
}

public void setContract(Contract contract) {
this.contract = contract;
}


Cette table utilise une table de type HierarchyId qui possède tout les attribut colonne de la table, Idem pour la seconde classe

voici la deuxième classe jointe :


@Entity
@Table(name = "Contract", catalog = "o")
public class Contract implements Serializable {

private ContractId contractId;

public Contract() {
}

public Contract(ContractId contractId) {
this.contractId = contractId;
}

@EmbeddedId
@AttributeOverrides({
@AttributeOverride(name = "crPeriodId", column = @Column(name = "CR_PERIOD_ID", nullable = false)),
@AttributeOverride(name = "crCtrId", column = @Column(name = "CR_CTR_ID", nullable = false)),
@AttributeOverride(name = "crCtrName", column = @Column(name = "CR_CTR_NAME", nullable = true, length = 100)),
@AttributeOverride(name = "crCtrCcy", column = @Column(name = "CR_CTR_CCY", nullable = true, length = 3)),
@AttributeOverride(name = "crContractBuId", column = @Column(name = "CR_CONTRACT_BU_ID",nullable = true, length = 5)),
@AttributeOverride(name = "crContractN", column = @Column(name = "CR_CONTRACT_N", nullable = true, length = 10)),
@AttributeOverride(name = "crExtensionN", column = @Column(name = "CR_EXTENSION_N", nullable = true, length = 5)),
@AttributeOverride(name = "crPolStatus", column = @Column(name = "CR_POL_STATUS", nullable = true)),
@AttributeOverride(name = "crpolHldCty", column = @Column(name = "CR_POL_HLD_CTY", nullable = true, length = 3))

})
public ContractId getContractId() {
return contractId;
}

public void setContractId(ContractId contractId) {
this.contractId = contractId;
}




J'ai tenté également d'utiliser une insert en SQL du style String query = "INSERT INTO Hierarchy ( ... ) VALUES (...) mais en vains

erreur rencontré est que le mot clé VALUES n'est pas reconnue


Merci de me débloqué de cette situation
toute solution est la bienvenue http://www.developpez.net/forums/ima...lies/zoubi.gif