-->
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 3.3 and J2EE resource-ref not working in WebSphere
PostPosted: Mon Aug 16, 2010 2:47 pm 
Newbie

Joined: Mon Aug 16, 2010 11:57 am
Posts: 2
We have been trying unsuccessfully to map abstract DataSource names in our hibernate.cfg.xml file to 'real' JNDI resources as configured on a WebSphere 7 server. We have read several articles and tutorials on the subject, and the only examples we can find show that the hibernate.connection.datasource property must exactly match the JNDI name of the resource as configured on the server.

The problem is that this reduces the portability of our configuration files. Take the example of a test, stage, and production environment. In the test environment, the JNDI name may be jdbc/TestDB. Likewise, in the stage environment, the JNDI name may be jdbc/StageDB. This requires us to maintain more than one hibernate.cfg.xml file for each of our applications, the only difference between them being the hibernate.connection.datasource value. Worse, if the configuration file is embedded in a JAR delivered by a developer, then we have to maintain separate JAR files for each environment. This really complicates the process of performing automated builds and code promotions.

Java EE supports the concept of resource-ref entries in an application's web.xml. These allow the application to request a 'generic' name during naming lookup, which gets mapped to a 'real' name within the application container at deploy-time. Thus, the hibernate configuration should be able to just specify 'MyConnection' as the hibernate.connection.datasource value, which the application server would know is mapped to 'jdbc/TestDB' in the test environment, or 'jdbc/StageDB' in the staging environment. This mechnanism works perfectly in our non-Hibernate applications.

Unfortunately this does not seem to be working within our Hibernate applications. If the hibernate.connection.datasource value does not exactly match the JNDI name of a resource on the target server, then a NamingException is thrown.

Is there a different property we need to use in our Hibernate configuration file to specify that lookups should be performed via a resource-ref? Can we substitute a class that Hibernate will use to do naming lookups via resource-refs? If someone could point us to an article or tutorial on the subject, we would certainly appreciate it.

Thanks in advance

- JP


Top
 Profile  
 
 Post subject: Re: Hibernate 3.3 and J2EE resource-ref not working in WebSphere
PostPosted: Tue Aug 24, 2010 10:55 am 
Newbie

Joined: Mon Aug 16, 2010 11:57 am
Posts: 2
hmmm ... no takers. Any WebSphere users in the house ? :)


Top
 Profile  
 
 Post subject: Re: Hibernate 3.3 and J2EE resource-ref not working in WebSphere
PostPosted: Tue Aug 24, 2010 11:12 am 
Beginner
Beginner

Joined: Thu Feb 08, 2007 10:40 am
Posts: 46
Why not use the same JNDI name on all stages?

If that is not an option.. have you tried doing the lookup on the resource-ref yourself. I am not sure, what that would give you in return (a string with the _actual_ JNDI name to use)? What I have been successfully doing is adding properties to the hibernate configuration at runtime, when using a session factory. For your problem, this could look something like this:

Code:
// read hibernate configuration file
HIBERNATE_CONFIG = new Configuration();
HIBERNATE_CONFIG.configure(HIBERNATE_CONFIG_FILE);

// add (or modify) your own properites at runtime
Properties properties = new Properties();
properties.put("hibernate.connection.datasource", dataSourceName);
HIBERNATE_CONFIG.addProperties(properties);

// create session factory
SESSION_FACTORY = HIBERNATE_CONFIG.buildSessionFactory();

Now, if you can lookup the dataSourceName from JNDI or if you can read it from a stage property file, you have almost build what hibernate should do on its own or rather what WebSphere should provide.


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.