-->
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: Problem with primary key generation
PostPosted: Sun Dec 28, 2008 1:18 pm 
Newbie

Joined: Sun Dec 28, 2008 1:06 pm
Posts: 2
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version: 3.3.1

Mapping documents:



Below is the code I use to create a row in DB .

hibernateSessionFactory = new Configuration().configure().buildSessionFactory();
Session session = factory.getCurrentSession();
try {
session.beginTransaction();
session.save(event);
System.out.println("save done");
session.getTransaction().commit();
System.out.println("commit done");
} catch (Exception e) {
e.printStackTrace();
session.getTransaction().rollback();
}


Note : I also used session.close() and factory.close() . But It did not help
No Exception

MySql 5.1

The generated SQL :: Hibernate: insert into EVENTS (EVENT_DATE, EVENT_TITLE) values (?, ?)


Problems with Session and transaction handling? - NO

After first record insertion the the primary key is 1. and when i use the same code and insert record again the primary key is still 1 there by there is no new row inserted.

I tried using select,assign,increment,native in generator class. But Still having the above..

The .hbm.xml file is as shown below

<?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="com.Event" table="EVENTS">
<id name="id" column="EVENT_ID">
<generator class="native"/>
</id>
<property name="eventdate" type="timestamp" column="EVENT_DATE"/>
<property name="title" type="string" column="EVENT_TITLE"/>
</class>

</hibernate-mapping>

Read this: http://hibernate.org/42.html


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 29, 2008 12:15 am 
Beginner
Beginner

Joined: Wed Nov 26, 2008 1:02 am
Posts: 22
hi,

just check in your hibernate.cfg.xml for<hbm2ddl.auto>,i think it may be create,and change it to update.

regards


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 30, 2008 10:28 am 
Newbie

Joined: Sun Dec 28, 2008 1:06 pm
Posts: 2
Thanks it worked


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.