-->
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.  [ 5 posts ] 
Author Message
 Post subject: Hibernate Insertion problem
PostPosted: Sun Jun 17, 2007 12:07 am 
Newbie

Joined: Sat Jun 16, 2007 11:13 pm
Posts: 5
Hi
I am new to Hibernate.
Any feedback is higly appreciated .

From the log it appears insertion happened .
But on querying the database , I see no rows have been inserted.
Any idea ??

Hibernate version:2.1.6
Name and version of the database you are using:
Oracle 9i


Mapping documents:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-2.0.dtd">
<hibernate-configuration>
<session-factory>

<property name="hibernate.connection.url">jdbc:oracle:thin:@localhost:1521:SATORA</property>
<property name="hibernate.connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
<property name="hibernate.connection.username">scott</property>
<property name="hibernate.connection.password">tiger</property>
<property name="dialect">net.sf.hibernate.dialect.OracleDialect</property>
<property name="hibernate.show_sql">true</property>

<mapping resource="src/config/CD.hbm.xml"/>

</session-factory>
</hibernate-configuration>



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

<hibernate-mapping>
<class name="src.java.dao.CD" table="CD">
<id name="id" type="integer" unsaved-value="null" >
<column name="id" sql-type="int" not-null="true"/>
<generator class="sequence">
<param name="sequence">
seq_cd
</param>
</generator>
</id>
<property name="title" type="string" />
<property name="artist" type="string" />
</class>
</hibernate-mapping>



Code between sessionFactory.openSession() and session.close():

SessionFactory factory = new Configuration().configure().buildSessionFactory();
Session session = factory.openSession();
CD cd = new CD("Bajan","Singers");
session.save(cd);
session.flush();
session.close();



Debug level Hibernate log excerpt:

Jun 16, 2007 11:00:58 PM net.sf.hibernate.cfg.Environment <clinit>
INFO: Hibernate 2.1.6
Jun 16, 2007 11:00:58 PM net.sf.hibernate.cfg.Environment <clinit>
INFO: hibernate.properties not found
Jun 16, 2007 11:00:58 PM net.sf.hibernate.cfg.Environment <clinit>
INFO: using CGLIB reflection optimizer
Jun 16, 2007 11:00:58 PM net.sf.hibernate.cfg.Configuration configure
INFO: configuring from resource: /hibernate.cfg.xml
Jun 16, 2007 11:00:58 PM net.sf.hibernate.cfg.Configuration getConfigurationInputStream
INFO: Configuration resource: /hibernate.cfg.xml
Jun 16, 2007 11:00:58 PM net.sf.hibernate.cfg.Configuration addResource
INFO: Mapping resource: src/config/CD.hbm.xml
Jun 16, 2007 11:00:58 PM net.sf.hibernate.cfg.Binder bindRootClass
INFO: Mapping class: src.java.dao.CD -> CD
Jun 16, 2007 11:00:58 PM net.sf.hibernate.cfg.Configuration doConfigure
INFO: Configured SessionFactory: null
Jun 16, 2007 11:00:58 PM net.sf.hibernate.cfg.Configuration secondPassCompile
INFO: processing one-to-many association mappings
Jun 16, 2007 11:00:58 PM net.sf.hibernate.cfg.Configuration secondPassCompile
INFO: processing one-to-one association property references
Jun 16, 2007 11:00:58 PM net.sf.hibernate.cfg.Configuration secondPassCompile
INFO: processing foreign key constraints
Jun 16, 2007 11:00:58 PM net.sf.hibernate.dialect.Dialect <init>
INFO: Using dialect: net.sf.hibernate.dialect.OracleDialect
Jun 16, 2007 11:00:58 PM net.sf.hibernate.cfg.SettingsFactory buildSettings
INFO: Use outer join fetching: true
Jun 16, 2007 11:00:58 PM net.sf.hibernate.connection.DriverManagerConnectionProvider configure
INFO: Using Hibernate built-in connection pool (not for production use!)
Jun 16, 2007 11:00:58 PM net.sf.hibernate.connection.DriverManagerConnectionProvider configure
INFO: Hibernate connection pool size: 20
Jun 16, 2007 11:00:59 PM net.sf.hibernate.connection.DriverManagerConnectionProvider configure
INFO: using driver: oracle.jdbc.driver.OracleDriver at URL: jdbc:oracle:thin:@localhost:1521:SATORA
Jun 16, 2007 11:00:59 PM net.sf.hibernate.connection.DriverManagerConnectionProvider configure
INFO: connection properties: {user=scott, password=tiger}
Jun 16, 2007 11:00:59 PM net.sf.hibernate.transaction.TransactionManagerLookupFactory getTransactionManagerLookup
INFO: No TransactionManagerLookup configured (in JTA environment, use of process level read-write cache is not recommended)
Jun 16, 2007 11:00:59 PM net.sf.hibernate.cfg.SettingsFactory buildSettings
INFO: Use scrollable result sets: true
Jun 16, 2007 11:00:59 PM net.sf.hibernate.cfg.SettingsFactory buildSettings
INFO: Use JDBC3 getGeneratedKeys(): false
Jun 16, 2007 11:00:59 PM net.sf.hibernate.cfg.SettingsFactory buildSettings
INFO: Optimize cache for minimal puts: false
Jun 16, 2007 11:00:59 PM net.sf.hibernate.cfg.SettingsFactory buildSettings
INFO: echoing all SQL to stdout
Jun 16, 2007 11:00:59 PM net.sf.hibernate.cfg.SettingsFactory buildSettings
INFO: Query language substitutions: {}
Hibernate: select
seq_cd
.nextval from dual
Jun 16, 2007 11:00:59 PM net.sf.hibernate.cfg.SettingsFactory buildSettings
INFO: cache provider: net.sf.hibernate.cache.EhCacheProvider
Jun 16, 2007 11:00:59 PM net.sf.hibernate.cfg.Configuration configureCaches
INFO: instantiating and configuring caches
Jun 16, 2007 11:00:59 PM net.sf.hibernate.impl.SessionFactoryImpl <init>
INFO: building session factory
Jun 16, 2007 11:01:00 PM net.sf.hibernate.impl.SessionFactoryObjectFactory addInstance
INFO: Not binding factory to JNDI, no JNDI name configured
Hibernate: insert into CD (title, artist, id) values (?, ?, ?)



Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 18, 2007 12:44 am 
Expert
Expert

Joined: Tue Jan 30, 2007 12:45 am
Posts: 283
Location: India
Hi sathyan.rajan,

Your transaction might be problem. Check after session.flush().

Try this way

Session session = factory.openSession();

Transaction tx=session.beginTransaction().
CD cd = new CD("Bajan","Singers");
session.save(cd);
session.flush();
session.close();
tx.close();

I am not using eclipse .You could find out correct syntax for transaction in eclipse

_________________
Dharmendra Pandey


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 18, 2007 4:56 am 
Regular
Regular

Joined: Wed May 05, 2004 8:01 am
Posts: 53
The previous snippet is incorrect. You should commit your transaction BEFORE closing session. Using session.flush() is not mandatory. So the shortest snippet that works is:

Session session = sessionFactory.openSession();
Transaction tx = session.beginTransaction();
CD cd = new CD("Bajan","Singers");
session.save(cd);
tx.commit();
session.close();

Of course you need to handle exceptions properly.

Please rate if that helped.


Top
 Profile  
 
 Post subject: Problem solved
PostPosted: Mon Jun 18, 2007 7:46 pm 
Newbie

Joined: Sat Jun 16, 2007 11:13 pm
Posts: 5
Thanks Ouzo commiting the transaction worked.
I have also rated .


Top
 Profile  
 
 Post subject: Problem Solved
PostPosted: Mon Jun 18, 2007 7:48 pm 
Newbie

Joined: Sat Jun 16, 2007 11:13 pm
Posts: 5
Hi Dharmendra.pandey ,
Closing the transaction alone didnt work.
Thanks anyway for your reply.


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