>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 <[email protected]> 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
>
>
>
>
>

Reply via email to