users@jpa-spec.java.net

[jpa-spec users] [jsr338-experts] Re: Re: Picking the right persistence unit from multiple choices when no unitName is specified

From: Michael Bouschen <michael.bouschen_at_akquinet.de>
Date: Wed, 19 Jun 2013 21:19:55 +0200

Hi,

I like the idea of specifying a default persistence unit name (e.g in
the form of a system property or any other global mechanism).
Without this option adding a new persistence-unit to the persistence.xml
would suddenly invalidate a PersistenceContext annotation of the form
   @PersistenceContext EntityManager em

Regards Michael

> On 06/19/2013 11:07 AM, Matthew Adams wrote:
>> Perhaps a Java system property called "javax.persistence.default-unit"
>> would work here instead, since you're talking about a concept that spans
>> multiple persistence units?
>
> If all containers supported a global default-unit name, that would
> also help application portability (doesn't matter where the global
> setting is stored).
>
> Or we could all agree that the container should fail the deployment
> for the below (ambiguous) case.
>
>>
>>
>> On Wed, Jun 19, 2013 at 6:50 AM, Scott Marlow <smarlow_at_redhat.com
>> <mailto:smarlow_at_redhat.com>> wrote:
>>
>> Should application deployment fail if there are multiple persistence
>> units defined and no unitName is specified? If not, which
>> persistence unit should be picked?
>>
>> For example, given the below persistence.xml contents:
>>
>> "
>> <persistence
>> <persistence-unit name="rightpu1">
>> </persistence-unit>
>> <persistence-unit name="otherrightpu2">
>> </persistence-unit>
>> </persistence>
>> "
>>
>> And a persistence context:
>>
>> "
>> @PersistenceContext EntityManager randompu;
>> "
>>
>> Should "rightpu1" be used or "otherrightpu2"?
>>
>> Should we have a standard pu property ("javax.persistence.default")
>> that allows the default pu to be specified for this case?
>>
>> If the default pu property is not specified, should application
>> deployment fail for this case? Or should the application deployment
>> continue with whichever persistence unit the deployer happens to
>> pick?
>>
>> Scott
>>
>>
>>
>>
>> --
>> mailto:matthew_at_matthewadams.me
>> skype:matthewadams12
>> googletalk:matthew_at_matthewadams.me
>> <mailto:googletalk%3Amatthew_at_matthewadams.me>
>> http://matthewadams.me
>> http://www.linkedin.com/in/matthewadams
>


-- 
*Michael Bouschen*
*Prokurist*
akquinet tech_at_spree GmbH
Bülowstr. 66, D-10783 Berlin
Fon:   +49 30 235 520-33
Fax:   +49 30 217 520-12
Email: michael.bouschen_at_akquinet.de
Web: www.akquinet.de <http://www.akquinet.de>
akquinet tech_at_spree GmbH, Berlin
Geschäftsführung: Martin Weber, Dr. Torsten Fink
Amtsgericht Berlin-Charlottenburg HRB 86780 B
USt.-Id. Nr.: DE 225 964 680