Hi,
we tried the same with annotations (We're using EJB3 in JBoss 5, Hibernate 3.2.6), and we have a strange effect...
I try to translate our problemn to that WheeledVehicle example:
Code:
@Entity
@Table(name = "VEHICLES")
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name = "VEHI_DTYPE", discriminatorType = DiscriminatorType.STRING)
@DiscriminatorValue("WheeledVehicle")
public class WheeledVehicle
{
@Id
@GeneratedValue(strategy = GenerationType.AUTO, generator = "VEHI_ID_GENERATOR")
@SequenceGenerator(name = "ORD_ID_GENERATOR", sequenceName = "VEHI_ID_SEQ", allocationSize = 60)
@Digits(integerDigits = 12, fractionalDigits = 0)
private Long vehiId;
@Column
private Long vehiWheels;
}
and we have two derived Entities:
Code:
@Entity
@DiscriminatorValue("Bike")
public class Bike extends WheeledVehicle
{
@Column
private String vehiBrakesBrand;
}
and a Car where we want to add a NotNull Validator to the wheels attriibute:
Code:
@Entity
@DiscriminatorValue("Car")
public class Bike extends WheeledVehicle
{
@Column
@NotNull
private Long vehiWheels;
}
That causes a strange effect, when we try to persist a Bike with vehiWheels = null we receive an error message (see excerpt from StackTrace below)..
Does anyone have an idea why this happens?
Best Regards
Hans
Caused by: org.hibernate.PropertyValueException: not-null property references a null or transient value: Bike.vehiWheels
at org.hibernate.engine.Nullability.checkNullability(Nullability.java:95)
at org.hibernate.event.def.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:312)
at org.hibernate.event.def.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:203)
at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:143)
at org.hibernate.ejb.event.EJB3PersistEventListener.saveWithGeneratedId(EJB3PersistEventListener.java:49)
at org.hibernate.event.def.DefaultPersistEventListener.entityIsTransient(DefaultPersistEventListener.java:154)
at org.hibernate.event.def.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:110)
at org.hibernate.event.def.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:61)
at org.hibernate.impl.SessionImpl.firePersist(SessionImpl.java:648)
at org.hibernate.impl.SessionImpl.persist(SessionImpl.java:622)
at org.hibernate.impl.SessionImpl.persist(SessionImpl.java:626)
at org.hibernate.ejb.AbstractEntityManagerImpl.persist(AbstractEntityManagerImpl.java:220)
... 189 more