-->
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: Hibernate generator with MySQL and auto_increment columns
PostPosted: Tue Aug 08, 2006 11:41 pm 
Newbie

Joined: Sun Aug 06, 2006 12:55 am
Posts: 11
Hi all

When I use the code generator to create POJOs and mapping files from my schema, the generator class selected for auto_increment columns is always specified as 'assigned' when I think it should be 'identity'

eg my table might be
Code:
CREATE TABLE `team_manager` (
  `team_manager_id` int(10) unsigned NOT NULL auto_increment,



a snippet from the mapping file created is
Code:
<id name="teamManagerId" type="int">
            <column name="team_manager_id" />
            <generator class="assigned" />
         </id>


With it specified as assigned, the key field in my POJO is not being populated (understandably) when a new TeamManager object is persisted. When I change it to identity all is OK.

Is there a way to force the code generator to always specify <generator class="identity" /> instead of <generator class="assigned" /> when reverse engineering auto_increment columns?

Is there any other hibernate or MySQL setting I can modify?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 09, 2006 9:06 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
we don't detect that automaticlly (patches welcome).


you can control it explicitly via reveng.xml (see the docs)

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 09, 2006 5:05 pm 
Newbie

Joined: Sun Aug 06, 2006 12:55 am
Posts: 11
Thanks Max

About 50 of my 60 tables have auto_increment primary key fields.

Is there a way to define a rule in revenge.xml where I can say

"all primary key fields except for A, B and C should have class="identity"" or something to that effect?

Basically I'm trying to come up with a scenario where I can continue running the code generator so it picks up new/modified/deleted columns in my tables, but recognises that they primary key for 90% of my tables should be defined as identity.


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.