Skip to main content

Changing ejb-jar.xml and persistence.xml in runtime

4 replies [Last post]
edilmar
Offline
Joined: 2003-11-13
Points: 0

Using GF3.1.x, is there some way to change the files ejb-jar.xml and persistence.xml, and to have a command-line or a programming way to reload these files in the web app?

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
f3riyanto
Offline
Joined: 2013-10-23
Points: 0

Dear Edilmar,

My Question is why you need to change the persistence.xml files.
Almost all configuration can be configure from container (in this case : glassfish). Use datasource name JNDI to more flexible configuration.

ejb-jar.xml now can be using with 2 method
1. use annotation (programatically)
with this way, you can make some configuration more flexible
2. use xml

Hope this will help you.

Thanks
Ferry

edilmar
Offline
Joined: 2003-11-13
Points: 0

Hi,

I have an webapp shared by many enterprises, where each enterprise has a database. The logical business is the same for all enterprises and in this way it consumes minor memory from the server.

I use ejb-jar to configure JNDI names for databases, like this:

      <persistence-context-ref>
        <description>monteiro</description>            
        <persistence-context-ref-name>persistence/monteiroPU</persistence-context-ref-name>       
        <persistence-unit-name>monteiroPU</persistence-unit-name>
        <persistence-context-type>Transaction</persistence-context-type>               
      </persistence-context-ref>

And I use persistence for normal database configuration.

Then, I have an installer to put new enterprises, just adding new configurations in ejb-jar and persistence. The problem is that I have to redeploy the webapp after this, and all enterprises become without system.

f3riyanto
Offline
Joined: 2013-10-23
Points: 0

Hi Edilmar,

In your case, my suggesstion is you only need to deploy the new application (war in this case) into separate domains (Glassfish).

Create new domain for each comapny/organization should be ok.
So you can change datasource directly from glassfsh server without have to change the persistence.xml.

Thanks
Ferry

edilmar
Offline
Joined: 2003-11-13
Points: 0

This solution to deploy a new app for each company is not possible,
because I have limited memory in the server. I pay for a virtual machine in a ISP with 2 Gb RAM, and with just one Glassfish domain, I get to install until 10 companies. If I will create a Glassfish domain for each one, I don't get to put more than 5 companies. This was the old way I had, bad to scale and save money.