Java Unit Test re-create the Tables from Entities

View: New views
3 Messages — Rating Filter:   Alert me  

Java Unit Test re-create the Tables from Entities

by RogerV :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi

I've created a new dynamic web-project in Eclipse Galileo and added Persistence & EclipseLink to it - rather than create two projects - a JPA Project and a Web Project and including the JPA project as a dependancy of the Web project. I've defined some entities (persistence.xml ddl-generation set to "drop-and-create-tables") and used the Dali tools to create Tables from Entities - and written the code to pre-populate some control table entries via EclipseLink.

However, when I try to run any unit test that accesses the persistence layer, EclipseLink drops the tables and re-creates them and my unit tests fail because the control data is obviously no longer present. Is this because I haven't separated the projects - or have I missed something in the setup?

Regards

Re: Java Unit Test re-create the Tables from Entities

by tware :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Take a look at your persistence.xml.

In the properties section, there are probably some properties that start with
"eclipselink.ddl-generation".  Those are the properties that control whether
EclipseLink tries to drop and create your tables.

-Tom

RogerV wrote:

> Hi
>
> I've created a new dynamic web-project in Eclipse Galileo and added
> Persistence & EclipseLink to it - rather than create two projects - a JPA
> Project and a Web Project and including the JPA project as a dependancy of
> the Web project. I've defined some entities (persistence.xml ddl-generation
> set to "drop-and-create-tables") and used the Dali tools to create Tables
> from Entities - and written the code to pre-populate some control table
> entries via EclipseLink.
>
> However, when I try to run any unit test that accesses the persistence
> layer, EclipseLink drops the tables and re-creates them and my unit tests
> fail because the control data is obviously no longer present. Is this
> because I haven't separated the projects - or have I missed something in the
> setup?
>
> Regards
_______________________________________________
eclipselink-users mailing list
eclipselink-users@...
https://dev.eclipse.org/mailman/listinfo/eclipselink-users

Re: Java Unit Test re-create the Tables from Entities

by mobrien :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Roger,
    Hi, If you don't want to drop existing tables but only create for
non-existent ones  - use "create-tables".
    Otherwise, you will want 2 persistence units - here only one is
configured with ddl-generation set to drop-and-create-tables.
       PU 1 = ddl-generation on, RESOURCE_LOCAL only - use to
create/populate your tables
       PU 2 = ddl-generation off, RESOURCE_LOCAL or JTA

    Check out the following tutorials which demonstrate how to run
EclipseLink on application servers like WebLogic or web container only
servers like Tomcat.  In all cases we use a separate SE JPA project to
create and initially populate the database.  After this the web or ejb
container-managed persistence unit can use the configured schema.

http://wiki.eclipse.org/EclipseLink/Examples/JPA/Tomcat_Web_Tutorial
http://wiki.eclipse.org/EclipseLink/Examples/JPA/WebLogic_Web_Tutorial
http://wiki.eclipse.org/EclipseLink/Examples/JPA#Tutorials

An example of [PU 1] - an SE JPA project to prep the database for the
tutorials
http://dev.eclipse.org/svnroot/rt/org.eclipse.persistence/trunk/examples/org.eclipse.persistence.example.jpa.server.common.ddlgen/
http://dev.eclipse.org/svnroot/rt/org.eclipse.persistence/trunk/examples/org.eclipse.persistence.example.jpa.server.common.ddlgen/src/META-INF/persistence.xml

An example of [PU 2] - container managed JTA based
http://dev.eclipse.org/svnroot/rt/org.eclipse.persistence/trunk/examples/org.eclipse.persistence.example.jpa.server.weblogic.enterpriseEJB/ejbModule/META-INF/persistence.xml

    thank you
    /michael

RogerV wrote:

> Hi
>
> I've created a new dynamic web-project in Eclipse Galileo and added
> Persistence & EclipseLink to it - rather than create two projects - a JPA
> Project and a Web Project and including the JPA project as a dependancy of
> the Web project. I've defined some entities (persistence.xml ddl-generation
> set to "drop-and-create-tables") and used the Dali tools to create Tables
> from Entities - and written the code to pre-populate some control table
> entries via EclipseLink.
>
> However, when I try to run any unit test that accesses the persistence
> layer, EclipseLink drops the tables and re-creates them and my unit tests
> fail because the control data is obviously no longer present. Is this
> because I haven't separated the projects - or have I missed something in the
> setup?
>
> Regards
>  

_______________________________________________
eclipselink-users mailing list
eclipselink-users@...
https://dev.eclipse.org/mailman/listinfo/eclipselink-users