users@jpa-spec.java.net

[jpa-spec users] [jsr338-experts] Re: Re: Re: add description of @PersistenceContexts to section 10.4.1 of the JPA 2.1 spec...

From: Scott Marlow <smarlow_at_redhat.com>
Date: Tue, 18 Sep 2012 12:34:05 +0200

@PersistenceUnits + @PersistenceContexts are both in JPA 2.0. I'm not
proposing that we add them to the specification, just that we document
them so that more people understand that they are available.

I apologize for not being clearer but greatly appreciate the discussion! :)

A similar example for @PersistenceUnits might be:

   @Stateless
   @PersistenceUnits({
   @PersistenceUnit(name="__OrderEMF"),
   @PersistenceUnit(name="__ItemEMF")
   })
   public class OrderEntryBean implements OrderEntry {
     @Resource EJBContext ctx;
     public Customer getCustomer(int custID) {
         EntityManagerFactory emf =
         (EntityManagerFactory)ctx.lookup("__OrderEMF");
         return emf.createEntityManager().find(Customer.class, custID);
         }
     public void enterItem(int orderID, Item newItem) {
         EntityManagerFactory emf =
         (EntityManagerFactory)ctx.lookup("__ItemEMF");
         ...
     }
}


On 09/18/2012 11:57 AM, Werner Keil wrote:
> I thought, that's done as of today with
>
> @PersistenceContext(unitName="...")
>
> Or is this a Spring proprietary way? (found it on a SpringSource docu)
>
>
> Would each PersistenceContext need more than one PersistenceUnit?
> Otherwise even if this has so far been Spring-specific, maybe we could
> keep that an attribute of the PersistenceContext instead of yet an other
> array of annotations??

no, PersistenceUnit (copied from JPA 2.0 spec) already has:

@Target({TYPE, METHOD, FIELD}) @Retention(RUNTIME)
public @interface PersistenceUnit {
String name() default "";
String unitName() default "";
}
@Target(TYPE) @Retention(RUNTIME)
public @interface PersistenceUnits {
PersistenceUnit[] value();
}

And PersistenceContext already has:

@Target({TYPE, METHOD, FIELD}) @Retention(RUNTIME)
public @interface PersistenceContext {
String name() default "";
String unitName() default "";
PersistenceContextType type default TRANSACTION;
PersistenceProperty[] properties() default {};
}
public enum PersistenceContextType {
TRANSACTION,
EXTENDED
}
@Target({}) @Retention(RUNTIME)
public @interface PersistenceProperty {
String name();
String value();
}
@Target({TYPE}) @Retention(RUNTIME)
public @interface PersistenceContexts {
PersistenceContext[] value();
}



>
> Werner
>
> On Tue, Sep 18, 2012 at 11:52 AM, Scott Marlow <smarlow_at_redhat.com
> <mailto:smarlow_at_redhat.com>> wrote:
>
> Could we also describe the @PersistenceUnits.
>
> "
> @PersistenceUnits
>
> If you need to specify more than one @PersistenceUnit, specify all
> the persistence units using a single @PersistenceUnits annotation.
> "
>
> Scott
>
>
> On 09/13/2012 07:29 PM, Linda DeMichiel wrote:
>
> Well, if people are confused, it doesn't hurt. Perhaps the
> javadoc page
> would be a better place though.
>
> On 9/13/2012 10:22 AM, michael keith wrote:
>
> Adding examples for @PersistenceContexts would kind of stick
> out,
> wouldn't it? If we add for that one annotation then we
> should probably add examples for all of them in the chapter.
> There are
> currently no examples for any of them.
>
> Sections 10.3.1 and 10.3.2 don't do any more than just
> mention the
> plural form in a sentence that states which classes
> they can annotate, and then they include the pluralized
> annotation
> definition. Sections 10.3.3 and 10.4.1 did include
> the definition, but did not mention it in text. Seems like if we
> wanted to make 10.3.3 and 10.4.1 be consistent with
> 10.3.1 and 10.3.2 the only thing that would need to be added
> would be
> a general statement of the form used in 10.3.1 and
> 10.3.2:
>
> <Annotation> and <pluralizedAnnotation> can be applied to .....
>
> -Mike
>
> On 13/09/2012 1:03 PM, Linda DeMichiel wrote:
>
> Hi Scott,
>
> Thanks for the suggestion. I will add.
>
> -Linda
>
>
> On 9/13/2012 5:37 AM, Scott Marlow wrote:
>
> Hi eg,
>
> I don't see a description of @PersistenceContexts.
> Could we add a
> few words about @PersistenceContexts to section
> 10.4.1?
>
> http://www.oracle.com/__technetwork/middleware/ias/__toplink-jpa-annotations-__096251.html
> <http://www.oracle.com/technetwork/middleware/ias/toplink-jpa-annotations-096251.html>
> includes the following:
>
> "
> @PersistenceContexts
>
> If you need to specify more than one
> @PersistenceContext, you must
> specify all your persistence contexts using a single
> @PersistenceContexts annotation.
> "
>
> The above link also has an example that would be
> nice to include:
>
> @Stateless
> @PersistenceContexts({
> @PersistenceContext(name="__OrderEM"),
> @PersistenceContext(name="__ItemEM")
> })
> public class OrderEntryBean implements OrderEntry {
> @Resource EJBContext ctx;
> public Customer getCustomer(int custID) {
> EntityManager em =
> (EntityManager)ctx.lookup("__OrderEM");
> return em.find(Customer.class, custID);
> }
> public void enterItem(int orderID, Item newItem) {
> EntityManager em =
> (EntityManager)ctx.lookup("__ItemEM");
> ...
> }
> }
>
>
>
>
>
>