-->
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: Custom ID generator specified in orm.xml
PostPosted: Sun May 18, 2008 5:35 pm 
Newbie

Joined: Tue Jan 18, 2005 11:13 pm
Posts: 19
Using annotations, it's possible to use a custom ID generator:

@Id @GeneratedValue(generator="MyIDGenerator")
@GenericGenerator(name="MyIDGenerator", strategy = "com.foo.MyIDGenerator")
public String getId() {
}


Is it possible to do the same through configuration in orm.xml? I'd like to use JPA but keep the meta-data seperate from the code.

If this isn't possible, is it possible to use a combination of orm.xml and .hbm.xml files?

Thanks.

Scott


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 19, 2008 8:51 am 
Hibernate Team
Hibernate Team

Joined: Thu Apr 05, 2007 5:52 am
Posts: 1689
Location: Sweden
Hi Scott,

I don't think that orm.xml will work. GenericGenerator is a Hibernate extension with no equivalent in JPA annotations or orm.xml.

You should be able to add a .hbm.xml file adding something like this to the mapping file for your class:

Code:
<id name="id" type="long" column="id">
        <generator class="com.foo.MyIDGenerator">
                <!-- potential parameters -->
                <param name="foo">bar</param>
        </generator>
</id>


I haven't really tried this and even if it works I wouldn't recommend this approach since it is spreading configuration information all over the place. You want to use annotation, maybe orm.xml and hbm.xml mapping files. For a developer it will become very hard to understand the configuration as a whole.

Do you have a specific reason why you want to extract parts of the configuration data?

--Hardy


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.