Hibernate: problems with insert and update
Hi, I'm having some problems inserting and updating records on my
application.
The class is Answer. It has a n-1 relation with Question.
When I try to save a new Answer or a modified one, I have this
exception:
org.hibernate.exception.SQLGrammarException: Could not execute JDBC
batch update
org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:
67)
org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:
43)
org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:
253)
org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:235)
org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:139)
org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:
298)
org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:
27)
org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1000)
org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:338)
org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:
106)
reservoirdogs.informaticTrivia.hibernate.facade.AnswerFacade.saveAnswer(AnswerFacade.java:
19)
I'm using a PostgreSQL server, Answer's primary key type is mapped as
"native".
This is the code I use for Answer saving:
public void saveAnswer(Answer answer) {
Session session =
reservoirdogs.informaticTrivia.hibernate.util.HibernateUtil.currentSession();
Transaction tx = session.beginTransaction();
//session.saveOrUpdate(answer);
session.merge(answer);
tx.commit();
reservoirdogs.informaticTrivia.hibernate.util.HibernateUtil.closeSession();
}
What's my mistake? Thanks.