-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Errors with save method
PostPosted: Fri Oct 14, 2005 10:30 am 
Newbie

Joined: Fri Oct 14, 2005 6:22 am
Posts: 7
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:


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 14, 2005 10:49 am 
Expert
Expert

Joined: Wed Apr 06, 2005 5:03 pm
Posts: 273
Location: Salt Lake City, Utah, USA
Is your nextMessage column nullable in your PostgreSQL database?

_________________
nathan


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.