-->
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: Can I set the generator class value in code?
PostPosted: Wed Mar 09, 2005 5:14 pm 
Beginner
Beginner

Joined: Tue Mar 08, 2005 5:32 pm
Posts: 20
Location: USA
Hi all.
Is there a way to set the generator class value in the code rather than in the *.hbm.xml file?

Currently I am doing something like :
<id name="id" type="integer" column="CAT_ID">
<generator class="identity">
</id>

Is there a way do something like:
1. <id name="id" type="integer" column="CAT_ID"/>
2. Set the generator class in Java code

Hibernate version: 3.0 rc1

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 11, 2005 11:01 am 
Beginner
Beginner

Joined: Tue Mar 08, 2005 5:32 pm
Posts: 20
Location: USA
I did something like this:

Code:
Configuration cfg = new Configuration();
Iterator mappings = cfg.getClassMappings();

while (mappings.hasNext) {
    RootClass rootClass = (RootClass)mappings.next();

    SimpleValue simpleValue = new SimpleValue(rootClass.getTable);
    System.out.println(simpleValue.getIdentifierGenerationStrategy());
}



I figured I could use this to set the generator class for id:

Code:
simpleValue.setIdentifierGenerationStrategy()


Output:
assigned

The problem is i have my hbm.xml set like this:
Code:
<id name="id" type="integer" column="CAT_ID" unsaved-value="0">
    <generator class="identity"/>
</id>


So, I was expecting the output as 'identity' and not 'assigned'.

Can anyone tell where I am going wrong?

I am using Hibernate 3.0rc1 with DB2 8.1.3 UDB

Thanks.


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.