Hibernate version:
Hibernate 3.1
Name and version of the database you are using:
HSQLDB 1.8
Full stack trace of any exception that occurs:
Exception in thread "main" org.hibernate.exception.SQLGrammarException: could not insert: [domain.Student]
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:65)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:1986)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2405)
at org.hibernate.action.EntityIdentityInsertAction.execute(EntityIdentityInsertAction.java:37)
at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:243)
at org.hibernate.event.def.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:269)
at org.hibernate.event.def.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:167)
at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:101)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:186)
at org.hibernate.event.def.DefaultSaveEventListener.saveWithGeneratedOrRequestedId(DefaultSaveEventListener.java:33)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:175)
at org.hibernate.event.def.DefaultSaveEventListener.performSaveOrUpdate(DefaultSaveEventListener.java:27)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:70)
at org.hibernate.impl.SessionImpl.fireSave(SessionImpl.java:544)
at org.hibernate.impl.SessionImpl.save(SessionImpl.java:533)
at org.hibernate.impl.SessionImpl.save(SessionImpl.java:529)
at hibernate.HibernateStartUpManager.saveStudent(HibernateStartUpManager.java:28)
at hibernate.HibernateStartUpManager.main(HibernateStartUpManager.java:12)
Caused by: java.sql.SQLException: Table not found in statement [insert into Student (name, matrikelNr, id) values (?, ?, null)]
at org.hsqldb.jdbc.Util.throwError(Unknown Source)
at org.hsqldb.jdbc.jdbcPreparedStatement.<init>(Unknown Source)
at org.hsqldb.jdbc.jdbcConnection.prepareStatement(Unknown Source)
at org.hibernate.jdbc.AbstractBatcher.getPreparedStatement(AbstractBatcher.java:442)
at org.hibernate.jdbc.AbstractBatcher.prepareStatement(AbstractBatcher.java:93)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:1948)
... 16 more
Ich möchte ein einfaches Domänen-Modell bestehend aus drei Klassen mappen.
Code:
@EmbeddableSuperclass
public abstract class Person {
private String id;
private String name;
public String getName() {
return name;
}
public void setName(String firstName) {
this.name = firstName;
}
@Id(generate=GeneratorType.IDENTITY)
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
}
Code:
@Entity
public class Student extends Person {
private String matrikelNr;
private List<Fach> fächer;
public Student(){}
public String getMatrikelNr() {
return matrikelNr;
}
public void setMatrikelNr(String matrikelNr) {
this.matrikelNr = matrikelNr;
}
@OneToMany
public List<Fach> getFächer() {
return fächer;
}
public void setFächer(List<Fach> fächer) {
this.fächer = fächer;
}
}
Code:
@Entity
public class Professor extends Person {
private String titel;
public Professor(){}
public String getTitel() {
return titel;
}
public void setTitel(String titel) {
this.titel = titel;
}
}
Code:
@Entity
public class Fach {
private String id;
private String bezeichnung;
public Fach(){}
public String getBezeichnung() {
return bezeichnung;
}
public void setBezeichnung(String bezeichnung) {
this.bezeichnung = bezeichnung;
}
@Id(generate=GeneratorType.IDENTITY)
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
}
Initialisieren tu ich Hibernate mit der Hibernate-Util-Klasse, wobei ich die Properties folgendermassen setze:
Code:
static {
try {
AnnotationConfiguration cfg = new AnnotationConfiguration();
cfg.addAnnotatedClass(Person.class)
.addAnnotatedClass(Student.class)
.addAnnotatedClass(Professor.class)
.addAnnotatedClass(Fach.class);
cfg.setProperty("hibernate.connection.driver_class","org.hsqldb.jdbcDriver");
cfg.setProperty("hibernate.connection.url","jdbc:hsqldb:hsql://localhost");
cfg.setProperty("hibernate.connection.username","sa");
cfg.setProperty("hibernate.connection.password","");
cfg.setProperty("hibernate.connection.pool_size","1");
cfg.setProperty("hibernate.dialect","org.hibernate.dialect.HSQLDialect");
cfg.setProperty("hibernate.current_session_context_class","thread");
cfg.setProperty("hibernate.cache.provider_class","org.hibernate.cache.EhCacheProvider");
cfg.setProperty("hibernate.show_sql","true");
cfg.setProperty("hibernate.hbm2ddl.auto","create");
cfg.setProperty("hibernate.connection.shutdown","true");
sessionFactory = cfg.buildSessionFactory();
} catch (Throwable ex) {
// Log exception!
throw new ExceptionInInitializerError(ex);
}
}
Wenn ich versuche einen Studenten in der DB zu speichern kommt obenstehende Exception. Während der Initialisierung wird nur eine Tabelle
STUDENT_FACH angelegt, ansonsten ist die DB leer.
Jemand eine Idee?
Danke + Gruss
SamDutsches