Tuesday 7 June 2016

How to resolve error "Caused by: org.hibernate.MappingException: Unable to find column with logical name: "

If you come across an error as like below

Caused by: org.hibernate.MappingException: Unable to find column with logical name: DESTINATION_ID  in org.hibernate.mapping.Table
(TRAVEL_DETAIL) and its related supertables and secondary tables
at org.hibernate.cfg.Ejb3JoinColumn.checkReferencedColumnsType(Ejb3JoinColumn.java:582)
at org.hibernate.cfg.BinderHelper.createSyntheticPropertyReference(BinderHelper.java:25

Please  remove the referencedColumnName attribute  which is used in Travel class  because destination_id is the primary key field of TravelDetail , referencedColumnName = ""  is only necessary if it references a non-primary-key field.

@Entity
public class Travel{

@Column(name="DESTINATION_ID" , insertable=false, updatable=false)
private java.math.BigDecimal destinationId;

//bi-directional many-to-one association to TravelDetail
@ManyToOne
@JoinColumns({
@JoinColumn(name="DESTINATION_ID" , referencedColumnName = "DESTINATION_ID")
})
private TravelDetail travelDetail;

.
.
.

}

@Entity
Public class TravelDetail{
@Id
@Column(name="\"DESTINATION_ID\"")
private long destinationId;
.
.
.

}

No comments:

Post a Comment