You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@aries.apache.org by "Delaire, Jonathan" <Jo...@experian.com> on 2015/09/16 12:24:10 UTC

Externalize the orm property from the persistence.xml

Hi Guys!

I'm currently working on a large refactoring of a project with the goal of using the JPA Aries within an OSGi  container for persistence (rather than plain old J2EE stack).

Currently so far so good, I'm following the guidance of the tasklit blueprint (it is managed jpa) example from your website and everything works fine (I'm using felix 5, with the aries jpa 2.1 version and hibernate 4.3+ as orm)

I'm trying to make the solution the most configurable as possible, currently my persistence.xml look like this:

<?xml version="1.0" encoding="UTF-8"?>

<persistence xmlns="http://java.sun.com/xml/ns/persistence"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd<http://java.sun.com/xml/ns/persistence%20http:/java.sun.com/xml/ns/persistence/persistence_1_0.xsd>"
             version="1.0">
    <persistence-unit name="Audit" transaction-type="JTA">
        <jta-data-source>osgi:service/javax.sql.DataSource/(osgi.jndi.service.name=jdbc/audit)</jta-data-source>

        <properties>
            <property name="hibernate.connection.driver_class" value="org.apache.derby.jdbc.EmbeddedDriver"/>
            <property name="hibernate.dialect" value="org.hibernate.dialect.DerbyDialect"/>
            <property name="hibernate.hbm2ddl.auto" value="create-drop"/>
        </properties>
    </persistence-unit>
</persistence>

I have externalized the dataSource configuration using blueprint-cm with configAdmin so for the dataSource it is working good.

But now I'm left with these properties in red, what do you think would be the most elegant way of externalizing them ?

Note that my entityManager is injected like this:

    /**
     * EntityManager, injected by blueprint jpa.
    */
    @PersistenceContext(unitName = "Audit")
    private EntityManager entityManager;

Thanks for your support!
Jonathan

Information in this e-mail and any attachments is confidential, and may not be copied or used by anyone other than the addressee, nor disclosed to any third party without our permission. There is no intention to create any legally binding contract or other binding commitment through the use of this electronic communication unless it is issued in accordance with the Experian Limited standard terms and conditions of purchase or other express written agreement between Experian Limited and the recipient. Although Experian has taken reasonable steps to ensure that this communication and any attachments are free from computer viruses, you are advised to take your own steps to ensure that they are actually virus free. 

Experian Ltd is authorised and regulated by the Financial Conduct Authority.
Companies Act information: Registered name: Experian Limited. Registered office: The Sir John Peace Building, Experian Way, NG2 Business Park, Nottingham, NG80 1ZZ, United Kingdom. Place of registration: England and Wales. Registered number: 653331.

RE: Externalize the orm property from the persistence.xml

Posted by "Delaire, Jonathan" <Jo...@experian.com>.
Thanks for your reply Christian, I didn't know for the hibernate.connection.driver_class,

Currently we externalized the dialect so that the end user can choose which database he want to use, other properties would be used for performance tuning I guess, it's easier to modify a .cfg rather than digging into the jars and change the xml file,

Jonathan

From: Christian Schneider [mailto:cschneider111@gmail.com] On Behalf Of Christian Schneider
Sent: 16 September 2015 12:32
To: user@aries.apache.org
Subject: Re: Externalize the orm property from the persistence.xml

If you are using a data source then hibernate.connection.driver_class should not be necessary.
The other ones are needed. Why do you want to externalize them?

Btw. in our tests we have properties for hibernate, eclipselink and openjpa side by side. So we can switch the persistence provider without changing the persistence.xml.

For a real project the typical case is to use an embedded DB for tests and a bigger one for prod. There again it should not hurt to have both configs in the same persistence.xml.

Christian

On 16.09.2015 12:24, Delaire, Jonathan wrote:
Hi Guys!

I'm currently working on a large refactoring of a project with the goal of using the JPA Aries within an OSGi  container for persistence (rather than plain old J2EE stack).

Currently so far so good, I'm following the guidance of the tasklit blueprint (it is managed jpa) example from your website and everything works fine (I'm using felix 5, with the aries jpa 2.1 version and hibernate 4.3+ as orm)

I'm trying to make the solution the most configurable as possible, currently my persistence.xml look like this:

<?xml version="1.0" encoding="UTF-8"?>

