-->
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.  [ 2 posts ] 
Author Message
 Post subject: hibernate3&mysql: Object-id not filled after save
PostPosted: Fri Feb 04, 2005 11:46 am 
Regular
Regular

Joined: Thu Feb 19, 2004 4:48 am
Posts: 62
I'm using mysql and hibernate3 and can't seem to get my primary keys filled. id is the primary key of unit, and it's set to auto_increment in mysql:

Unit unit = new Unit();
unit.setName("noId");

Session session = HibernateUtil.getSession();

Transaction tx = session.beginTransaction();
session.save(unit);
tx.commit();
session.close();

System.out.println("Generated key: " + unit.getId());

assertTrue("generated key not returned", unit.getId()>0);

prints 0 and throws and AssertionFailedError.

Did I miss a switch here?? Is

I already set

hibernate.jdbc.use_get_generated_keys true

with no effect.

I'm using
- mysql-connector-java-3.0.9-stable
- hibernate 3.0 beta 3
- mysql 4.0.15-nt
- jdk1.5.0


any help is highly appreciated, as this really drives me mad...
cheers
stf


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 04, 2005 1:05 pm 
Regular
Regular

Joined: Thu Feb 19, 2004 4:48 am
Posts: 62
Ok, solved this one with the help from michael:

using @Id without giving a generator-type falls back to the default, which is GeneratorType.NONE

so, adding a
@Id (generate=GeneratorType.AUTO)

tells hibernate to use the auto_increment *and* that there is actually something that can be retrieved from the DB... - after the flush, the ids are filled now.

Case Solved, many thx michael!
stf


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