Instances and JDBC resources

44 views
Skip to first unread message

Joshua

unread,
Aug 9, 2018, 1:10:19 PM8/9/18
to Payara Forum
I have some questions about the best way to go about setting up an application. I have an application which is the same war file for many different clients. Each client has it's own database which stores it's specific data. I'm trying to make managing and developing this as easy as possible while still allowing clustering.

So i created an instance for each client and was hoping to deploy the application using the same JDBC resource name so the war wouldn't have to be recompiled per client. But the JDBC resources are shared between instances even if the instance doesn't have access to that resource. So I can't reuse the same name and have the instance configured to pick that up automatically.

So does anyone know a solution to allow one compiled war deployed on different instances to pick up different database connections automatically?

Thanks

Tony Shuba

unread,
Aug 9, 2018, 1:47:00 PM8/9/18
to Payara Forum
Interesting question.

Without knowing anything of your requirements, my first thought goes to the database model.  Not that this helps you at all, but I would think this architecture would have lent itself to a multi-tenant strategy.  That might have made this a bit easier since you'd only have the single database resource.  

That said, it seems like you can still pull this off by perhaps using JNDI to set up a resource per client that defines which JDBC resource to use.  You'll have to change your application to no longer look directly for the JDBC resource by name, instead it would pick up the JNDI name for that client.  You'd still need to create multiple JDBC resources (one for each client). 

Joshua

unread,
Aug 9, 2018, 1:59:16 PM8/9/18
to Payara Forum
Yes a multi-tenant strategy would have been nice to use. But currently that is not possible in any sense, nor is it likely to happen anytime soon :(

I can setup the JNDI per client for the JDBC Resource. The question is how do I tell the application persistence.xml to use each clients JNDI name without recompiling the application once for each client. Which can lead to mistakes and a complex build. Looking for a way to set a property in an instance to pass to the persistence.xml so it uses what is configured in the instance. To prevent the recompiling of the application each time, just deploying it to a instance will point it to the correct database.

Steve Millidge

unread,
Aug 9, 2018, 2:30:53 PM8/9/18
to Payara Forum
Perhaps you can use environment variables or system properties in the resource configuration. See https://docs.payara.fish/documentation/payara-server/server-configuration/var-substitution/types-of-variables.html

Joshua

unread,
Aug 9, 2018, 4:46:53 PM8/9/18
to Payara Forum
I found that link and thought I was home free and clear. I added a system property to point to the JNDI that I wanted. It worked for the payara domain, so I tried to add the system property to the instance and deploy the application to the instance. It doesn't find the system property and doesn't deploy the application.

I'm using ${CLIENT_JTA_DATA_SOURCE} and I get the error "Exception while preparing the app : Invalid resource : ${CLIENT_JTA_DATA_SOURCE}__pm"

José Pereira

unread,
Aug 9, 2018, 5:21:39 PM8/9/18
to Joshua, Payara Forum
Are you using hibernate as underlying jpa implementation? If so, then there is support for per-database multitenancy as well as per-schema. Read about it in the hibernate documentation... you'll have to implement your own lookup code that is hibernate specific though... 

--
You received this message because you are subscribed to the Google Groups "Payara Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email to payara-forum...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/payara-forum/9adc56e0-4305-4da0-b8cb-0235b45b1ec6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Joshua

unread,
Aug 9, 2018, 5:23:39 PM8/9/18
to Payara Forum
No using eclipselink, the system properties should do the trick for what I want. It just needs to work with instances system properties which it appears to not, or is currently a bug.

Joshua

unread,
Sep 21, 2018, 6:03:13 PM9/21/18
to Payara Forum
Solution and Possible Bug.

You need to add the system properties to the Payara DAS as well as inside the instance system properties. When you deploy an application it checks the Paraya DAS for the variable and the setting of it first. After it passes from the Payara DAS it is then deployed to the instance where it picks up the correct system properties for the instance and the deployment is then successful.

Hope this helps others.

Martin Charlesworth

unread,
Sep 21, 2018, 8:42:05 PM9/21/18
to Payara Forum
Hi Joshua, we do this exact thing using docker. You can use environment variables for the server, database name, user and password in the connection pool config in payara, then set these as environment variables in a docker-compose file. Then you can deploy the same image for every clients, you just maintain a separate docker-compose file for each one. This assumes you use or can use docker of course! HTH,
Martin
Reply all
Reply to author
Forward
0 new messages