How to externalize persistence.xml properties for JBOSS 7.1.1?

My persistence.xml is currently present in the application warfare (in the META-INF. Folder). However, for an application that must run across multiple databases, persistence must be changed again and again. I want to avoid this. But I can’t understand how to configure properties (for example, dialect) in the persistence.xml file, say, with a properties file that I would modify based on my database, so it did not force me to update and translate my war.

My problem can also be solved if I can configure the dialect in the data source in the standalone.xml file, where I mentioned other details of the database. I can’t understand what kind of property this is. Although I would prefer a solution for the first.

PS: I am new to web application development. Questions may annoy you.: D

+1
source share
1 answer

I use a method that works well for sleep mode.

1) enter the hibernate configuration properties in the xml file (name hibernate.cfg.xml, but this is not necessary)

This is an example:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
    <session-factory>
        <property name="hibernate.dialect">org.hibernate.dialect.PostgreSQLDialect</property>
        <property name="hibernate.hbm2ddl.auto">create-drop</property>
        <property name="hibernate.show_sql">false</property>
        <property name="hibernate.search.default.directory_provider">ram</property>
    </session-factory>
</hibernate-configuration>

you can only set hibernation properties that do not start with hibernate.ejb

2) Create a jboss module. It is very simple. Suppose you want to call the module com.myorganization.config, than create a directory structure in the folder modulesfor installing the server: / com / myorganization / config / main. In the main folder, place the hibernate.cfg.xml file and the following file module.xml:

<?xml version="1.0" encoding="UTF-8"?>  
<module xmlns="urn:jboss:module:1.1" name="com.myorganization.config">  
    <resources>  
        <resource-root path="."/>  
    </resources>
</module>

3) The following property has been added to your persistence.xml file:

<property name="hibernate.ejb.cfgfile" value="/hibernate.cfg.xml" />

4) , META-INF/MANIFEST.MF :

Dependencies: com.myorganization.config

maven, maven-war-plugin, MANIFEST.MF:

<configuration>
    <archive>
        <manifestEntries>
            <Dependencies>com.myorganization.config</Dependencies>
        </manifestEntries>
    </archive>
</configuration>

.

+2

All Articles