I am migrating from xml
configuration to annotations.
I have Barrier.hbm.xml
file which has:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping schema="inv">
<class name="Barrier" table="INV_BARRIER" >
<composite-id access="field">
<key-many-to-one name="coupon" class="domain.Coupon" column="COUPON_ID"/>
<key-many-to-one name="underlyingUsage" class="domain.Underlying" column="UNDERLYING_USAGE_ID"/>
</composite-id>
<version name="version" type="int" insert="true" access="field">
<column name="VERSION" default="0" />
</version>
<property name="barrierValue" type="big_decimal" column="BARRIER_VALUE"/>
</class>
</hibernate-mapping>
when I'm starting application without any annotation in class then I have an exception:
org.hibernate.AnnotationException: No identifier specified for entity: domain.Barrier
so I added annotations:
package domain;
import legacy.HibernatePersistentObject;
import flexjson.JSON;
import java.io.Serializable;
import java.math.BigDecimal;
import javax.persistence.*;
@Entity
@Table(name = "INV_BARRIER", schema = "inv")
public class Barrier extends HibernatePersistentObject implements Serializable {
@Embeddable
public static class BarrierId implements Serializable {
@ManyToOne
@JoinColumn(name = "COUPON_ID")
private Coupon coupon;
@ManyToOne
@JoinColumn(name = "UNDERLYING_USAGE_ID")
private UnderlyingUsage underlyingUsage;
//getters/setters/constructor/equals/hashcode
}
@EmbeddedId
private BarrierId id;
@Version
@Column(name = "VERSION", nullable = false, columnDefinition = "int default 0")
private Integer version;
@Transient
private Coupon coupon;
private AbstractUnderlyingUsage underlyingUsage;
@Column(name = "BARRIER_VALUE")
private BigDecimal barrierValue;
public Barrier() {
}
}
but now it's worse because I just get:
java.lang.NullPointerException
at org.hibernate.boot.internal.InFlightMetadataCollectorImpl.processFkSecondPassesInOrder(InFlightMetadataCollectorImpl.java:1730)
at org.hibernate.boot.internal.InFlightMetadataCollectorImpl.processSecondPasses(InFlightMetadataCollectorImpl.java:1640)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:709)
without more information. What's wrong here?
That is a bit strange but problem was with Coupon
and UnderlyingUsage
classes. They were also extending other classes and I had to add annotations to them as well. Once annotations for whole hierarchy for Coupon
and UnderlyingUsage
were added then error disappeard.
So if someone will face the same issue please look into all classes related to the one which you change.