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