////////////////// 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();
...
上的說明query.list();拋出的異常 - [java] 4085 [「http-apr-8080」-exec-10] ERROR org.hibernate.util.JDBCExceptionReporter - ORA-00904:「GBLOADFORE0 _」。「GBCAPACITYENTITY_ORG_ID」:?????? ?????? ?????????????
有人知道爲什麼嗎?我會很感激! : - )
=========================================
添加@ JoinColumn註解的子類,而現在它看起來像這樣 -
////////////////// 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;
}
...
但現在另一個例外 - 產生的原因:org.hibernate.MappingException:在實體映射重複列:com.intellex。 marksist.hbn.model.GbLoadForecast列:ORG_ID(應該被映射爲insert =「false」update =「false」)
事情是,我懷疑有一堆相同字段名稱ORG_ID列的名稱與表格MARKSIST.GB_LOAD_FORECAST中以及表格MARKSIST.GB_CAPACITY中的相同。或者不是嗎?
嗨,JB Nizet!是的,它幫助,謝謝! :-) – 2012-03-29 12:16:19