persistence@glassfish.java.net

Re: Some question regarding JPA

From: Marina Vatkina <Marina.Vatkina_at_Sun.COM>
Date: Mon, 17 Apr 2006 10:49:25 -0700

Tom,

Calling Persistence.createEntityManagerFactory(pu) is accessing PU outside
a container. Will this call create a new EMF every time?

thanks,
-marina

Tom Ware wrote:
> Hi Marcel,
>
> I'll handle question #2. I'll let the folks that work on the container
> answer the other ones.
>
> #2 The javaagent is used to allow us to do dynamic weaving of domain
> classes that use fetch=LAZY for OneToOne and ManyToOne mappings. Those
> classes are weaved to contain som TopLink-specific data structures that
> allow us to provide LAZY loading of those relationships. If you do not
> want to (or cannot use the agent), a flag can be provided in the
> properties of your persitence unit to avoid the weaving. The property
> "toplink.weaving" can be set to "false". This will disable the
> weaving. The consequences of setting this property is that the LAZY
> hint will not be observed for OneToOne and ManyToOne relationships and
> they will be loaded EAGERly.
>
> -Tom
>
> Marcel Overdijk wrote:
>
>> Hi,
>>
>> I'm adding JPA support to a framework and have some questions.
>> Currently I'm using the Toplink Essentials and javaee.jar from
>> GlassFish M6.
>>
>> 1. The javaee.jar contains more then only the persistence related
>> classes and therefor is 1mb big. Is there a official Sun jar
>> downloadable containing only persistence classes. In Spring 2.0
>> distribution a persistence.jar (58kb) is included. I can use this but
>> I don't know the origin of it.
>>
>> 2. In the persistence example on the GlassFish page the
>> toplinks-essentials-agent.jar is used in combination with -javaagent
>> (SE example). What does the toplink-essentials-agent do? If I just put
>> toplink-essentials and javaee.jar on the classpath everything seems to
>> work fine. Is there any drawback?
>>
>> 3. When I want to get an EntityManager based on an persistence unit
>> Name I don't know at compile time. The only option (I believe) is to
>> create an emf first:
>> String pu = "some dynamic pu name";
>> Persistence.createEntityManagerFactory(pu);
>> However to create a emf each time is expensive. I could keep a
>> reference to a pu once created.
>> But what I'm wondering is how JEE 5 containers handle this. Do they
>> create subsequent emf's or are they smart that they know it was
>> already created in a previous call?
>>
>> Hope you can hekp me on this.
>>
>> Regards,
>> Marcel Overdijk
>>
>>
>>