Hi, I am relatively new to using Hibernate. I have two tables which I have tried to map unsuccesfully.
Table 1:
Primary Key(Instrument) -> Generated using function.
Table 2:
Primary Key(Instrument) -> Referenced from primary key of table 1
Table 3:
Primary Key(Instrument) -> Referenced from primary key of table 2
Additional Column(Parent_Instrument) -> Referenced from the primary key of table 2
So, two columns in Table 3 have to be mapped to the primary key of table 2.
I have tried mapping them but am getting the following error:
Caused by: org.hibernate.MappingException: Repeated column in mapping for entity: com.db.csb.model.securitycreation.entities.tradegate.WiBonds column: INSTRUMENT (should be mapped with insert="false" update="false")
at org.hibernate.mapping.PersistentClass.checkColumnDuplication(PersistentClass.java:652)
at org.hibernate.mapping.PersistentClass.checkPropertyColumnDuplication(PersistentClass.java:674)
at org.hibernate.mapping.PersistentClass.checkColumnDuplication(PersistentClass.java:696)
at org.hibernate.mapping.PersistentClass.validate(PersistentClass.java:450)
at org.hibernate.mapping.RootClass.validate(RootClass.java:192)
at org.hibernate.cfg.Configuration.validate(Configuration.java:1102)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1287)
at org.hibernate.cfg.AnnotationConfiguration.buildSessionFactory(AnnotationConfiguration.java:915)
at org.springframework.orm.hibernate3.LocalSessionFactoryBean.newSessionFactory(LocalSessionFactoryBean.java:807)
at org.springframework.orm.hibernate3.LocalSessionFactoryBean.buildSessionFactory(LocalSessionFactoryBean.java:740)
at org.springframework.orm.hibernate3.AbstractSessionFactoryBean.afterPropertiesSet(AbstractSessionFactoryBean.java:131)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1062)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1029)
... 32 more
The following is my code:
TABLE 2
@Entity
@Table(name="BOND_SPEC")
@Id
@GenericGenerator
@GeneratedValue
@Column(name="INSTRUMENT", nullable=false,insertable=false,updatable=false)
public long getInstrument() {
return instrument;
}
public void setInstrument(long instrument) {
this.instrument = instrument;
}
@OneToMany
@JoinColumn(name = "INSTRUMENT", nullable=false, insertable=false)
public Set<WiBonds> getWiBonds(){
return Wi_Bonds;
}
public void setWiBonds(Set<WiBonds> Wi_Bonds){
this.Wi_Bonds = Wi_Bonds;
}
TABLE 3
@Entity
@Table(name="WI_BONDS")
@Id
@GenericGenerator(name = "fk_bondspec", strategy = "foreign", parameters = { @Parameter(name = "property", value = "BondSpec") })
@GeneratedValue(generator = "fk_bondspec")
@Column(name="INSTRUMENT", nullable=false,insertable=false,updatable=false)
public long getInstrument() {
return instrument;
}
public void setInstrument(long instrument) {
this.instrument = instrument;
}
@ManyToOne(targetEntity = BondSpec.class)
@JoinColumn(name = "INSTRUMENT", nullable = false, insertable=false, updatable=false)
public BondSpec getBondSpec() {
}
public void setbondSpec(BondSpec bondspec) {
}
@OneToOne(targetEntity = BondSpec.class)
@JoinColumn(name = "PARENT_INSTRUMENT", nullable = false, insertable = false, updatable = false, unique=true)
public long getParent_instrument() {
}
public void setParent_instrument(long parent_instrument) {
}
What am I doing wrong?