0

我试图将表映射到实体类并对其使用 hql 查询。我在 Eclipse 中工作,我尝试在 Hibernate 控制台中执行 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", uniqueConstraints=@UniqueConstraint(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 查询是“SELECT fw FROM FirmwareImage fw left join fw.properties as fp”

我无法弄清楚为什么我会得到那个例外。请有人提出解决方案。

4

1 回答 1

0

例如,将 @annotation 移动到 getter

private String name;

@Column(name="NAME")
public String getName(){
     return name;
}
于 2013-04-15T19:03:21.060 回答