我也遇到了這個例外休眠無法找到邏輯名稱
Caused by:
org.hibernate.MappingException: Unable to find column with logical name: picture_id in org.hibernate.mapping.Table(TXN_INVENTORY_PICTURE) and its related supertables and secondary tables
at org.hibernate.cfg.Ejb3JoinColumn.checkReferencedColumnsType(Ejb3JoinColumn.java:564)
at org.hibernate.cfg.BinderHelper.createSyntheticPropertyReference(BinderHelper.java:258)
at org.hibernate.cfg.ToOneFkSecondPass.doSecondPass(ToOneFkSecondPass.java:116)
at org.hibernate.cfg.Configuration.processEndOfQueue(Configuration.java:1596)
at org.hibernate.cfg.Configuration.processFkSecondPassInOrder(Configuration.java:1519)
at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1420)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1844)
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl$4.perform(EntityManagerFactoryBuilderImpl.java:850)
下面是這些類的要點涉及
@Entity
@Table(name = "REF_PRODUCT")
public class Product extends JpaModel{
@Column(name= "NAME")
private String name;
@Column(name = "MANUFACTURER")
private String manufacturer;
/**
* Work around for missing
*/
@OneToOne(optional = true)
@JoinColumn(name="picture",referencedColumnName = "picture_id")
private InventoryItemPicture picture;
}
而這裏的inventoryItemPicutre
@Entity
@Table(name = "TXN_INVENTORY_PICTURE")
public class InventoryItemPicture extends JpaModel{
@Column
private byte[] image;
@Column
private String fileName;
public InventoryItemPicture(){
}
....
}
而這裏的JPAModel
@MappedSuperclass
public abstract class JpaModel {
@Id
@Column(name ="ID", columnDefinition = "serial")
@GeneratedValue(strategy = GenerationType.SEQUENCE)
private Long id;
@Type(type="org.jadira.usertype.dateandtime.joda.PersistentLocalDateTime")
@Column(name = "created_date")
private DateTime createdDate;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public DateTime getCreatedDate() {
return createdDate;
}
public void setCreatedDate(DateTime createdDate) {
this.createdDate = createdDate;
}
}
注:省略了getter和setter方法,而我想在這裏實現的是該圖片可以在產品類爲空
有一列'picture_id'表'TXN_INVENTORY_PICTURE'? – 2015-03-13 15:42:33
@PredragMaric沒有,但它有一個id字段。 – user962206 2015-03-13 15:48:04