-->
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: Hibernate3 + Mysql5
PostPosted: Wed Jul 19, 2006 2:19 am 
Newbie

Joined: Wed Mar 29, 2006 5:29 am
Posts: 3
Hi i m using Mysql5 .when i m trying run a simple java application with hibernate(Just inserting one record)..its creating the tables( <property name="hibernate.hbm2ddl.auto">update</property> ) but not inserting the records.But the same time when i use Mysql4.0.26 its creating the table and inserting the records also!!! Plz help me out in this...


Thnxin advance


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 19, 2006 2:53 am 
Regular
Regular

Joined: Sat Nov 06, 2004 5:20 pm
Posts: 54
Location: Collierville, TN
Take a look at your error message. It probably has something to do with "condition".

From Christian:
Quote:
"condition" is a new keyword in MySQL 5. Put this in your mapping file and quote it:

<property name="condition" column="`CONDITION`"/>


Hope this helps.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 19, 2006 2:54 am 
Regular
Regular

Joined: Mon May 08, 2006 6:00 am
Posts: 53
Location: India
<property name="hbm2ddl.auto">create</property>

Not sure whether you need such (above) property better you comment it and then try.

I assume your tables are already created and you just need to do the insertion.

Sudhir


Top
 Profile  
 
 Post subject: Re:Hibernate3 + Mysql5
PostPosted: Wed Jul 19, 2006 3:09 am 
Newbie

Joined: Wed Mar 29, 2006 5:29 am
Posts: 3
I m not getting any error messages. when i give <property name="hibernate.hbm2ddl.auto">update</property> then table s getting created.bit no inserting.Strnge thing is its working fine with Mysql4.0.26

This is my code:

Example.java
SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();
session =sessionFactory.openSession();
//Create new instance of Contact and set values in it by reading them from form object
System.out.println("Inserting Record");
Contact contact = new Contact();
contact.setId(123);
contact.setFirstName("shah");
contact.setLastName("shah");
contact.setEmail("deepak_38@yahoo.com");
session.save(contact);
hibernate.cfg.xml
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">

<hibernate-configuration>
<session-factory>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.url">jdbc:mysql:///hibernate</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.connection.password"></property>
<property name="show_sql">true</property>
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="hibernate.hbm2ddl.auto">update</property>
<!-- Mapping files -->
<mapping resource="contact.hbm.xml"/>

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

contact.hbm.xml

<?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>


Top
 Profile  
 
 Post subject: Re:Hibernate3 + Mysql5
PostPosted: Wed Jul 19, 2006 4:16 am 
Newbie

Joined: Wed Jul 19, 2006 4:13 am
Posts: 6
jophis wrote:

This is my code:

Example.java
SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();
session =sessionFactory.openSession();
//Create new instance of Contact and set values in it by reading them from form object
System.out.println("Inserting Record");
Contact contact = new Contact();
contact.setId(123);
contact.setFirstName("shah");
contact.setLastName("shah");
contact.setEmail("deepak_38@yahoo.com");
session.save(contact);


You are missing the session.getTransaction().commit() here.

It was probably working under MySQL 4.0 because you were using MyISAM tables, which do not support transactions.


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.