openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Rick Curtis <curti...@gmail.com>
Subject Re: entities not detected properly in JUnit Test case (OpenJPA 1.2.2)
Date Tue, 07 Sep 2010 13:48:38 GMT
Marc -

I'm willing to bet that your Entities are being loaded before you execute
the query. You could try setting *-verbose:class* on your app server jvm and
add some debug to your app in the first place where you execute the query.
These two pieces of information should help you get a better feeling as to
what is going on.

Now your next question... where is DP_PLZ_DA.class is being loaded? You
could add a static initializer to DP_PLZ_DA.class and dump the stack trace
to figure out who is loading it.

Thanks,
Rick

On Tue, Sep 7, 2010 at 1:38 AM, Marc Logemann <li@logemann.org> wrote:

> Hi,
>
> thanks for this pretty straight answer. But one more thing that bothers me.
> Why is this only an issue while testing? When my app is running, i am pretty
> sure that i dont use the DP_PLZ_DA class somewhere in the code before the
> worfklow with the query arrives. So why does it work in normal runtime mode?
>
> ---
> regards
> Marc Logemann
> http://www.logemann.org
> http://www.logentis.de
>
>
>
>
> Am 06.09.2010 um 23:26 schrieb Rick Curtis:
>
> >> So why does OpenJPA fail on registering Entities?
> >
> > The problem is that when you don't list your entities, OpenJPA doesn't
> know
> > that the alias 'DP_PLZ_DA' is an Entity until the x.y.z.DP_PLZ_DA class
> is
> > loaded. If you were to look at an enhanced Entity you would see that
> OpenJPA
> > adds a static initializer that will register each Entity with OpenJPA.
> >
> > An alternative to calling "new DP_PLZ_DA();" would be to add something
> like
> > this to each of your testcases.
> >
> > // List each Entity that this test is going to use.
> > private Class[] _entities = new
> > Class[]{x.y.z.DP_PLZ_DA.class,x.y.z.DP_PLZ_DB.class,etc... };
> >
> > Thanks,
> > Rick
> >
> > On Mon, Sep 6, 2010 at 4:14 PM, Marc Logemann <li@logemann.org> wrote:
> >
> >> Hi,
> >>
> >> i am using a pretty straightforward Spring/OpenJPA JUnit Testcase
> scenario:
> >>
> >> @RunWith(SpringJUnit4ClassRunner.class)
> >> @ContextConfiguration(locations = "/appContext.xml")
> >> public class DHLLeitcodeCreatorTest {
> >>  ...
> >>  @Test
> >>   public void getDHLLeitcode() {
> >>       someBean.superDuperAction();
> >>  }
> >> }
> >>
> >> I am not explicitely declaring my entities in persistence.xml. Its all
> >> autodetected via Annotations. (at least during normal runtime).
> >>
> >> Inside superDuperAction(), a lot of queries are fired against OpenJPA.
> It
> >> fails on the first Query saying that it cant find Entity DP_PLZ_DA
> (weird
> >> class name, i know).
> >>
> >> "Error message: The name "DP_PLZ_DA" is not a recognized entity or ...."
> >>
> >> Now when i do this:
> >>
> >>  @Test
> >>   public void getDHLLeitcode() {
> >>      DP_PLZ_DA df = new DP_PLZ_DA();
> >>      someBean.superDuperAction();
> >>  }
> >>
> >> It works and it can find the Entity. But why in gods name do i need to
> >> instantiate the class by myself in order to get detected? During normal
> >> runtime, this is no problem. Kevin Sutter reported something similar
> here (
> >> http://www.ibm.com/developerworks/forums/thread.jspa?messageID=14459507
> )
> >> but i thought i can solve this by upgrading to 1.2.2 but i was mistaken.
> >>
> >> So why does OpenJPA fail on registering Entities?
> >>
> >> ---
> >> regards
> >> Marc Logemann
> >> http://www.logemann.org
> >> http://www.logentis.de
> >>
> >>
> >>
> >>
> >>
>
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message