Confronted with the problem –
////////////////// GbCapacityEntity class //////////////////
@Entity
@Cache(usage = org.hibernate.annotations.CacheConcurrencyStrategy.NONE)
@Table(name = "MARKSIST.GB_CAPACITY")
public class GbCapacityEntity {
@Id
@Column(name = "ORG_ID")
private Integer orgId;
...
@OneToMany(cascade = CascadeType.ALL,fetch=FetchType.LAZY,mappedBy="gbCapacityEntity")
private List<GbLoadForecast> gbLoadForecast;
/**
*
* @return
*/
public List<GbLoadForecast> getGbLoadForecast() {
return gbLoadForecast;
}
/**
*
* @param gbLoadForecast
*/
public void setGbLoadForecast(List<GbLoadForecast> gbLoadForecast) {
this.gbLoadForecast = gbLoadForecast;
}
////////////////// GbLoadForecast class //////////////////
@Entity
@Cache(usage = org.hibernate.annotations.CacheConcurrencyStrategy.NONE)
@Table(name = "MARKSIST.GB_LOAD_FORECAST")
public class GbLoadForecast {
@Id
@Column(name = "ORG_ID")
private Integer orgId;
...
@ManyToOne(cascade = {CascadeType.REFRESH}, fetch = FetchType.LAZY)
private GbCapacityEntity gbCapacityEntity;
/**
* @return
*/
public GbCapacityEntity getGbCapacityEntity() {
return gbCapacityEntity;
}
/**
* @param gbLoadForecast
*/
public void setGbCapacityEntity(GbCapacityEntity gbCapacityEntity) {
this.gbCapacityEntity = gbCapacityEntity;
}
...
////////////////// Some query //////////////////
String hql = "FROM com.intellex.marksist.hbn.model.GbLoadForecast E " +
"WHERE E.orgId = :id1 AND E.cargoGroup = :id2";
Session session = HibernateUtil.getMarksistSessionFactory().openSession();
session.beginTransaction();
Query query = session.createQuery(hql);
query.setParameter("id1", orgId);
query.setParameter("id2", gcId);
List results = query.list();
session.close();
...
On the instructions query.list(); thrown exception –
[java] 4085 [“http-apr-8080”-exec-10] ERROR org.hibernate.util.JDBCExceptionReporter – ORA-00904: “GBLOADFORE0_”.”GBCAPACITYENTITY_ORG_ID”: ???????????? ?????????????
Anybody know why? I would be very grateful! : -)
=========================================
Added @ JoinColumn annotation in the child class, and now it looks like this –
////////////////// GbLoadForecast class //////////////////
@Entity
@Cache(usage = org.hibernate.annotations.CacheConcurrencyStrategy.NONE)
@Table(name = "MARKSIST.GB_LOAD_FORECAST")
public class GbLoadForecast {
@Id
@Column(name = "ORG_ID")
private Integer orgId;
...
@ManyToOne(cascade = {CascadeType.REFRESH}, fetch = FetchType.LAZY)
@JoinColumn(name = "ORG_ID")
private GbCapacityEntity gbCapacityEntity;
/**
* @return
*/
public GbCapacityEntity getGbCapacityEntity() {
return gbCapacityEntity;
}
/**
* @param gbLoadForecast
*/
public void setGbCapacityEntity(GbCapacityEntity gbCapacityEntity) {
this.gbCapacityEntity = gbCapacityEntity;
}
...
But now another exception – Caused by: org.hibernate.MappingException: Repeated column in mapping for entity: com.intellex.marksist.hbn.model.GbLoadForecast column: ORG_ID (should be mapped with insert = “false” update = “false” )
The thing is, i suspect that there are a bunch of the same name of the field-name ORG_ID column is as in table MARKSIST.GB_LOAD_FORECAST, and in the table MARKSIST.GB_CAPACITY. Or is not it?
Let’s examine this mapping:
This means that the ID is mapped to the column
ORG_ID, and that you also have a column, which is a foreign key to the GB_CAPACITY.ORG_ID column, and which is also namedORG_ID.You can’t have two columns with the same name in the same table. Choose a different name for your join column: