Hi Heather,
Interesting use of the OpenJPA metadata processing.  Just from your brief
description, I would be careful on depending on an implementation versus
defined interfaces.  Even if we could get this initialization done earlier
for you, unless there was some defined mechanism to force this (ie. the
openjpa.InitializeEagerly property), I wouldn't count on it.  In this
particular case, the metadata repository is meant for OpenJPA processing.

I know with OpenJPA the lines may not be crystal clear between public API's,
provider SPI's, or internal classes.  Of course, since this is an
open-source project, you are welcome to peruse the complete contents of the
code base and see if a solution is doable or not.  I would just be careful
on being too dependent on a specific implementation.

Kevin

On Fri, May 15, 2009 at 9:30 AM, Heather Sterling <hst...@us.ibm.com> wrote:

> Thanks Kevin.
>
> Our scenario is that we have added product-specific annotations to the
> persistent classes. In particular, we have some annotations that we need in
> our perPersist entity listener to generate unique identifiers before the
> object is persisted. We're currently initializing all of the metadata at the
> beginning. We essentially iterate through the persistent classes and create
> maps that hold this extra information. I guess it's possible for us to
> lazily load this data in the entity listener if it hasn't been loaded for a
> particular class. I also looked to see if there was another hook we could
> potentially use, but didn't see any that seemed to fit the problem.
>
>
> Heather Sterling
> Systems Management Development
> Phone: 919-254-7163 T/L: 444-7163
> Cell: 919-423-3143
> Email: hst...@us.ibm.com
>
>
> [image: Inactive hide details for Kevin Sutter ---05/12/2009 12:53:30
> PM---Heather,]
> Kevin Sutter ---05/12/2009 12:53:30 PM---Heather,
>
>
>
>
>     *Kevin Sutter <kwsut...@gmail.com>*
>
>             05/12/2009 12:48 PM
>             Please respond to users
>
>
>
>  To: users@openjpa.apache.org
>  cc:
>  Subject: Re: correct way to load persistent metadata at startup
>
>
> Heather,
> Good question...  :-)  This topic has come up recently due to some
> potential
> locking issues (serialized access) when reading the metadata repository in
> a
> multi-threaded environment.  At this point, there is not a clear cut answer
> for forcing the initialization of the metadata repository.  The code for
> the
> new openjpa.InitializeEagerly property was committed to trunk last August
> (after the 1.2.0 release was created), but we've since determined that it
> may not be complete for all cases.  You are welcome to try it out from
> either the 1.3.x or trunk branches and see if it helps in your particular
> situation.
>
> Let us know what you find out.  Also, can you explain your need for getting
> this data eagerly vs letting the lazy loading process play out?  Thanks!
>
> Kevin
>
>
>
> On Mon, May 11, 2009 at 2:40 PM, Heather Sterling <hst...@us.ibm.com>
> wrote:
>
> >
> >
> > I am attempting to load all the persistent class metadata eagerly.  I
> > realize this isn't great performance-wise, but I need to do it for the
> > time-being.   I had wanted to call:
> >
> >            ClassMetaData[] classMetaDatas =
> > conf.getMetaDataRepositoryInstance().getMetaDatas();
> >
> > but realized the data was loaded lazily when nothing came back.  I
> switched
> > to using:);
> >
> > Collection c = conf.getMetaDataRepositoryInstance().loadPersistentTypes(.
> > true, null);
> >
> > which returned the classes to me, but getMetaDatas() still returned
> > nothing.  Finally, I resorted to iterating through the class names, which
> > seemed to work.
> >
> >            Set names = conf.getMetaDataRepositoryInstance
> > ().getPersistentTypeNames(false, null);
> >            if (names != null) {
> >                for (Iterator it = names.iterator(); it.hasNext();) {
> >                    String persistentClassname = (String)it.next();
> >                    System.out.println("Pre-loading metadata for: " +
> > persistentClassname);
> >                    try {
> >                    ClassMetaData cc = conf.getMetaDataRepositoryInstance
> > ().getMetaData(Class.forName(persistentClassname), null, true);
> >                } catch (ClassNotFoundException e) {
> >                    // TODO Auto-generated catch block
> >                    e.printStackTrace();
> >                }
> >
> >                }
> >            }
> >
> > I found a link regarding a potential openjpa property called
> > openjpa.InitializeEagerly (
> > https://issues.apache.org/jira/browse/OPENJPA-620) but it was never
> > checked
> > into a release.
> >
> > Given all these options, what is the correct way to load the metadata on
> > startup?
> >
> >
> > Heather Sterling
> > Systems Management Development
> > Phone:  919-254-7163 T/L: 444-7163
> > Cell: 919-423-3143
> > Email: hst...@us.ibm.com
>

Reply via email to