Ok me again :-D
I can't get those annotations to run. And i followed the instructions from the docs.
Code:
<hibernate-configuration>
[...]
<!-- mapping files -->
<mapping package="org.mendrik.suigeneris.model"/>
<mapping class="org.mendrik.suigeneris.model.ModelObject"/>
<mapping class="org.mendrik.suigeneris.model.Project"/>
</session-factory>
</hibernate-configuration>
Then I have:
Code:
@Entity
@Table(name="project")
public class Project extends ModelObject {
private static Logger log = Logger.getLogger(Project.class.getName());
public Project() {
// data = new HashSet<Data>();
}
private String name;
public String getName() {return name;}
public void setName(String name) {this.name = name;}
/*
private Set<Data> data;
public Set<Data> getData() {
return data;
}
*/
public static final Dao<Project> DAO = new Dao<Project>(Project.class);
public Dao<? extends ModelObject> getDao() {
return DAO;
}
}
and
Code:
@MappedSuperclass
public abstract class ModelObject {
@EmbeddedId @GeneratedValue(strategy= GenerationType.IDENTITY)
private Long id;
public Long getId() {return id;}
public void setId(Long id) {this.id = id;}
public abstract Dao<? extends ModelObject> getDao();
}
Now trying:
Code:
<%
Project p = new Project();
p.getDao().save(p);
%>
gives me a frustrating:
org.hibernate.MappingException: Unknown entity: org.mendrik.suigeneris.model.Project
at org.hibernate.impl.SessionFactoryImpl.getEntityPersister(SessionFactoryImpl.java:513)
at org.hibernate.impl.SessionImpl.getEntityPersister(SessionImpl.java:1321)
at org.hibernate.engine.ForeignKeys.isTransient(ForeignKeys.java:180)
at org.hibernate.event.def.AbstractSaveEventListener.getEntityState(AbstractSaveEventListener.java:460)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.performSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:84)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:70)
at org.hibernate.impl.SessionImpl.fireSaveOrUpdate(SessionImpl.java:531)
at org.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java:523)
at org.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java:519)
at org.mendrik.suigeneris.persistence.Dao$1.execute(Dao.java:26)
at org.mendrik.suigeneris.persistence.Transaction.run(Transaction.java:28)
at org.mendrik.suigeneris.persistence.Dao.save(Dao.java:24)