-->
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.  [ 3 posts ] 
Author Message
 Post subject: Error while storing object into database
PostPosted: Fri May 26, 2006 9:06 am 
Newbie

Joined: Fri May 26, 2006 8:56 am
Posts: 2
Hi, I new to hibernate and trying to store some values into a simple table.
I am getting error saying that javax/transaction/Synchronization
while using below code.
Goodthing is the table 'CONTACT' is created in the database. But no rows are inserted.

Can anyone help me please.....

Thanks,
Sidhu.

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

<hibernate-mapping>
<class name="Contact" table="CONTACT">
<id name="id" type="long" column="ID" >
<generator class="assigned"/>
</id>

<property name="firstName">
<column name="FIRSTNAME" />
</property>
<property name="lastName">
<column name="LASTNAME"/>
</property>
<property name="email">
<column name="EMAIL"/>
</property>
</class>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close():
SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();
session =sessionFactory.openSession();
Transaction tx;
tx = session.beginTransaction();

//Create new instance of Contact and set values in it by reading them from form object
Contact contact = new Contact();
contact.setId(3);
contact.setFirstName("firstname");
contact.setLastName("lastname");
contact.setEmail("firstlast@hiber.com");
session.save(contact);
session.flush();
tx.commit();
session.close();
Full stack trace of any exception that occurs:
javax/transaction/Synchronization

Name and version of the database you are using:
oracle 10g
The generated SQL (show_sql=true):

Debug level Hibernate log excerpt:


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 26, 2006 10:56 am 
Regular
Regular

Joined: Thu Sep 22, 2005 1:53 pm
Posts: 88
Location: Rio de Janeiro
Seems to me you do everything right but if you use a transaction than there is no need for the session.flush()

You could try to use in you configuration file :

Code:
<property name="hibernate.connection.autocommit">true</property>


take out the transaction en use session.flush();

But to me it seems tho code should work me you can debug your code and stop after the flush do a slect in the table (dirty read if you use a transaction ) and check in the record is inserted....

Good Luck

_________________
DonĀ“t forget to rate!


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 26, 2006 11:01 am 
Newbie

Joined: Fri May 26, 2006 8:56 am
Posts: 2
I got it worked , I have to include few jar files into my lib directory.

Thanks for your help.


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