-->
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.  [ 14 posts ] 
Author Message
 Post subject: Data are not persisted to Oracle but to mySQL
PostPosted: Thu Nov 25, 2004 7:20 am 
Beginner
Beginner

Joined: Thu Nov 25, 2004 7:07 am
Posts: 43
Location: Germany
Hi all,

I started evaluating Hibernate for our company. I ran into one problem which seems to be easy, but I can't find the fault right now. Maybe someone has a hint for me.

I have some (simple) mapping class for a CD. My GUI has a button to add a CD to the database. The code works (now) without any exceptions but data are not stored in the DB if I use an Oracle DB (Oracle 9iR2). When I switch my application to use mySQL everything works fine.

The log seems to be ok. I am using JDK 1.4.2_05 with new ojdbc14.jar JDBC drivers for Oracle.

TIA,
Axel

Hibernate version:
2.1.7c
Mapping documents:
Code:
<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE hibernate-mapping
   PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN"
   "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">

<hibernate-mapping package="de.innosystec.hibernate.demo.middleware">
   <class name="CompactDisc" table="compact_disc">
      <id name="id" unsaved-value="null" type="int">
         <column name="id" sql-type="NUMBER" not-null="true" />
         <generator class="hilo" />
      </id>
      <property name="title" />
      <property name="artist" />
      <property name="purchaseDate" column="purchase_date" type="date" />
      <property name="cost" type="double" />
   </class>
</hibernate-mapping>

Code between sessionFactory.openSession() and session.close():
Code:
CompactDisc cd = new CompactDisc();
cd.setArtist(artistField.getText());
cd.setTitle(titleField.getText());
cd.setPurchaseDate(new Timestamp(System.currentTimeMillis()));
               cd.setCost(Double.parseDouble(costField.getText()));
               
try {
        Session session = sessionFactory.openSession();
   session.save(cd);
   session.flush();
   session.close();
} catch (Exception ex) {
   ex.printStackTrace();
}

Full stack trace of any exception that occurs:
No Exception occurs!!!
Name and version of the database you are using:
Oracle 9iR2 -> not working
mySQL 3.23.58 -> working
The generated SQL (show_sql=true):
Code:
insert into compact_disc (title, artist, purchase_date, cost, id) values (?, ?, ?, ?, ?)

