This is my main:
==========
Code:
public static void main(String[] args) throws MappingException, HibernateException {
Configuration cfg = new Configuration();
cfg.addClass(Customer.class);
SessionFactory sessions = cfg.buildSessionFactory();
Session session = sessions.openSession();
Transaction tx = null;
Customer c=new Customer();
c.setFirstName("Jeff");
c.setLastName("Halleux");
try {
tx = session.beginTransaction();
session.save(c);
tx.commit();
} catch (HibernateException he) {
if (tx != null)
tx.rollback();
throw he;
} finally {
session.close();
}
}
The customer class:
-----------------------
Quote:
package jfh.hibernatetest;
public class Customer {
private Long id;
private String firstName;
private String lastName;
public Customer() {
}
public String getFirstName() {
return firstName;
}
public Long getId() {
return id;
}
public String getLastName() {
return lastName;
}
public void setFirstName(String string) {
firstName = string;
}
public void setId(Long along) {
id = along;
}
public void setLastName(String string) {
lastName = string;
}
}
...and the relevant part of the log:
---------------------------------------
Quote:
21:24:52,333 DEBUG SQL:223 - insert into Customer (firstName, lastName, id) values (?, ?, null)
21:24:52,333 DEBUG BatcherImpl:227 - preparing statement
21:24:52,343 DEBUG EntityPersister:389 - Dehydrating entity: [jfh.hibernatetest.Customer#<null>]
21:24:52,353 DEBUG JDBCExceptionReporter:36 - SQL Exception
java.sql.SQLException: Try to insert null into a non-nullable column in statement [insert into Customer (firstName, lastName, id) values ('Jeff', 'Halleux', null)]
at org.hsqldb.Trace.getError(Unknown Source)
at org.hsqldb.jdbcResultSet.<init>(Unknown Source)
at org.hsqldb.jdbcConnection.executeStandalone(Unknown Source)
at org.hsqldb.jdbcConnection.execute(Unknown Source)
at org.hsqldb.jdbcStatement.fetchResult(Unknown Source)
at org.hsqldb.jdbcStatement.executeUpdate(Unknown Source)
at org.hsqldb.jdbcPreparedStatement.executeUpdate(Unknown Source)
at net.sf.hibernate.persister.EntityPersister.insert(EntityPersister.java:502)
at net.sf.hibernate.persister.EntityPersister.insert(EntityPersister.java:433)
at net.sf.hibernate.impl.SessionImpl.doSave(SessionImpl.java:876)
at net.sf.hibernate.impl.SessionImpl.doSave(SessionImpl.java:817)
at net.sf.hibernate.impl.SessionImpl.saveWithGeneratedIdentifier(SessionImpl.java:737)
at net.sf.hibernate.impl.SessionImpl.save(SessionImpl.java:717)
at jfh.hibernatetest.Main.main(Main.java:26)
Note that I'm executing all of this inside Eclipse.[/code]