<persistence xmlns="http://java.sun.com/xml/ns/persistence<https://urldefense.proofpoint.com/v2/url?u=http-3A__java.sun.com_xml_ns_persistence&d=BQMDEA&c=BNNF-YNv0CLLslhP2Bcx5Q&r=qRc1fEiiFdAoKgEAqSoXUnFzqzef5YKMohrLQFUub18&m=0tri42FW1UWQ-fbfwaAF9Ed-uqqnird17AwUmk9mdOI&s=T-6eXkSR3oHn8t_Wx3YYkNcEbVCNcp9uHacmnPS0BK0&e=>"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance<https://urldefense.proofpoint.com/v2/url?u=http-3A__www.w3.org_2001_XMLSchema-2Dinstance&d=BQMDEA&c=BNNF-YNv0CLLslhP2Bcx5Q&r=qRc1fEiiFdAoKgEAqSoXUnFzqzef5YKMohrLQFUub18&m=0tri42FW1UWQ-fbfwaAF9Ed-uqqnird17AwUmk9mdOI&s=rxwp53wFCYa9yMIPfrijMXteQ7-5eNmWN9prE1K30SI&e=>"
             xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd<https://urldefense.proofpoint.com/v2/url?u=http-3A__java.sun.com_xml_ns_persistence-2520http-3A_java.sun.com_xml_ns_persistence_persistence-5F1-5F0.xsd&d=BQMDEA&c=BNNF-YNv0CLLslhP2Bcx5Q&r=qRc1fEiiFdAoKgEAqSoXUnFzqzef5YKMohrLQFUub18&m=0tri42FW1UWQ-fbfwaAF9Ed-uqqnird17AwUmk9mdOI&s=VpVe-BEph9JGyfKDtaS_nU-XozdugsY71lBYrEt1Lbs&e=>"
             version="1.0">
    <persistence-unit name="Audit" transaction-type="JTA">
        <jta-data-source>osgi:service/javax.sql.DataSource/(osgi.jndi.service.name=jdbc/audit)</jta-data-source>

        <properties>
            <property name="hibernate.connection.driver_class" value="org.apache.derby.jdbc.EmbeddedDriver"/>
            <property name="hibernate.dialect" value="org.hibernate.dialect.DerbyDialect"/>
            <property name="hibernate.hbm2ddl.auto" value="create-drop"/>
        </properties>
    </persistence-unit>
</persistence>

I have externalized the dataSource configuration using blueprint-cm with configAdmin so for the dataSource it is working good.

But now I'm left with these properties in red, what do you think would be the most elegant way of externalizing them ?

Note that my entityManager is injected like this:

    /**
     * EntityManager, injected by blueprint jpa.
    */
    @PersistenceContext(unitName = "Audit")
    private EntityManager entityManager;

Thanks for your support!
Jonathan
Information in this e-mail and any attachments is confidential, and may not be copied or used by anyone other than the addressee, nor disclosed to any third party without our permission. There is no intention to create any legally binding contract or other binding commitment through the use of this electronic communication unless it is issued in accordance with the Experian Limited standard terms and conditions of purchase or other express written agreement between Experian Limited and the recipient. Although Experian has taken reasonable steps to ensure that this communication and any attachments are free from computer viruses, you are advised to take your own steps to ensure that they are actually virus free.

Experian Ltd is authorised and regulated by the Financial Conduct Authority.
Companies Act information: Registered name: Experian Limited. Registered office: The Sir John Peace Building, Experian Way, NG2 Business Park, Nottingham, NG80 1ZZ, United Kingdom. Place of registration: England and Wales. Registered number: 653331.




--

Christian Schneider

http://www.liquid-reality.de<https://urldefense.proofpoint.com/v2/url?u=http-3A__www.liquid-2Dreality.de&d=BQMDEA&c=BNNF-YNv0CLLslhP2Bcx5Q&r=qRc1fEiiFdAoKgEAqSoXUnFzqzef5YKMohrLQFUub18&m=0tri42FW1UWQ-fbfwaAF9Ed-uqqnird17AwUmk9mdOI&s=k1w5puVb3ILp8Uyb99FnoXaKCXJCqEegE9u8Ju6lHT8&e=>



Open Source Architect

http://www.talend.com<https://urldefense.proofpoint.com/v2/url?u=http-3A__www.talend.com&d=BQMDEA&c=BNNF-YNv0CLLslhP2Bcx5Q&r=qRc1fEiiFdAoKgEAqSoXUnFzqzef5YKMohrLQFUub18&m=0tri42FW1UWQ-fbfwaAF9Ed-uqqnird17AwUmk9mdOI&s=_sBh86Lzim7H92473XRDvjwgDswjSYYZtX-RoDZgoP0&e=>