Debug level Hibernate log excerpt:
Code:
2004-11-25 12:17:42,462 [main] DEBUG net.sf.hibernate.impl.SessionFactoryImpl - instantiated session factory
2004-11-25 12:17:54,649 [AWT-EventQueue-0] DEBUG net.sf.hibernate.impl.SessionImpl - opened session
2004-11-25 12:17:54,659 [AWT-EventQueue-0] DEBUG net.sf.hibernate.connection.DriverManagerConnectionProvider - total checked-out connections: 0
2004-11-25 12:17:54,659 [AWT-EventQueue-0] DEBUG net.sf.hibernate.connection.DriverManagerConnectionProvider - using pooled JDBC connection, pool size: 0
2004-11-25 12:17:54,709 [AWT-EventQueue-0] DEBUG net.sf.hibernate.connection.DriverManagerConnectionProvider - returning connection to pool, pool size: 1
2004-11-25 12:17:54,709 [AWT-EventQueue-0] DEBUG net.sf.hibernate.id.TableHiLoGenerator - new hi value: 17
2004-11-25 12:17:54,709 [AWT-EventQueue-0] DEBUG net.sf.hibernate.impl.SessionImpl - generated identifier: 557057
2004-11-25 12:17:54,709 [AWT-EventQueue-0] DEBUG net.sf.hibernate.impl.SessionImpl - saving [de.innosystec.hibernate.demo.middleware.CompactDisc#557057]
2004-11-25 12:17:54,709 [AWT-EventQueue-0] DEBUG net.sf.hibernate.impl.SessionImpl - flushing session
2004-11-25 12:17:54,709 [AWT-EventQueue-0] DEBUG net.sf.hibernate.impl.SessionImpl - Flushing entities and processing referenced collections
2004-11-25 12:17:54,709 [AWT-EventQueue-0] DEBUG net.sf.hibernate.impl.SessionImpl - Processing unreferenced collections
2004-11-25 12:17:54,709 [AWT-EventQueue-0] DEBUG net.sf.hibernate.impl.SessionImpl - Scheduling collection removes/(re)creates/updates
2004-11-25 12:17:54,709 [AWT-EventQueue-0] DEBUG net.sf.hibernate.impl.SessionImpl - Flushed: 1 insertions, 0 updates, 0 deletions to 1 objects
2004-11-25 12:17:54,709 [AWT-EventQueue-0] DEBUG net.sf.hibernate.impl.SessionImpl - Flushed: 0 (re)creations, 0 updates, 0 removals to 0 collections
2004-11-25 12:17:54,719 [AWT-EventQueue-0] DEBUG net.sf.hibernate.impl.Printer - listing entities:
2004-11-25 12:17:54,739 [AWT-EventQueue-0] DEBUG net.sf.hibernate.impl.Printer - de.innosystec.hibernate.demo.middleware.CompactDisc{title=Queen II, purchaseDate=25 November 2004, artist=Queen, cost=9.99, id=557057}
2004-11-25 12:17:54,739 [AWT-EventQueue-0] DEBUG net.sf.hibernate.impl.SessionImpl - executing flush
2004-11-25 12:17:54,739 [AWT-EventQueue-0] DEBUG net.sf.hibernate.persister.EntityPersister - Inserting entity: [de.innosystec.hibernate.demo.middleware.CompactDisc#557057]
2004-11-25 12:17:54,739 [AWT-EventQueue-0] DEBUG net.sf.hibernate.impl.BatcherImpl - about to open: 0 open PreparedStatements, 0 open ResultSets
2004-11-25 12:17:54,739 [AWT-EventQueue-0] DEBUG net.sf.hibernate.connection.DriverManagerConnectionProvider - total checked-out connections: 0
2004-11-25 12:17:54,739 [AWT-EventQueue-0] DEBUG net.sf.hibernate.connection.DriverManagerConnectionProvider - using pooled JDBC connection, pool size: 0
2004-11-25 12:17:54,739 [AWT-EventQueue-0] DEBUG net.sf.hibernate.SQL - insert into compact_disc (title, artist, purchase_date, cost, id) values (?, ?, ?, ?, ?)
2004-11-25 12:17:54,739 [AWT-EventQueue-0] DEBUG net.sf.hibernate.impl.BatcherImpl - preparing statement
2004-11-25 12:17:54,739 [AWT-EventQueue-0] DEBUG net.sf.hibernate.persister.EntityPersister - Dehydrating entity: [de.innosystec.hibernate.demo.middleware.CompactDisc#557057]
2004-11-25 12:17:54,739 [AWT-EventQueue-0] DEBUG net.sf.hibernate.type.StringType - binding 'Queen II' to parameter: 1
2004-11-25 12:17:54,739 [AWT-EventQueue-0] DEBUG net.sf.hibernate.type.StringType - binding 'Queen' to parameter: 2
2004-11-25 12:17:54,739 [AWT-EventQueue-0] DEBUG net.sf.hibernate.type.DateType - binding '25 November 2004' to parameter: 3
2004-11-25 12:17:54,739 [AWT-EventQueue-0] DEBUG net.sf.hibernate.type.DoubleType - binding '9.99' to parameter: 4
2004-11-25 12:17:54,739 [AWT-EventQueue-0] DEBUG net.sf.hibernate.type.IntegerType - binding '557057' to parameter: 5
2004-11-25 12:17:54,739 [AWT-EventQueue-0] DEBUG net.sf.hibernate.impl.BatcherImpl - Adding to batch
2004-11-25 12:17:54,739 [AWT-EventQueue-0] DEBUG net.sf.hibernate.impl.BatcherImpl - Executing batch size: 1
2004-11-25 12:17:54,739 [AWT-EventQueue-0] DEBUG net.sf.hibernate.impl.BatcherImpl - success of batch update unknown: 0
2004-11-25 12:17:54,739 [AWT-EventQueue-0] DEBUG net.sf.hibernate.impl.BatcherImpl - done closing: 0 open PreparedStatements, 0 open ResultSets
2004-11-25 12:17:54,739 [AWT-EventQueue-0] DEBUG net.sf.hibernate.impl.BatcherImpl - closing statement
2004-11-25 12:17:54,739 [AWT-EventQueue-0] DEBUG net.sf.hibernate.impl.SessionImpl - post flush
2004-11-25 12:17:54,739 [AWT-EventQueue-0] DEBUG net.sf.hibernate.impl.SessionImpl - closing session
2004-11-25 12:17:54,739 [AWT-EventQueue-0] DEBUG net.sf.hibernate.impl.SessionImpl - disconnecting session
2004-11-25 12:17:54,739 [AWT-EventQueue-0] DEBUG net.sf.hibernate.connection.DriverManagerConnectionProvider - returning connection to pool, pool size: 1
2004-11-25 12:17:54,739 [AWT-EventQueue-0] DEBUG net.sf.hibernate.impl.SessionImpl - transaction completion

_________________
You'll never get a second chance to make a first impression!


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 25, 2004 7:36 am 
Expert
Expert

Joined: Tue Oct 05, 2004 9:45 am
Posts: 263
well ... where's your 'commit'?

gtx
curio


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 25, 2004 7:42 am 
Beginner
Beginner

Joined: Thu Nov 25, 2004 7:07 am
Posts: 43
Location: Germany
As I am quite new to Hibernate I thought that data is committed when calling save() on the Session object. Does it mean, if I want to use oracle I always have to use a Transaction object and commit this? I didn't find a commit on Session. I used Torque before and was used that data are committed automatically when not using an explicit Transaction.

Thanks for your help.

caterham

_________________
You'll never get a second chance to make a first impression!


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 25, 2004 7:54 am 
Expert
Expert

Joined: Tue Oct 05, 2004 9:45 am
Posts: 263
take a look at the reference-guide Chapter 9 ... there're information about how to change/store an object...

gtx
curio


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 25, 2004 9:20 am 
Expert
Expert

Joined: Sat Jun 12, 2004 4:49 pm
Posts: 915
Hello,
Oracle don't do commit default - You can call connection and set autocommit to true (or in hibernate setting) - this is correct for JDBC specification

regards


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 25, 2004 9:29 am 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
Quote:
this is correct for JDBC


is it correct for you? do you really want to work with this setting?

_________________
Anthony,
Get value thanks to your skills: http://www.redhat.com/certification


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 25, 2004 9:49 am 
Expert
Expert

Joined: Sat Jun 12, 2004 4:49 pm
Posts: 915
There is problems with distributed transaction when autocommit is on (chapter 12 from JDBC
specification), but and for every transaction with > 2 commands
I don't use it


regards


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 25, 2004 9:52 am 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
don't you think it's always better to know how transaction are working?

_________________
Anthony,
Get value thanks to your skills: http://www.redhat.com/certification


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 25, 2004 2:17 pm 
Expert
Expert

Joined: Sat Jun 12, 2004 4:49 pm
Posts: 915
I know
autocomit is off and transaction start and end when I request

regards


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 25, 2004 6:20 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
Transactions are necessary (they are present anyway) so a typical transaction should use the following idiom:
Code:
Session sess = factory.openSession();
Transaction tx;
try {
     tx = sess.beginTransaction();
     //do some work
     ...
     tx.commit();
}
catch (Exception e) {
     if (tx!=null) tx.rollback();
     throw e;
}
finally {
     sess.close();
}


This is documented on the Reference documentation, Wiki, in the Session JavaDoc, HIA Book. Use this idiom and you really, really will encounter less issues.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 07, 2004 4:41 pm 
Newbie

Joined: Wed Nov 17, 2004 3:56 pm
Posts: 5
I am having the same problem with data not being persisted on save. I'm using Hibernate with Spring via HibernateTemplate.

JDK 1.4.2_06, latest ojdbc14.jar from Oracle, dabatabase is Oracle 8.1.7.2, hibernate version 2.1.6, 9.8.2004, spring 1.1.2

applicationContext.xml
Code:
<bean id="ppsSessionFactory" class="org.springframework.orm.hibernate.LocalSessionFactoryBean">
...
   <property name="hibernateProperties">
      <props>
            <prop key="hibernate.dialect">net.sf.hibernate.dialect.OracleDialect</prop>
         <prop key="hibernate.show_sql">true</prop>
         <prop key="hibernate.cglib.use_reflection_optimizer">true</prop>
            <prop key="hibernate.connection.driver_class">oracle.jdbc.driver.OracleDriver</prop>
            <prop key="hibernate.connection.url">jdbc:oracle:thin:@dbhost:1522:bisd</prop>
            <prop key="hibernate.connection.username">foo</prop>
            <prop key="hibernate.connection.password">bar</prop>
            <prop key="hibernate.c3p0.min_size">5</prop>
            <prop key="hibernate.c3p0.max_size">20</prop>
            <prop key="hibernate.c3p0.timeout">1800</prop>
            <prop key="hibernate.c3p0.max_statements">50</prop>
      </props>
   </property>
</bean>

<bean id="myTransactionManager" class="org.springframework.orm.hibernate.HibernateTransactionManager">
   <property name="sessionFactory"><ref local="ppsSessionFactory"/></property>
</bean>



Application code:
Code:
getHibernateTemplate().update(facility);


Debug level Hibernate log excerpt:
Code:
DEBUG net.sf.hibernate.impl.SessionImpl - opened session
DEBUG net.sf.hibernate.impl.SessionImpl - updating [gov.ca.dfg.pps.domain.objects.Facility#128]
DEBUG net.sf.hibernate.impl.SessionImpl - flushing session
DEBUG net.sf.hibernate.impl.SessionImpl - Flushing entities and processing referenced collections
DEBUG net.sf.hibernate.impl.SessionImpl - Updating entity: [gov.ca.dfg.pps.domain.objects.Facility#128]
DEBUG net.sf.hibernate.impl.SessionImpl - Collection found: [gov.ca.dfg.pps.domain.objects.Facility.facilityContactMechanisms#128], was: [gov.ca.dfg.pps.domain.objects.Facility.facilityContactMechanisms#128]
DEBUG net.sf.hibernate.impl.SessionImpl - Collection found: [gov.ca.dfg.pps.domain.objects.Facility.facilities#128], was: [gov.ca.dfg.pps.domain.objects.Facility.facilities#128]
DEBUG net.sf.hibernate.impl.SessionImpl - Collection found: [gov.ca.dfg.pps.domain.objects.Facility.partyFacilities#128], was: [gov.ca.dfg.pps.domain.objects.Facility.partyFacilities#128]
DEBUG net.sf.hibernate.impl.SessionImpl - Processing unreferenced collections
DEBUG net.sf.hibernate.impl.SessionImpl - Scheduling collection removes/(re)creates/updates
DEBUG net.sf.hibernate.impl.SessionImpl - Flushed: 0 insertions, 1 updates, 0 deletions to 1 objects
DEBUG net.sf.hibernate.impl.SessionImpl - Flushed: 0 (re)creations, 0 updates, 0 removals to 3 collections
DEBUG net.sf.hibernate.impl.Printer - listing entities:
DEBUG net.sf.hibernate.impl.Printer - gov.ca.dfg.pps.domain.objects.Facility{facilityType=FacilityType#2, facilityName=Fish and Game Headquarters -TEST, facility=null, facilitySeq=128, creationDate=2002-03-22 11:06:01, partyFacilities=[PartyFacility#PartyFacilityPK{partySeq=81515, partyFacilitySeq=499, facFacilitySeq=128}, PartyFacility#PartyFacilityPK{partySeq=91779, partyFacilitySeq=446, facFacilitySeq=128}, PartyFacility#PartyFacilityPK{partySeq=81513, partyFacilitySeq=369, facFacilitySeq=128}, PartyFacility#PartyFacilityPK{partySeq=91779, partyFacilitySeq=448, facFacilitySeq=128}, PartyFacility#PartyFacilityPK{partySeq=81516, partyFacilitySeq=329, facFacilitySeq=128}, PartyFacility#PartyFacilityPK{partySeq=81517, partyFacilitySeq=281, facFacilitySeq=128}, PartyFacility#PartyFacilityPK{partySeq=81507, partyFacilitySeq=370, facFacilitySeq=128}, PartyFacility#PartyFacilityPK{partySeq=81512, partyFacilitySeq=365, facFacilitySeq=128}, PartyFacility#PartyFacilityPK{partySeq=81508, partyFacilitySeq=373, facFacilitySeq=128}, PartyFacility#PartyFacilityPK{partySeq=81516, partyFacilitySeq=328, facFacilitySeq=128}, PartyFacility#PartyFacilityPK{partySeq=81516, partyFacilitySeq=368, facFacilitySeq=128}, PartyFacility#PartyFacilityPK{partySeq=81518, partyFacilitySeq=366, facFacilitySeq=128}, PartyFacility#PartyFacilityPK{partySeq=81515, partyFacilitySeq=374, facFacilitySeq=128}, PartyFacility#PartyFacilityPK{partySeq=81517, partyFacilitySeq=128, facFacilitySeq=128}, PartyFacility#PartyFacilityPK{partySeq=81514, partyFacilitySeq=367, facFacilitySeq=128}], lastUpdatedByUserId=null, lastUpdatedDate=null, createdByUserId=BIS_WEB, squareFootage=null, description=null, facilities=uninitialized, facilityContactMechanisms=[FacilityContactMechanism#311, FacilityContactMechanism#309, FacilityContactMechanism#310]}
DEBUG net.sf.hibernate.impl.SessionImpl - executing flush
DEBUG net.sf.hibernate.persister.EntityPersister - Updating entity: [gov.ca.dfg.pps.domain.objects.Facility#128]
DEBUG net.sf.hibernate.impl.BatcherImpl - about to open: 0 open PreparedStatements, 0 open ResultSets
DEBUG net.sf.hibernate.SQL - update FACILITY set CREATED_BY_USER_ID=?, DESCRIPTION=?, LAST_UPDATED_BY_USER_ID=?, LAST_UPDATED_DATE=?, FACILITY_NAME=?, SQUARE_FOOTAGE=?, CREATION_DATE=?, FAC_FACILITY_SEQ=?, FACILITY_TYPE_SEQ=? where FACILITY_SEQ=?
Hibernate: update FACILITY set CREATED_BY_USER_ID=?, DESCRIPTION=?, LAST_UPDATED_BY_USER_ID=?, LAST_UPDATED_DATE=?, FACILITY_NAME=?, SQUARE_FOOTAGE=?, CREATION_DATE=?, FAC_FACILITY_SEQ=?, FACILITY_TYPE_SEQ=? where FACILITY_SEQ=?
DEBUG net.sf.hibernate.impl.BatcherImpl - preparing statement
DEBUG net.sf.hibernate.persister.EntityPersister - Dehydrating entity: [gov.ca.dfg.pps.domain.objects.Facility#128]
DEBUG net.sf.hibernate.type.StringType - binding 'BIS_WEB' to parameter: 1
DEBUG net.sf.hibernate.type.StringType - binding null to parameter: 2
DEBUG net.sf.hibernate.type.StringType - binding null to parameter: 3
DEBUG net.sf.hibernate.type.TimestampType - binding null to parameter: 4
DEBUG net.sf.hibernate.type.StringType - binding 'Headquarters' to parameter: 5
DEBUG net.sf.hibernate.type.BigDecimalType - binding null to parameter: 6
DEBUG net.sf.hibernate.type.TimestampType - binding '2002-03-22 11:06:01' to parameter: 7
DEBUG net.sf.hibernate.type.BigDecimalType - binding null to parameter: 8
DEBUG net.sf.hibernate.engine.Cascades - id unsaved-value strategy NULL
DEBUG net.sf.hibernate.type.BigDecimalType - binding '2' to parameter: 9
DEBUG net.sf.hibernate.type.BigDecimalType - binding '128' to parameter: 10
DEBUG net.sf.hibernate.impl.BatcherImpl - Adding to batch
DEBUG net.sf.hibernate.impl.BatcherImpl - Executing batch size: 1
DEBUG net.sf.hibernate.impl.BatcherImpl - success of batch update unknown: 0
DEBUG net.sf.hibernate.impl.BatcherImpl - done closing: 0 open PreparedStatements, 0 open ResultSets
DEBUG net.sf.hibernate.impl.BatcherImpl - closing statement
DEBUG net.sf.hibernate.impl.SessionImpl - post flush
DEBUG net.sf.hibernate.impl.SessionImpl - closing session
DEBUG net.sf.hibernate.impl.SessionImpl - disconnecting session
DEBUG net.sf.hibernate.impl.SessionImpl - transaction completion


Before this, I was using an older Oracle JDBC driver that was giving errors as described here http://forum.hibernate.org/viewtopic.php?t=934050. I tried setting the hibernate.c3p0.max_statements=0 but that did not help. I also tried using the JDBC driver from Oracle compiled with -g which hung completely when exectuting the batch update.

Here http://forum.hibernate.org/viewtopic.php?t=932154 is another instance of the same issue with no resolution there either.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 07, 2004 4:54 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Simplify your problem first, do the same without Spring. We can't help you if you wrap our software into some other framework.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 08, 2004 4:20 am 
Senior
Senior

Joined: Sat Jul 17, 2004 5:16 pm
Posts: 143
Both of those have resolutions.

One is change the oracle driver. Which one do you have?

The other seemed like a user error (dont know, never got more info from the user).

Post the generated SQL (not from the debug log). See whats going back and forth. Is there a commit?

Chris


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 08, 2004 5:24 pm 
Newbie

Joined: Wed Nov 17, 2004 3:56 pm
Posts: 5
Silly user error: I hadn't setup my transactional properties correctly in Spring. Everything works now. =)


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