我遇到过这个例外
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;
}
}
注意:省略了setter和getters,我想在这里实现的是在Product类中图片可以为null
答案 0 :(得分:-1)
您的地图中存在错误,referencedColumnName
定位picture_id
表中的TXN_INVENTORY_PICTURE
列,该列不存在。
如果picture_id
是REF_PRODUCT
表中作为TXN_INVENTORY_PICTURE
表的外键的列的名称,则将映射更改为
@OneToOne(optional = true)
@JoinColumn(name="picture_id")
private InventoryItemPicture picture;