You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@openjpa.apache.org by Pawel Veselov <pa...@gmail.com> on 2011/12/27 12:03:28 UTC

Lazy many-to-many properties don't load on demand? (2.1.1)

Hi.

I'm using 2.2.1

I have declared a ManyToMany property, with lazy fetch type (my entities
are all property based).
The property does not load when accessed (the collection is null).
Setting it to eager loading works, but I don't want (for performance
reasons) for it to always load.

Is there something I may be missing?

Thank you,
  Pawel.

Re: Lazy many-to-many properties don't load on demand? (2.1.1)

Posted by Pawel Veselov <pa...@gmail.com>.
Hi Rick.

On Tue, Dec 27, 2011 at 1:35 PM, Rick Curtis <cu...@gmail.com> wrote:

> How are you enhancing your entities and


Enhancing is done with PCEnhancer, during build time.


> can you post the contents of your
> persistence.xml?
>

<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence" version="2.0">

    <persistence-unit name="Snap">

<provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider>
        <non-jta-data-source>snap_db_jpa</non-jta-data-source>
        <class>xxx.E_App</class>
        <class>xxx.E_AppDevMap</class>
        <class>xxx.E_AppDevMapId</class>
        <class>xxx.E_Device</class>
        <class>xxx.E_Category</class>
        <class>xxx.E_Tag</class>

        <properties>
            <property name="openjpa.Log" value="File=/tmp/jpa.log,
SQL=TRACE"/>
        </properties>

    </persistence-unit>


</persistence>

Thank you,
  Pawel.



> On Dec 27, 2011 1:37 PM, "Pawel Veselov" <pa...@gmail.com> wrote:
>
> > Hi.
> >
> > On Tue, Dec 27, 2011 at 8:42 AM, Pinaki Poddar <pp...@apache.org>
> wrote:
> >
> > > > @ManyToMany(fetch = FetchType.LAZY, mappedBy = "categories")
> > > > public Collection<E_App> apps;
> > >
> > > change 'public' to 'private'
> > >
> >
> > I will try this tonight. Any reason why? I typically access the fields
> > directly, without getters. Would that not work for any other fields
> loaded
> > lazy as well? The only other ones I have declared LAZY are LOBs.
>
>

Re: Lazy many-to-many properties don't load on demand? (2.1.1)

Posted by Rick Curtis <cu...@gmail.com>.
How are you enhancing your entities and can you post the contents of your
persistence.xml?
On Dec 27, 2011 1:37 PM, "Pawel Veselov" <pa...@gmail.com> wrote:

> Hi.
>
> On Tue, Dec 27, 2011 at 8:42 AM, Pinaki Poddar <pp...@apache.org> wrote:
>
> > > @ManyToMany(fetch = FetchType.LAZY, mappedBy = "categories")
> > > public Collection<E_App> apps;
> >
> > change 'public' to 'private'
> >
>
> I will try this tonight. Any reason why? I typically access the fields
> directly, without getters. Would that not work for any other fields loaded
> lazy as well? The only other ones I have declared LAZY are LOBs.
>
> Thank you,
>  Pawel.
>
>
> >
> > -----
> > Pinaki Poddar
> > Chair, Apache OpenJPA Project
> >
>

Re: Lazy many-to-many properties don't load on demand? (2.1.1)

Posted by Pawel Veselov <pa...@gmail.com>.
Hi Pinaki.

On Tue, Dec 27, 2011 at 1:08 PM, Pinaki Poddar <pp...@apache.org> wrote:

> "The instance variables of a class must be private, protected, or package
> visibility independent of
> whether field access or property access is used. When property access is
> used, the property accessor
> methods must be public or protected."
>

thank you, that explains it. Changing all fields to private, and adding
getters worked, obviously.


> JPA 2.0 Section 2.2
>
> /respect

Re: Lazy many-to-many properties don't load on demand? (2.1.1)

Posted by Pinaki Poddar <pp...@apache.org>.
"The instance variables of a class must be private, protected, or package
visibility independent of
whether field access or property access is used. When property access is
used, the property accessor
methods must be public or protected."
JPA 2.0 Section 2.2

