-->
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.  [ 6 posts ] 
Author Message
 Post subject: Insert, commit, no exceptions, but no data either
PostPosted: Wed Apr 12, 2006 6:12 pm 
Newbie

Joined: Wed Apr 12, 2006 5:45 pm
Posts: 3
Location: Zurich, Switzerland
Hi
My problem is that the log looks o.k. with insert statement and commit, but nothing is written to the DB. No exceptions occur. The DB is created with lck, log, script, and properties file. I can open the DB, but it's empty.


Hibernate version: 3.1.2

Code between sessionFactory.openSession() and session.close():
Code:
    Session session = HibernateUtil.getSessionFactory().openSession();
    Transaction tx = null;
    try {
      tx = session.beginTransaction();

      ProductCategory theCategory = new ProductCategory();
      theCategory.setIntlKey(intlKey);
      theCategory.setActive(active);
      theCategory.setOrder(order);
      theCategory.setActiveFrom(activeFrom);
      theCategory.setActiveUntil(activeUntil);

      session.save(theCategory);
      session.getTransaction().commit();
    } catch (HibernateException e) {
      if (tx != null) tx.rollback();
      e.printStackTrace();
    }
    finally {
      session.close();
    }

Full stack trace of any exception that occurs: no exceptions

Name and version of the database you are using: HSQL 1.8.0.1

The generated SQL (show_sql=true): (from log excerpt below)
Code:
drop table CATEGORY if exists
create table CATEGORY (ID bigint generated by default as identity (start with 1), INTL_KEY varchar(8) not null, D_ORDER integer, IS_ACTIVE char(1), FROM_DATE date, TILL_DATE date, primary key (ID))
insert into CATEGORY (INTL_KEY, D_ORDER, IS_ACTIVE, FROM_DATE, TILL_DATE, ID) values (?, ?, ?, ?, ?, null)
commit


Debug level Hibernate log excerpt:
Code:
23:26:07,187  INFO SchemaExport:155 - Running hbm2ddl schema export
23:26:07,187 DEBUG SchemaExport:173 - import file not found: /import.sql
23:26:07,187  INFO SchemaExport:182 - exporting generated schema to database
23:26:07,187 DEBUG SchemaExport:296 - drop table CATEGORY if exists
23:26:07,187 DEBUG SchemaExport:296 - create table CATEGORY (ID bigint generated by default as identity (start with 1), INTL_KEY varchar(8) not null, D_ORDER integer, IS_ACTIVE char(1), FROM_DATE date, TILL_DATE date, primary key (ID))
23:26:07,187  INFO SchemaExport:202 - schema export complete
23:26:07,234 DEBUG JDBCTransaction:54 - begin
23:26:07,234 DEBUG JDBCTransaction:59 - current autocommit status: false
23:26:07,250 DEBUG SQL:346 - insert into CATEGORY (INTL_KEY, D_ORDER, IS_ACTIVE, FROM_DATE, TILL_DATE, ID) values (?, ?, ?, ?, ?, null)
Hibernate: insert into CATEGORY (INTL_KEY, D_ORDER, IS_ACTIVE, FROM_DATE, TILL_DATE, ID) values (?, ?, ?, ?, ?, null)
23:26:07,265 DEBUG StringType:79 - binding 'bouquets' to parameter: 1
23:26:07,265 DEBUG IntegerType:79 - binding '1' to parameter: 2
23:26:07,265 DEBUG YesNoType:79 - binding 'true' to parameter: 3
23:26:07,265 DEBUG DateType:79 - binding '12 April 2006' to parameter: 4
23:26:07,265 DEBUG DateType:79 - binding '12 April 2006' to parameter: 5
23:26:07,265 DEBUG SQL:346 - call identity()
Hibernate: call identity()
23:26:07,281 DEBUG JDBCTransaction:103 - commit
23:26:07,281 DEBUG JDBCTransaction:116 - committed JDBC Connection
23:26:07,281  INFO SessionFactoryImpl:728 - closing
23:26:07,281  INFO DriverManagerConnectionProvider:147 - cleaning up connection pool: jdbc:hsqldb:C:/Data/HSQL/blumenb


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 12, 2006 7:29 pm 
Newbie

Joined: Wed Apr 12, 2006 7:28 pm
Posts: 1
stick in
session.flush();
might help might not!


Top
 Profile  
 
 Post subject:
PostPosted: Sat Apr 15, 2006 1:49 am 
Regular
Regular

Joined: Wed Jul 07, 2004 2:00 pm
Posts: 64
What's with the drop table statement in your debug log? Is it possible that your insert succeeded (as the log indicates), but something dropped and recreated the table again?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 18, 2006 5:42 pm 
Newbie

Joined: Wed Apr 12, 2006 5:45 pm
Posts: 3
Location: Zurich, Switzerland
dilldill wrote:
stick in
session.flush();
might help might not!

Thanks, but this didn't help.
org.hibernate.Session.flush() Javadoc: Transaction.commit() calls this method.
Ursus


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 18, 2006 5:49 pm 
Newbie

Joined: Wed Apr 12, 2006 5:45 pm
Posts: 3
Location: Zurich, Switzerland
DWright wrote:
What's with the drop table statement in your debug log? Is it possible that your insert succeeded (as the log indicates), but something dropped and recreated the table again?

Thanks, but this didn't help either.
I created the table by hand, inserted two rows, and removed the 'Drop and re-create the database schema on startup'. Now I can read from the DB, but I can still not insert.
Ursus


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 20, 2006 3:56 pm 
Regular
Regular

Joined: Wed Jul 07, 2004 2:00 pm
Posts: 64
Looking at the SQL trace again, it looks like it tried inserting a record with a null value for the primary key (ID), even though the table DDL uses auto-increment for the value. How does HQL handle this? Using MySQL with a generator of native or identity, the SQL does not include the ID column. Perhaps you could post your mapping docs?

Also, you could try using JDBC to do an insert after your tx=... line, like:
Connection con = session.connection();
PreparedStatement stmt = con.prepareStatement("insert into CATEGORY (INTL_KEY, D_ORDER, IS_ACTIVE, FROM_DATE, TILL_DATE) values (?, ?, ?, ?, ?)");
stmt.setString(1,"abc");
stmt.setInteger(2,1);
stmt.setString(3,"1");
stmt.setDate(4,new java.sql.Date(10));
stmt.setDate(5,new java.sql.Date(20));
int rows = stmt.executeUpdate();
stmt.close();
//do not close con

Check that the value of rows is 1. Then, after the tx.commit(), check if the record is still there.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 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.