Skip to main content

Separate JNDI per instance?

Please note these java.net forums are being decommissioned and use the new and improved forums at https://community.oracle.com/community/java.
3 replies [Last post]
seclarke
Offline
Joined: 2006-07-03

Hi,

I understand Glassfish uses a common JNDI across the domain (as defined by a management/admin domain DAS) and therefore shared across all clusters and instances within that admin domain.

Is this understanding correct? if so, are there any plans to change this?

I have a situation whereby i wish to deploy and manage (i.e. upgrade etc.) a single application for multiple clients - the application pulls things like DB connection details from the JNDI and uses EJB dependancy injection for all applicable resources. Ideally each instance would have a different DB within the JNDI. This looks like it could be possible as each instance seems to run in it's own JVM, however the shared JNDI means it cannot work.

Normally I could use an extenal properties file, however I am using Hibernate and it's entity manager which looks/expects the persistence XML to be within the package.

It feels like it should be possible? and I really don't want to produce multiple builds as that would be completley unscalable/supportable. I could also acheive this with seperate domains - but it really fits a common domain pattern with a single management console to manage all instances (they are of course the same instance of the application, just running with different values for the JNDI).

Has anyone experienced and solved this or a similiar problem?

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
cf126330
Offline
Joined: 2005-03-29

I don't quite understand your use case. Clustered instances are homogeneous and app deployed to a cluster share the common configuration including JNDI. Why would you want to have different datasource depending on which server instance the app is deployed to? Shouldn't the whole app shares a common database?

seclarke
Offline
Joined: 2006-07-03

I guess the confusion is coming from the use of the term "instance"... In Weblogic you can have a single "admin console" and then each "managed instance" has it's own JNDI etc. and what I am trying to achieve is something similiar.

Ultamatley I am trying to run multiple discreet copies of the same application with a single admin point. The application is designed on a per client basis only, so a shared database is not possible (nor desirable to have the same customers data within the same DB, this is a job management and invoice type CRM/ERP system) - if I create multiple Glassfish domains (each obviously has it's own JNDI, DAS etc.) then it all works fine as you would expect, but that feels untidy.

As another example - imagine a co-hosting environment whereby you can host multiple applications that are completley seperate from each other, but you can manage them from the one admin server (DAS) - this is very similiar to the weblogic approach.

If I could work around it if i could externalise the hibernate persistence XML file - thereby each instance of the application would use a different config which would point to a different DB - thats doesn't appear possible so both options seems not to work.

Does that make more sense?

ss141213
Offline
Joined: 2005-03-30

Although the JPA spec has provided options for a container to override
things like jta-data-source name while calling
PersistenceProvider.createContainerEMF, GlassFish does not currently
leverage it. File an RFE. Currently your option is to directly call
Persistence.createEntityManagerFactory and pass different values in the
Map parameter. You have to take care of things like transaction
management and life cycle of entity managers explicitly in your EJB with
this approach.

Sahoo
On Thursday 29 September 2011 02:30 AM, forums@java.net wrote:
>
> If I could work around it if i could externalise the hibernate
> persistence
> XML file - thereby each instance of the application would use a different
> config which would point to a different DB - thats doesn't appear
> possible so
> both options seems not to work.
>
> Does that make more sense?
>
>
> --
>
> [Message sent by forum member 'seclarke']
>
> View Post: http://forums.java.net/node/848220
>
>