-->
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: How to Programmatically change generator from seq->assign
PostPosted: Fri Feb 03, 2006 4:27 pm 
Newbie

Joined: Fri Feb 03, 2006 4:18 pm
Posts: 2
Hi all,

I was wondering how to programmatically change the sequence generator of a class in Hibernate. For instance, in the below excerpt, I normally generate an ID from a sequence in the DB. Someone has requested that I take input of the ID instead of using the sequence. So, in his case, he gives me the sequence number, but in most cases I want to use the sequence generator in the hbm.xml.

Can i basically programmatically change it from "sequence" to "assigned" when he sends me the number instead?

Thanks!
Olav


Hibernate version: 2

Mapping documents:

<class name="Suite" table="SUITE">
<id name="buildId" column="BUILD_ID" type="java.lang.Long">
<generator class="sequence">
<param name="sequence">BUILD_ID_SEQ</param>
</generator>
</id>
...
</class>


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 03, 2006 11:17 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
nope


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 09, 2006 12:04 pm 
Newbie

Joined: Fri Feb 03, 2006 4:18 pm
Posts: 2
After thinking through the problem, I came up with a solution. Thanks for the very terse reply! :)

The solution, in case anyone else has this issue. It's a bit hacky, but will do it.

Generally the configuration is through hibernate.cfg.xml, as everyone knows, so you'd have a line such as:

<mapping resource="com/myapp/Suite.hbm.xml" />

In the hibernateSessionFactory, generally you do something like:

cfg.configure(CONFIG_FILE_LOCATION); where CONFIG_FILE_LOCATION specifies where the hibernate.hbm.xml file is. Well, programmatically, you could take a command line option specifying which config to use of course. So, you could have 2 of the hibernate.cfg.xml's, one has a mapping resource like:

<mapping resource="com/myapp/Suite_assigned_id.hbm.xml" />

and the other has

<mapping resource="com/myapp/Suite_generated_id.hbm.xml" />

with the same file contents in both, except that one would have a generated sequence ID and the other an assigned ID. Problem solved.

Figured I'd post for anyone else coming up against this issue.


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.