2013-04-10 58 views
0

我試圖將表映射到實體類中,並對它們使用hql查詢。我在Eclipse中工作,我嘗試在Hibernate控制檯中執行HQL查詢。在查詢中給出的結果如預期,但是當我部署了我的申請,我得到了錯誤:執行hql的例外

org.hibernate.exception.SQLGrammarException: 
could not initialize a collection: [com.alu.mdm.entities.firmware.FirmwareImage.properties#3014] 

    ORA-00904: "PROPERTIES0_"."FIRMWARE": invalid identifier 

當我看到SQL啓用日誌,我發現該查詢是這樣的:

select properties0_.FIRMWARE_ID as FIRMWARE4_23_1_, 
properties0_.firmware as firmware1_, 
properties0_.firmware as firmware19_0_, 
properties0_.NAME as NAME19_0_, 
properties0_.VALUE as VALUE19_0_ 
from FW_PROPERTIES properties0_ 
where properties0_.FIRMWARE_ID=? 

我有兩個表一個是FIRMWAREIMAGE等是FW_PROPERTIES它看起來像這樣

@Table(name = "FIRMWARE_IMAGE",uniqueConstraints= 
@UniqueConstraint(columnNames = {"IMAGE_NAME"})) 
@org.hibernate.annotations.Table(appliesTo = "FIRMWARE_IMAGE") 
public class FirmwareImage extends PersistentObject { 

@Id 
@Column(name = "ID") 
@GeneratedValue(strategy=GenerationType.SEQUENCE, generator="FIRMWARE_IMAGE_SEQUENCE") 
private Long id; 

@Column(name = "IMAGE_NAME", nullable = false) 
private String name; 

@OneToMany(fetch = FetchType.EAGER) 
@Cascade({CascadeType.ALL, CascadeType.DELETE_ORPHAN}) 
@JoinColumn(name="FIRMWARE_ID") 
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE, region = "com.alu.mdm.entities.firmware") 
private Set<FirmwareImageProperty> properties = new LinkedHashSet<FirmwareImageProperty>(); 

//一些getter和setter

我FW_PROPERTIES實體類是像

@Entity 
@Table(name="FW_PROPERTIES", [email protected](columnNames=  {"FIRMWARE_ID","NAME","VALUE"})) 
@org.hibernate.annotations.Table(appliesTo="FW_PROPERTIES") 
public class FirmwareImageProperty extends Persistence implements Serializable{ 

/** 
* 
*/ 
private static final long serialVersionUID = 5574911511734379510L; 


@Id 
@PrimaryKeyJoinColumns(value={@PrimaryKeyJoinColumn(name="FIRMWARE_ID"), @PrimaryKeyJoinColumn(name="NAME")}) 



@ManyToOne(optional=true) 
@JoinColumn(name="FIRMWARE_ID" , nullable=false) 
@ForeignKey(name="FK_FW_PROPERTIES_FIRMWARE_ID") 
private FirmwareImage firmware; 


@Column(name="NAME") 
private String name; 

@Lob 
@Column(name="VALUE") 
private String value; 

    //Some getters and setters 

我的HQL查詢「選擇從FW FW FirmwareImage左連接fw.properties爲FP」

我無法弄清楚爲什麼我收到這個異常。請有人提出解決方案。

+0

「當ORA-00904時,必須輸入一個有效的列名,因爲它是丟失或進入一個無效」。你確定你有有效的列名嗎? – kosa 2013-04-10 18:42:13

+0

也許你沒有部署最新版本。查詢查找FW_PROPERTIES表中的FIRMWARE列,但您沒有(再?)這樣的映射。 – dcernahoschi 2013-04-10 18:53:36

+0

我的表沒有FIRMWARE列。即使在實體類中我也沒有定義它。但仍然在查詢它正在考慮該列。我沒有得到我犯了錯誤的地方。 – user2267399 2013-04-11 06:01:04

回答

0

移動@annotation至干將,例如

private String name; 

@Column(name="NAME") 
public String getName(){ 
    return name; 
}