Hibernate version:
Core 3.3.1
Annotation 3.4.0
Full stack trace of any exception that occurs:
org.hibernate.PropertyAccessException: could not get a field value by reflection getter of xxx.Category.id
at org.hibernate.property.DirectPropertyAccessor$DirectGetter.get(DirectPropertyAccessor.java:58)
at org.hibernate.tuple.entity.AbstractEntityTuplizer.getIdentifier(AbstractEntityTuplizer.java:206)
at org.hibernate.persister.entity.AbstractEntityPersister.getIdentifier(AbstractEntityPersister.java:3619)
at org.hibernate.persister.entity.AbstractEntityPersister.isTransient(AbstractEntityPersister.java:3335)
at org.hibernate.engine.ForeignKeys.isTransient(ForeignKeys.java:204)
at org.hibernate.engine.ForeignKeys$Nullifier.isNullifiable(ForeignKeys.java:160)
at org.hibernate.engine.ForeignKeys$Nullifier.nullifyTransientReferences(ForeignKeys.java:92)
at org.hibernate.engine.ForeignKeys$Nullifier.nullifyTransientReferences(ForeignKeys.java:70)
at org.hibernate.event.def.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:311)
at org.hibernate.event.def.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:204)
at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:144)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:210)
at org.hibernate.event.def.DefaultSaveEventListener.saveWithGeneratedOrRequestedId(DefaultSaveEventListener.java:56)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:195)
at org.hibernate.event.def.DefaultSaveEventListener.performSaveOrUpdate(DefaultSaveEventListener.java:50)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:93)
at org.hibernate.impl.SessionImpl.fireSave(SessionImpl.java:562)
at org.hibernate.impl.SessionImpl.save(SessionImpl.java:550)
at org.hibernate.impl.SessionImpl.save(SessionImpl.java:546)
Exception while saving object Characteristic.
Exception method: field.get(target);
field - java.lang.reflect.Field( Identity.id )
target - Integer (not null)
My classes and mapping.
Code:
@Entity
@SequenceGenerator(name="genId", sequenceName="characteristics_seq", allocationSize=1)
public class Characteristic extends Identity {
@ManyToOne(targetEntity=Category.class, optional=false)
private Integer category;
...
}
@Entity
@SequenceGenerator(name="genId", sequenceName="categories_seq", allocationSize=1)
public class Category extends Identity {
...
}
@MappedSuperclass
public abstract class Identity implements Identifiable {
@Id
@GeneratedValue(generator="genId")
private Integer id;
...
}
I tried to debug. Maybe the problem is here, but i'm not sure
Code:
public Serializable getIdentifier(Object entity) throws HibernateException {
final Object id;
if ( entityMetamodel.getIdentifierProperty().isEmbedded() ) {
id = entity; //<-- here what i need
}
else {
if ( idGetter == null ) {
...
}
else {
id = idGetter.get( entity ); //<-- what hibernate tries to do
}
}
...