Hi, I'm getting a "
java.sql.SQLException: Try to insert null into a non-nullable column in statement" in my very simple application. I have a POJO with an Integer PK that looks like:
Code:
/**
* @hibernate.class
* table="conferences"
*/
public class Conference implements Serializable {
...
/**
* @hibernate.id
* column="PK_ID"
* generator-class="native"
*/
public Integer getId() {
return id;
}
...
}
From a SessionBean I'm trying to save an object of the type shown above
Code:
/**
* @ejb.interface-method
* @ejb.transaction
* type="NotSupported"
*
* @return
*/
public boolean saveConference(Conference conference) {
boolean result = true;
System.out.println("Saving " + conference);
Session session = null;
try {
session = sessionFactory.openSession();
session.save(conference);
} catch (HibernateException hex) {
result = false;
throw new EJBException("Could not retrieve list of conferences", hex);
} finally {
if (session != null) {
try {
session.close();
} catch (HibernateException e) {
// do nothing, just log it
}
}
}
return result;
}
It doesn't matter if I set the value of the id field or not, I always get the exception. From the println added to the code above I can see that the value is in the object right before the call to session.save
The server output and stack trace is shown below.
Any help would be greatly appreaciated.
04:06:03,320 INFO [STDOUT] Saving [Conference] id = null, name = Apress OSC, description = Apress Open Source Conference, st
art date = Sun Jan 18 04:06:03 EST 2004, end date = Sun Jan 18 04:06:03 EST 2004, tracks = 3
04:06:03,330 INFO [STDOUT] Hibernate: insert into conferences (name, description, startDate, endDate, abstractSubmissionStar
tDate, abstractSubmissionEndDate, PK_ID) values (?, ?, ?, ?, ?, ?, null)
04:06:03,340 WARN [JDBCExceptionReporter] SQL Error: -10, SQLState: 23000
04:06:03,340 ERROR [JDBCExceptionReporter] Try to insert null into a non-nullable column in statement [insert into conference
s (name, description, startDate, endDate, abstractSubmissionStartDate, abstractSubmissionEndDate, PK_ID) values ('Apress OSC'
, 'Apress Open Source Conference', '2004-01-18 04:06:03.29', '2004-01-18 04:06:03.29', '2004-01-18 04:06:03.29', '2004-01-18
04:06:03.29', null)]
04:06:03,340 WARN [JDBCExceptionReporter] SQL Error: -10, SQLState: 23000
04:06:03,340 ERROR [JDBCExceptionReporter] Try to insert null into a non-nullable column in statement [insert into conference
s (name, description, startDate, endDate, abstractSubmissionStartDate, abstractSubmissionEndDate, PK_ID) values ('Apress OSC'
, 'Apress Open Source Conference', '2004-01-18 04:06:03.29', '2004-01-18 04:06:03.29', '2004-01-18 04:06:03.29', '2004-01-18
04:06:03.29', null)]
04:06:03,340 ERROR [JDBCExceptionReporter] could not insert: [com.ejdoab.pojos.Conference]
java.sql.SQLException: Try to insert null into a non-nullable column in statement [insert into conferences (name, description
, startDate, endDate, abstractSubmissionStartDate, abstractSubmissionEndDate, PK_ID) values ('Apress OSC', 'Apress Open Sourc
e Conference', '2004-01-18 04:06:03.29', '2004-01-18 04:06:03.29', '2004-01-18 04:06:03.29', '2004-01-18 04:06:03.29', null)]
at org.hsqldb.Trace.getError(Unknown Source)
at org.hsqldb.Result.<init>(Unknown Source)
at org.hsqldb.jdbcConnection.executeHSQL(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 org.jboss.resource.adapter.jdbc.WrappedPreparedStatement.executeUpdate(WrappedPreparedStatement.java:308)
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 com.ejdoab.beans.ConferenceHibernateFacadeBean.saveConference(ConferenceHibernateFacadeBean.java:127)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at org.jboss.ejb.StatelessSessionContainer$ContainerInterceptor.invoke(StatelessSessionContainer.java:629)
at org.jboss.resource.connectionmanager.CachedConnectionInterceptor.invoke(CachedConnectionInterceptor.java:186)
at org.jboss.ejb.plugins.StatelessSessionInstanceInterceptor.invoke(StatelessSessionInstanceInterceptor.java:72)
at org.jboss.ejb.plugins.AbstractTxInterceptor.invokeNext(AbstractTxInterceptor.java:84)
at org.jboss.ejb.plugins.TxInterceptorCMT.runWithTransactions(TxInterceptorCMT.java:216)
at org.jboss.ejb.plugins.TxInterceptorCMT.invoke(TxInterceptorCMT.java:104)
at org.jboss.ejb.plugins.SecurityInterceptor.invoke(SecurityInterceptor.java:117)
at org.jboss.ejb.plugins.LogInterceptor.invoke(LogInterceptor.java:191)
at org.jboss.ejb.plugins.ProxyFactoryFinderInterceptor.invoke(ProxyFactoryFinderInterceptor.java:122)
at org.jboss.ejb.StatelessSessionContainer.internalInvoke(StatelessSessionContainer.java:322)
at org.jboss.ejb.Container.invoke(Container.java:674)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at org.jboss.mx.capability.ReflectedMBeanDispatcher.invoke(ReflectedMBeanDispatcher.java:284)
at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:549)
at org.jboss.invocation.jrmp.server.JRMPInvoker.invoke(JRMPInvoker.java:359)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:261)
at sun.rmi.transport.Transport$1.run(Transport.java:148)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.Transport.serviceCall(Transport.java:144)
at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:460)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:701)
at java.lang.Thread.run(Thread.java:534)
04:06:03,340 ERROR [LogInterceptor] EJBException, causedBy:
net.sf.hibernate.JDBCException: could not insert: [com.ejdoab.pojos.Conference]
at net.sf.hibernate.persister.EntityPersister.insert(EntityPersister.java:541)
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 com.ejdoab.beans.ConferenceHibernateFacadeBean.saveConference(ConferenceHibernateFacadeBean.java:127)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at org.jboss.ejb.StatelessSessionContainer$ContainerInterceptor.invoke(StatelessSessionContainer.java:629)
at org.jboss.resource.connectionmanager.CachedConnectionInterceptor.invoke(CachedConnectionInterceptor.java:186)
at org.jboss.ejb.plugins.StatelessSessionInstanceInterceptor.invoke(StatelessSessionInstanceInterceptor.java:72)
at org.jboss.ejb.plugins.AbstractTxInterceptor.invokeNext(AbstractTxInterceptor.java:84)
at org.jboss.ejb.plugins.TxInterceptorCMT.runWithTransactions(TxInterceptorCMT.java:216)
at org.jboss.ejb.plugins.TxInterceptorCMT.invoke(TxInterceptorCMT.java:104)
at org.jboss.ejb.plugins.SecurityInterceptor.invoke(SecurityInterceptor.java:117)
at org.jboss.ejb.plugins.LogInterceptor.invoke(LogInterceptor.java:191)
at org.jboss.ejb.plugins.ProxyFactoryFinderInterceptor.invoke(ProxyFactoryFinderInterceptor.java:122)
at org.jboss.ejb.StatelessSessionContainer.internalInvoke(StatelessSessionContainer.java:322)
at org.jboss.ejb.Container.invoke(Container.java:674)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at org.jboss.mx.capability.ReflectedMBeanDispatcher.invoke(ReflectedMBeanDispatcher.java:284)
at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:549)
at org.jboss.invocation.jrmp.server.JRMPInvoker.invoke(JRMPInvoker.java:359)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:261)
at sun.rmi.transport.Transport$1.run(Transport.java:148)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.Transport.serviceCall(Transport.java:144)
at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:460)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:701)
at java.lang.Thread.run(Thread.java:534)
Caused by: java.sql.SQLException: Try to insert null into a non-nullable column in statement [insert into conferences (name,
description, startDate, endDate, abstractSubmissionStartDate, abstractSubmissionEndDate, PK_ID) values ('Apress OSC', 'Apress
Open Source Conference', '2004-01-18 04:06:03.29', '2004-01-18 04:06:03.29', '2004-01-18 04:06:03.29', '2004-01-18 04:06:03.
29', null)]
at org.hsqldb.Trace.getError(Unknown Source)
at org.hsqldb.Result.<init>(Unknown Source)
at org.hsqldb.jdbcConnection.executeHSQL(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 org.jboss.resource.adapter.jdbc.WrappedPreparedStatement.executeUpdate(WrappedPreparedStatement.java:308)
at net.sf.hibernate.persister.EntityPersister.insert(EntityPersister.java:502)
... 39 more