Information in this e-mail and any attachments is confidential, and may not be copied or used by anyone other than the addressee, nor disclosed to any third party without our permission. There is no intention to create any legally binding contract or other binding commitment through the use of this electronic communication unless it is issued in accordance with the Experian Limited standard terms and conditions of purchase or other express written agreement between Experian Limited and the recipient. Although Experian has taken reasonable steps to ensure that this communication and any attachments are free from computer viruses, you are advised to take your own steps to ensure that they are actually virus free. 

Experian Ltd is authorised and regulated by the Financial Conduct Authority.
Companies Act information: Registered name: Experian Limited. Registered office: The Sir John Peace Building, Experian Way, NG2 Business Park, Nottingham, NG80 1ZZ, United Kingdom. Place of registration: England and Wales. Registered number: 653331.

Re: Externalize the orm property from the persistence.xml

Posted by Christian Schneider <ch...@die-schneider.net>.
If you are using a data source then hibernate.connection.driver_class 
should not be necessary.
The other ones are needed. Why do you want to externalize them?

Btw. in our tests we have properties for hibernate, eclipselink and 
openjpa side by side. So we can switch the persistence provider without 
changing the persistence.xml.

For a real project the typical case is to use an embedded DB for tests 
and a bigger one for prod. There again it should not hurt to have both 
configs in the same persistence.xml.

Christian

On 16.09.2015 12:24, Delaire, Jonathan wrote:
>
> Hi Guys!
>
> I’m currently working on a large refactoring of a project with the 
> goal of using the JPA Aries within an OSGi  container for persistence 
> (rather than plain old J2EE stack).
>
> Currently so far so good, I’m following the guidance of the tasklit 
> blueprint (it is managed jpa) example from your website and everything 
> works fine (I’m using felix 5, with the aries jpa 2.1 version and 
> hibernate 4.3+ as orm)
>
> I’m trying to make the solution the most configurable as possible, 
> currently my persistence.xml look like this:
>
> /<?xml version="1.0" encoding="UTF-8"?>/
>
> //
>
> /<persistence xmlns="http://java.sun.com/xml/ns/persistence//"/
>
> /             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance//"/
>
> /xsi:schemaLocation="http://java.sun.com/xml/ns/persistence 
> http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd 
> <http://java.sun.com/xml/ns/persistence%20http:/java.sun.com/xml/ns/persistence/persistence_1_0.xsd>//"/
>
> /version="1.0">/
>
> /    <persistence-unit name="Audit" transaction-type="JTA"> /
>
> /        <jta-data-source>osgi:service/javax.sql.DataSource/(osgi.jndi.service.name=jdbc/audit)</jta-data-source>/
>
> //
>
> /        <properties>/
>
> /<property name="hibernate.connection.driver_class" 
> value="org.apache.derby.jdbc.EmbeddedDriver"/>/
>
> /<property name="hibernate.dialect" 
> value="org.hibernate.dialect.DerbyDialect"/>/
>
> /<property name="hibernate.hbm2ddl.auto" value="create-drop"/>/
>
> /        </properties>/
>
> /    </persistence-unit>/
>
> /</persistence>/
>
> I have externalized the dataSource configuration using blueprint-cm 
> with configAdmin so for the dataSource it is working good.
>
> But now I’m left with these properties in red, what do you think would 
> be the most elegant way of externalizing them ?
>
> Note that my entityManager is injected like this:
>
> /    /**/
>
> /     * EntityManager, injected by blueprint jpa./
>
> /    *//
>
> /    @PersistenceContext(unitName = "Audit")/
>
> /    private EntityManager entityManager;/
>
> //
>
> Thanks for your support!
>
> Jonathan
>
> Information in this e-mail and any attachments is confidential, and 
> may not be copied or used by anyone other than the addressee, nor 
> disclosed to any third party without our permission. There is no 
> intention to create any legally binding contract or other binding 
> commitment through the use of this electronic communication unless it 
> is issued in accordance with the Experian Limited standard terms and 
> conditions of purchase or other express written agreement between 
> Experian Limited and the recipient. Although Experian has taken 
> reasonable steps to ensure that this communication and any attachments 
> are free from computer viruses, you are advised to take your own steps 
> to ensure that they are actually virus free.
>
> Experian Ltd is authorised and regulated by the Financial Conduct 
> Authority.
> Companies Act information: Registered name: Experian Limited. 
> Registered office: The Sir John Peace Building, Experian Way, NG2 
> Business Park, Nottingham, NG80 1ZZ, United Kingdom. Place of 
> registration: England and Wales. Registered number: 653331.


-- 
Christian Schneider
http://www.liquid-reality.de

Open Source Architect
http://www.talend.com