Hi, I am newbie with Hibernate, i am doing the first example of the book Hibernate in Action. I am working with PostGreSQL and SQLServer. With SQLServer i haven't problems but with PostGreSQL i have some errors when i use the save method. Can someone help me?. Thanks
Hibernate version: 2.1.7
Mapping documents:
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"hibernate-mapping-2.0.dtd" >
<hibernate-mapping>
<class name="com.pruebas.Messages" table="Messages">
<id name="id" column="id" >
<generator class="increment"/>
</id>
<property name="text" column="text" />
<many-to-one name="nextMessage" cascade="all" column="nextMessage" />
</class>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close():
public static void main(String[] args) {
try{
Configuration cfg = new Configuration();
cfg.addResource("com/pruebas/Message.hbm.xml");
SessionFactory sessions = cfg.buildSessionFactory();
Session session = sessions.openSession();
Transaction tx = session.beginTransaction();
System.out.println("Begin transaction");
Message message = new Message("Real Madrid");
System.out.println(message.getText());
session.save(message);
tx.commit();
System.out.println("End transaction");
session.close();
}
catch(MappingException ex){
System.out.println("ERROR: " + ex.getMessage());
}
catch(HibernateException ex){
System.out.println("ERROR: " + ex.getMessage());
ex.printStackTrace();
}
}
Full stack trace of any exception that occurs:
net.sf.hibernate.exception.SQLGrammarException: Could not execute JDBC batch update
at net.sf.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:59)
at net.sf.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:30)
at net.sf.hibernate.impl.BatcherImpl.convert(BatcherImpl.java:325)
at net.sf.hibernate.impl.BatcherImpl.executeBatch(BatcherImpl.java:134)
at net.sf.hibernate.impl.SessionImpl.executeAll(SessionImpl.java:2441)
at net.sf.hibernate.impl.SessionImpl.execute(SessionImpl.java:2391)
at net.sf.hibernate.impl.SessionImpl.flush(SessionImpl.java:2260)
at net.sf.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:61)
at com.pruebas.Init.main(Init.java:26)
Caused by: java.sql.BatchUpdateException: Batch entry 0 insert into Messages (text, nextMessage, id) values (Real Madrid, NULL, 1) was aborted. Call getNextException to see the cause.
at org.postgresql.jdbc2.AbstractJdbc2Statement$BatchResultHandler.handleError(AbstractJdbc2Statement.java:2392)
at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1257)
at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:334)
at org.postgresql.jdbc2.AbstractJdbc2Statement.executeBatch(AbstractJdbc2Statement.java:2451)
at com.mchange.v2.sql.filter.FilterPreparedStatement.executeBatch(FilterPreparedStatement.java:260)
at net.sf.hibernate.impl.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:54)
at net.sf.hibernate.impl.BatcherImpl.executeBatch(BatcherImpl.java:127)
... 5 more
Name and version of the database you are using: PostGreSQL 8.0.3
The generated SQL (show_sql=true):
insert into Messages (text, nextMessage, id) values (?, ?, ?)
Debug level Hibernate log excerpt:
|