Hi List,
I'm using hibernate with the hibernate entity manager and annotation. And 'am getting the exception below.The problem seems to be in that my VersionedPersistentObject class inherits from a Map implementation. Hibernate seems to think that a class which implements Map is a dynamicaly mapped entity and because it cannot find a special key, it just
refuses to persist the object.
I have the feeling that this is not conformant with the EJB3 spec (Entities may extend non entity classes). What do you think about it? Should I report this as a bug?
Here are the details:
Hibernate version: 3.2.2
Entity Classes:
@MappedSuperclass
public abstract class VersionedPersistentObject extends HashMap<Object, Object> implements Serializable {
private Long id;
private Long version;
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
public Long getId() {
return id;
}
protected void setId(Long id) {
this.id = id;
}
@Version
public Long getVersion() {
return version;
}
protected void setVersion(Long version) {
this.version = version;
}
@Override
public String toString() {
return toStringBuffer().toString();
}
/**
* @return Returns the string buffer representation of self. This method is used
* in {@link #toString()}}
*/
protected StringBuffer toStringBuffer() {
return new StringBuffer()
.append(getClass().getName())
.append("[")
.append("id: ")
.append(getId())
.append(", ")
.append("version: ")
.append(getVersion())
.append("]");
}
}
@Entity
@Table(name="events")
public class Event extends VersionedPersistentObject implements IEvent {
private String title;
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
@Override
protected StringBuffer toStringBuffer() {
return super.toStringBuffer()
.append("[")
.append("title: ")
.append(getTitle())
.append("]");
}
public void copyTo(Event event) {
}
}
Code between sessionFactory.openSession() and session.close():
em.getTransaction().begin();
Event e = new Event();
e.setTitle("Title");
e.copyTo(new Event());
em.persist(e);
em.getTransaction().commit();
Full stack trace of any exception that occurs:
Exception in thread "main" javax.persistence.PersistenceException: org.hibernate.HibernateException: could not determine type of dynamic entity
at org.hibernate.ejb.AbstractEntityManagerImpl.throwPersistenceException(AbstractEntityManagerImpl.java:641)
at org.hibernate.ejb.AbstractEntityManagerImpl.persist(AbstractEntityManagerImpl.java:218)
at com.ls.hibernate.EntityManagerTest.main(EntityManagerTest.java:22)
Caused by: org.hibernate.HibernateException: could not determine type of dynamic entity
at org.hibernate.impl.SessionImpl.guessEntityName(SessionImpl.java:1764)
at org.hibernate.impl.SessionImpl.getEntityPersister(SessionImpl.java:1338)
at org.hibernate.engine.ForeignKeys.isTransient(ForeignKeys.java:180)
at org.hibernate.event.def.AbstractSaveEventListener.getEntityState(AbstractSaveEventListener.java:487)
at org.hibernate.event.def.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:70)
at org.hibernate.event.def.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:38)
at org.hibernate.impl.SessionImpl.firePersist(SessionImpl.java:618)
at org.hibernate.impl.SessionImpl.persist(SessionImpl.java:592)
at org.hibernate.impl.SessionImpl.persist(SessionImpl.java:596)
at org.hibernate.ejb.AbstractEntityManagerImpl.persist(AbstractEntityManagerImpl.java:212)
... 1 more
|