jsr342-experts@javaee-spec.java.net

[jsr342-experts] Re: Platform default data source and JMS connection factory

From: Antonio Goncalves <antonio.goncalves_at_gmail.com>
Date: Mon, 21 May 2012 20:50:47 +0200

Well I suppose you need an empty beans.xml to trigger CDI, an empty
faces-config.xml to trigger JSF... you would then need an empty
persistence.xml to trigger JPA.... makes sense.

Ok

Antonio

On Mon, May 21, 2012 at 8:28 PM, Linda DeMichiel <linda.demichiel_at_oracle.com
> wrote:

> Hi Antonio, all,
>
>
> On 5/21/2012 1:16 AM, Antonio Goncalves wrote:
>
>> Hi all,
>>
>> I was thinking about the default datasource... and a default
>> persistence.xml. With a default datasource, here is what a
>> minimal persistence.xml could look like in a managed environment :
>>
>> <?xml version="1.0" encoding="UTF-8"?>
>> <persistence xmlns="http://java.sun.com/**xml/ns/persistence<http://java.sun.com/xml/ns/persistence>
>> "
>> xmlns:xsi="http://www.w3.org/**2001/XMLSchema-instance<http://www.w3.org/2001/XMLSchema-instance>
>> "
>> xsi:schemaLocation="http://**java.sun.com/xml/ns/**
>> persistence <http://java.sun.com/xml/ns/persistence>
>> http://java.sun.com/xml/ns/**persistence/persistence_2_1.**xsd<http://java.sun.com/xml/ns/persistence/persistence_2_1.xsd>
>> "
>> version="2.1">
>>
>> <persistence-unit name="defaultPU" transaction-type="JTA">
>> *<jta-data-source>java:global/**defaultDataSource</jta-data-**source>*
>>
>
> By default, a JTA datasource is to be provided in Java EE container
> environments,
> so this will come for free :-)
>
>
> <properties>
>> <property name="hibernate.hbm2ddl.auto" value="create-drop"/>
>> </properties>
>> </persistence-unit>
>> </persistence>
>>
>> I don't know what are the plans on the JPA 2.1 expert group, but it would
>> be great to standardise more properties, like
>> the generation of tables at deployment. So we could have something like
>>
>>
> This area is currently under discussion in the JPA EG. Please see my
> proposal on schema
> generation and feel free to chime in over there.
>
> <persistence-unit name="defaultPU" transaction-type="JTA">
>> <jta-data-source>java:global/**defaultDataSource</jta-data-**source>
>> <properties>
>> *<property name="javax.persistence.**generateddl" value="create-drop"/>*
>>
>> </properties>
>> </persistence-unit>
>>
>> If we have all the needed configuration by default, then, why not having
>> a default persistence.xml with a default
>> persistence unit being produced by the container ? We could just then
>> write (without any extra configuration) :
>>
>>
> We had this discussion in the JPA 1.0 days, and experts were pretty much
> of the opinion that a
> persistence.xml would be needed anyway for configuration. Schema
> generation properties will
> presumably add to this. Again, feel free to raise the issue to the JPA
> 2.1 EG.
>
> thanks,
>
> -Linda
>
> @Stateless
>> public class MyService {
>>
>> @Inject
>> private EntityManager entityManager;
>> }
>>
>> Again, that's inreasing the easy of development. Any thoughts ?
>>
>> Antonio
>>
>> On Sun, Apr 15, 2012 at 7:13 PM, Adam Bien <abien_at_adam-bien.com <mailto:
>> abien_at_adam-bien.com>> wrote:
>>
>>
>> On 22.03.2012, at 23:23, Linda DeMichiel wrote:
>>
>> > In view of the feedback we've received on this issue, our
>> conclusion is
>> > that we should adopt approach 3.
>> >
>> > To summarize, in the data source case, the following will apply:
>> >
>> > The Java EE Platform requires that a Java EE Product Provider
>> > provide a database in the operational environment. The Java EE
>> > Product Provider must also provide a preconfigured, default data
>> > source for use by the application in accessing this database.
>> >
>> > The Java EE Product Provider must make the default data source
>> > accessible to the application under the JNDI name
>> > java:comp/defaultDataSource.
>> >
>> > The Application Component Provider or Deployer may explicitly bind a
>> > DataSource resource reference to the default data source using the
>> > lookup element of the Resource annotation or the lookup-name element
>> > of the resource-ref deployment descriptor element. For example,
>> >
>> > @Resource(name="myDataSource", lookup="java:comp/**
>> defaultDataSource")
>> > DataSource myDS;
>>
>> +1 but:
>>
>> @Inject
>> DataSource myDS; should work as well. (I would require a default
>> producer to do the job).
>> >
>> > If a DataSource resource reference is not mapped to a specific data
>> > source by the Application Component Provider or Deployer, it must be
>> > mapped by the Java EE Product Provider to a preconfigured data
>> source
>> > for the Java EE Product Provider's default database. For example,
>> in
>> > the absence of any action on the part of the developer or deployer,
>> > the following will map to a preconfigured data source for the
>> > product's default database:
>> >
>> > @Resource(name="myDataSource")
>> > DataSource myDS;
>> >
>> >
>> > And similarly for default JMS Connection Factory, whose JNDI name is
>> > java:comp/**defaultJMSConnectionFactory.
>> >
>> >
>> > -Linda
>> >
>> >
>>
>>
>>
>>
>> --
>> Antonio Goncalves
>> Software architect and Java Champion
>>
>> Web site <http://www.antoniogoncalves.**org<http://www.antoniogoncalves.org>>
>> | Twitter <http://twitter.com/agoncal> | Blog
>> <http://feeds.feedburner.com/**AntonioGoncalves<http://feeds.feedburner.com/AntonioGoncalves>>
>> | LinkedIn <http://www.linkedin.com/in/**agoncal<http://www.linkedin.com/in/agoncal>>
>> | Paris JUG
>> <http://www.parisjug.org>
>>
>


-- 
Antonio Goncalves
Software architect and Java Champion
Web site <http://www.antoniogoncalves.org> |
Twitter<http://twitter.com/agoncal>|
Blog <http://feeds.feedburner.com/AntonioGoncalves> |
LinkedIn<http://www.linkedin.com/in/agoncal>| Paris
JUG <http://www.parisjug.org>