-----
Pinaki Poddar
Chair, Apache OpenJPA Project
--
View this message in context: http://openjpa.208410.n2.nabble.com/Lazy-many-to-many-properties-don-t-load-on-demand-2-1-1-tp7129842p7131059.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.

Re: Lazy many-to-many properties don't load on demand? (2.1.1)

Posted by Pawel Veselov <pa...@gmail.com>.
Hi.

On Tue, Dec 27, 2011 at 8:42 AM, Pinaki Poddar <pp...@apache.org> wrote:

> > @ManyToMany(fetch = FetchType.LAZY, mappedBy = "categories")
> > public Collection<E_App> apps;
>
> change 'public' to 'private'
>

I will try this tonight. Any reason why? I typically access the fields
directly, without getters. Would that not work for any other fields loaded
lazy as well? The only other ones I have declared LAZY are LOBs.

Thank you,
  Pawel.


>
> -----
> Pinaki Poddar
> Chair, Apache OpenJPA Project
>

Re: Lazy many-to-many properties don't load on demand? (2.1.1)

Posted by Pinaki Poddar <pp...@apache.org>.
> @ManyToMany(fetch = FetchType.LAZY, mappedBy = "categories")
> public Collection<E_App> apps; 

change 'public' to 'private'

-----
Pinaki Poddar
Chair, Apache OpenJPA Project
--
View this message in context: http://openjpa.208410.n2.nabble.com/Lazy-many-to-many-properties-don-t-load-on-demand-2-1-1-tp7129842p7130527.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.

Re: Lazy many-to-many properties don't load on demand? (2.1.1)

Posted by Pawel Veselov <pa...@gmail.com>.
On Tue, Dec 27, 2011 at 4:27 AM, Boblitz John <Jo...@bertschi.com>wrote:

> Is your persistent context still active?
>

Yep. The operations are pretty much after each other.

            TypedQuery<E_Category> q2 =
                    em.createNamedQuery(Q.LIST_CATS, E_Category.class);
            for (E_Category db : q2.getResultList()) {
                appList.categories.add(new Category(db, true));
            }

Inside the 'new Category()', I access entity.apps, which is:

public class E_Category {
...
@ManyToMany(fetch = FetchType.LAZY, mappedBy = "categories")
public Collection<E_App> apps;
...
}

Mapping in the other direction is also LAZY.


Thanks,
  Pawel.

> -----Ursprüngliche Nachricht-----
> > Von: Pawel Veselov [mailto:pawel.veselov@gmail.com]
> > Gesendet: Dienstag, 27. Dezember 2011 12:03
> > An: users@openjpa.apache.org
> > Betreff: Lazy many-to-many properties don't load on demand? (2.1.1)
> >
> > Hi.
> >
> > I'm using 2.2.1
> >
> > I have declared a ManyToMany property, with lazy fetch type
> > (my entities are all property based).
> > The property does not load when accessed (the collection is null).
> > Setting it to eager loading works, but I don't want (for performance
> > reasons) for it to always load.
> >
> > Is there something I may be missing?
> >
> > Thank you,
> >   Pawel.
> >
>

AW: Lazy many-to-many properties don't load on demand? (2.1.1)

Posted by Boblitz John <Jo...@BERTSCHI.com>.
Is your persistent context still active?

 

John

---- 

Who is General Failure, and why is he reading my hard disk?

 

> -----Ursprüngliche Nachricht-----
> Von: Pawel Veselov [mailto:pawel.veselov@gmail.com] 
> Gesendet: Dienstag, 27. Dezember 2011 12:03
> An: users@openjpa.apache.org
> Betreff: Lazy many-to-many properties don't load on demand? (2.1.1)
> 
> Hi.
> 
> I'm using 2.2.1
> 
> I have declared a ManyToMany property, with lazy fetch type 
> (my entities are all property based).
> The property does not load when accessed (the collection is null).
> Setting it to eager loading works, but I don't want (for performance
> reasons) for it to always load.
> 
> Is there something I may be missing?
> 
> Thank you,
>   Pawel.
>