-->
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.  [ 6 posts ] 
Author Message
 Post subject: How do I configure the HiLo Generator as a stateless EJB
PostPosted: Fri Jul 23, 2004 10:20 am 
Newbie

Joined: Thu Jul 22, 2004 4:32 pm
Posts: 6
Location: Sacramento, CA USA
I'm working with a J2EE application that is using Hibernate 2.1.1 for its persistence layer.

This application is designed to work against any one of a set of database types, including Oracle, MS SQL Server and Pointbase (among others).

The Persistence layer is configured to use the native generator type. The application will run when using Oracle or MS SQL Server, but not when using PointBase.

I assume this is because when using Pointbase, Hibernate wants to use the HiLo generator, which cannot be used from within a CMT.

I've read the FAQ several times, and found the document titled "Session Bean Hi/Lo Generator", but can't get it to work.

First, the code won't compile, as it can't find HiLoGeneratorUtil, IdentifierGeneratorException or SessionImplementor. Does this example only work with a specific version of Hibernate? How do I make it work with the 2.1.1 version?

Next, can someone please explain how I configure Hibernate to use my class as the HiLo Generator? I've seen snippets of XML, but no indication where this XML should be placed.

Thanks for any help,


Top
 Profile  
 
 Post subject: Re: How do I configure the HiLo Generator as a stateless EJB
PostPosted: Fri Jul 23, 2004 10:41 am 
Newbie

Joined: Thu Jul 22, 2004 4:32 pm
Posts: 6
Location: Sacramento, CA USA
meh wrote:
I'm working with a J2EE application that is using Hibernate 2.1.1 for its persistence layer.

This application is designed to work against any one of a set of database types, including Oracle, MS SQL Server and Pointbase (among others).

The Persistence layer is configured to use the native generator type. The application will run when using Oracle or MS SQL Server, but not when using PointBase.

I assume this is because when using Pointbase, Hibernate wants to use the HiLo generator, which cannot be used from within a CMT.

I've read the FAQ several times, and found the document titled "Session Bean Hi/Lo Generator", but can't get it to work.

First, the code won't compile, as it can't find HiLoGeneratorUtil, IdentifierGeneratorException or SessionImplementor. Does this example only work with a specific version of Hibernate? How do I make it work with the 2.1.1 version?

Next, can someone please explain how I configure Hibernate to use my class as the HiLo Generator? I've seen snippets of XML, but no indication where this XML should be placed.

Thanks for any help,


I'm not sure why I couldn't find these before, but I've resolved the import problems, so my code is now compiling.

However, I still do not understand how to configure Hibernate to use my class as the HiLo generator.

Thanks,


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 23, 2004 1:58 pm 
Beginner
Beginner

Joined: Thu Jun 24, 2004 1:04 pm
Posts: 35
Location: Minnesota - USA
Try this:
http://www.hibernate.org/hib_docs/refer ... -generator

--gus


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 23, 2004 2:21 pm 
Newbie

Joined: Thu Jul 22, 2004 4:32 pm
Posts: 6
Location: Sacramento, CA USA
Thanks, I saw that. However, I don't know where that XML snippet needs to go.

The code I'm working with specifies the generator strategy in a base class used for all their persistence classes, named Persistence.java. In that class there is the following Hibernate comment:

Code:
    /**
     * @hibernate.id generator-class="native"
     */


If I change this to my Hi/Lo Generator class, then it will be used by the application regardless of the database chosen when the application is deployed.

Therefore, I think I need to continue to specify "native", but somehow tell Hibernate to use my Hi/Lo Generator class when it decided that a hilo strategy is to be used.

I see, in IdentifierGeneratorFactory.java, that when the "hilo" strategy is to be used, it will use TableHiLoGenerator.class. There doesn't appear to be any way to change the class assigned to this table for the "hilo" strategy.

Thanks for your help,


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 23, 2004 2:38 pm 
Beginner
Beginner

Joined: Thu Jun 24, 2004 1:04 pm
Posts: 35
Location: Minnesota - USA
That mapping is in the *.hml.xml file, in the <id> section.

Looks to me you can put any class you want into there, say: com.mycompany.MyGenerator

No clue on the xdoclet stuff (if that's what that is), try:
Code:
   /**
     * @hibernate.id generator-class="com.mycompany.MyGenerator"
     */


You may need to apply this on a per class basis to override the one you're getting from your base class. Can you do that with xdoclet?

I agree on your assessment of the IdentifierGeneratorFactory limitation. No way to change what 'hilo' is associated with, unless you want to patch Hibernate.

Idea based on how the IdentifierGeneratorFactory works... Perhaps you could implement a generator that implements the Configurable interface, and have set it's behaviour when configured to do the same logic as 'native' does? Just delegate to the standard implementions for 'identify' and 'sequences' and do your thing for 'hilo'.

--gus


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 23, 2004 2:53 pm 
Newbie

Joined: Thu Jul 22, 2004 4:32 pm
Posts: 6
Location: Sacramento, CA USA
In the case of this application, all the xml files (except for the hibernate.cfg.xml) get generated (I assume by the XDoclet package).

I was able to change the generator tag from "native" to my generator class name, and it appears to want to use it, but I get errors from that (see my separate thread on that issue: "Session Bean Hi/Lo Generator cannot configure TableHiLoGenerator").

You have a good idea with using a Configurable generator. I'm not quite sure how I would do that, but I guess I'll cross that bridge when I come to it.

Thanks very much for your help on this.


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