Hallo, ich versuche gerade, mittels Hibernate Personendaten, die in einerm csv-file stehen in eine Datenbank zu schreiben. Zu folgendem Code kommt untenstehende Fehlermeldung, die ich nicht wegbekomme. Hat jemand vielleicht eine Idee, wie ich das lösen könnte?
Code:
personHome = new PersonHome(session);
person = null;
try {
while ((str = breader.readLine()) != null) {
if (!str.equals("")) {
try {
tx = manager.beginTransaction(session);
} catch (HibernateException he) {
LOG
.error(
"begin Transaction failed (PersonImport.perform",
he);
manager.closeSession(session);
throw new JobErrorException(
"begin Transaction failed (PersonImport.perform",
-1);
}
String splitted[] = str.split(";");
var1 = new String(splitted[0].trim());
var2 = new String(splitted[1].trim());
var3 = new String(splitted[2].trim());
var4 = splitted[3].trim();
var5 = splitted[4].trim();
person = new Person();
cty.setId(new Long(a));
cty.setBla(b);
cty.setbla2(c);
try {
personHome.attachDirty(person);
} catch (RuntimeException re) {
LOG
.error(
"attachDirty failed (PersonImport.perform)",
re);
manager.rollbackTransaction(session, tx);
throw new JobErrorException(
"attachDirty failed (PersonImport.perform)",
-4);
}
try {
manager.commitTransaction(tx);
} catch (HibernateException he) {
LOG
.error(
"commitTransaction failed (PersonImport.perform)",
he);
manager.rollbackTransaction(session, tx);
throw new JobErrorException(
"attachDirty failed (PersonImport.perform)",
-6);
}
counter++;
}
Full stack trace of any exception that occurs:Code:
2007-06-12 13:28:20,172 ERROR [main] (SessionManager.java:137) - commit transaction failed
org.hibernate.PropertyValueException: not-null property references a null or transient value: .Person.key
at org.hibernate.engine.Nullability.checkNullability(Nullability.java:72)
at org.hibernate.event.def.DefaultFlushEntityEventListener.scheduleUpdate(DefaultFlushEntityEventListener.java:256)
at org.hibernate.event.def.DefaultFlushEntityEventListener.onFlushEntity(DefaultFlushEntityEventListener.java:114)
at org.hibernate.event.def.AbstractFlushingEventListener.flushEntities(AbstractFlushingEventListener.java:195)
at org.hibernate.event.def.AbstractFlushingEventListener.flushEverythingToExecutions(AbstractFlushingEventListener.java:76)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:26)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:985)
at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:333)
at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:106)
at *.SessionManager.commitTransaction(SessionManager.java:135)
at *Person.perform(PersonImport.java:276)
at *.JobProcessor.<init>(JobProcessor.java:91)
at *.JobProcessor.main(JobProcessor.java:48)
org.hibernate.PropertyValueException: not-null property references a null or transient value: *.Person.key
at org.hibernate.engine.Nullability.checkNullability(Nullability.java:72)
at org.hibernate.event.def.DefaultFlushEntityEventListener.scheduleUpdate(DefaultFlushEntityEventListener.java:256)
at org.hibernate.event.def.DefaultFlushEntityEventListener.onFlushEntity(DefaultFlushEntityEventListener.java:114)
at org.hibernate.event.def.AbstractFlushingEventListener.flushEntities(AbstractFlushingEventListener.java:195)
at org.hibernate.event.def.AbstractFlushingEventListener.flushEverythingToExecutions(AbstractFlushingEventListener.java:76)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:26)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:985)
at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:333)
at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:106)
at *.SessionManager.commitTransaction(SessionManager.java:135)
at *.PersonImport.perform(PersonImport.java:276)
at *.JobProcessor.<init>(JobProcessor.java:91)
at *.JobProcessor.main(JobProcessor.java:48)
2007-06-12 13:28:20,250 ERROR [main] (PersonImport.java:279) - commitTransaction failed (PersonImport.perform)
org.hibernate.PropertyValueException: not-null property references a null or transient value: *.Person.key
at org.hibernate.engine.Nullability.checkNullability(Nullability.java:72)
at org.hibernate.event.def.DefaultFlushEntityEventListener.scheduleUpdate(DefaultFlushEntityEventListener.java:256)
at org.hibernate.event.def.DefaultFlushEntityEventListener.onFlushEntity(DefaultFlushEntityEventListener.java:114)
at org.hibernate.event.def.AbstractFlushingEventListener.flushEntities(AbstractFlushingEventListener.java:195)
at org.hibernate.event.def.AbstractFlushingEventListener.flushEverythingToExecutions(AbstractFlushingEventListener.java:76)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:26)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:985)
at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:333)
at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:106)
at *.SessionManager.commitTransaction(SessionManager.java:135)
at *.PersonImport.perform(PersonImport.java:276)
at *.JobProcessor.<init>(JobProcessor.java:91)
at *.JobProcessor.main(JobProcessor.java:48)
2007-06-12 13:28:20,250 ERROR [main] (JobProcessor.java:99) - error during execution of job: personImport, errorcode: -6
*: attachDirty failed (PersonImport.perform)
at *.PersonImport.perform(PersonImport.java:283)
at *.JobProcessor.<init>(JobProcessor.java:91)
at *.JobProcessor.main(JobProcessor.java:48)
Wenn ich das manager.commitTransaction(tx); auskommentiere, dann verschwinden zwar die Fehler aber es werden keine Daten in die DB geschrieben. Vielen Dank schon mal für eventeulle Hilfestellungen,
Gruß Basti
DB2