-->
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: Record in table getting updated instead of insertion
PostPosted: Wed May 18, 2011 5:10 am 
Newbie

Joined: Wed May 18, 2011 3:16 am
Posts: 2
Hi,

I am using MySQL with Hibernate, a small application, inserting record into table Person, which was created as :

CREATE TABLE `person` (
`PERSON_ID` bigint(20) NOT NULL AUTO_INCREMENT,
`PERSON_NAME` varchar(100) NOT NULL,
PRIMARY KEY (`PERSON_ID`)
) AUTO_INCREMENT=3

Person.hbm.xml::

<hibernate-mapping>
<class name="com.vaannila.student.Person" table="test.person">
<meta attribute="class-description">This class contains student details.</meta>
<id name="personId" type="long" column="PERSON_ID">
<generator class="native" />
</id>
<property name="personName" type="string" not-null="true" length="100" column="PERSON_NAME" />
</class>
</hibernate-mapping>

Hibernate.cfg.xml::

<hibernate-configuration>
<session-factory>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost/test</property>
<property name="hibernate.connection.username">root</property>
<property name="connection.password">root</property>
<property name="connection.pool_size">1</property>
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="show_sql">true</property>
<property name="hbm2ddl.auto">create</property>
<mapping resource="com/company/project/Person.hbm.xml"/>
</session-factory>
</hibernate-configuration>

To my surprise, every time I run app (so i am inserting a record) - record is getting updated with same id:

mysql> select * from person;
+-----------+-------------+
| PERSON_ID | PERSON_NAME |
+-----------+-------------+
| 1 | BOMBAYite |
+-----------+-------------+
1 row in set (0.00 sec)

where my old record is going . pls help.

Edit - I even tried by inserting more records by command line - they are gettign inserted & total records shoes 4.
But the moment I run my Hibernate app - all records are gone - just the latest (being inserted) is shown.


Top
 Profile  
 
 Post subject: Re: Record in table getting updated instead of insertion
PostPosted: Wed May 18, 2011 10:07 am 
Beginner
Beginner

Joined: Sat Aug 01, 2009 5:28 am
Posts: 42
look at this.........................
<property name="hbm2ddl.auto">create</property>

_________________
Warm Regards,
Tarun Walia


Top
 Profile  
 
 Post subject: Re: Record in table getting updated instead of insertion
PostPosted: Thu May 19, 2011 7:30 am 
Newbie

Joined: Wed May 18, 2011 3:16 am
Posts: 2
Thanks Tarun.
It seems a basic stuff - but it's ok given I am just few days old in Hibernate' territory.


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.