Skip to main content

[EclipseLink] Clean JPA database for EJB unit tests

4 replies [Last post]
walec51
Offline
Joined: 2010-03-17

Hello,

Is there any easy way to remove all JPA entities ? (one line soultion would be best :) )

I tried to use the drop-and-create-tables for this but it doesn't form becouse of this bug I reported:

https://glassfish.dev.java.net/issues/show_bug.cgi?id=11727

Is there any way to do this by using EclipseLinks API ?

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
gyorke
Offline
Joined: 2005-06-21

You can use the built in JPA DDL generation facility to drop and create tables on the creation of an EMF.

youness_teimoury
Offline
Joined: 2010-02-23

Though I think I have tested it before and works fine, as an alternative, you can drop all tables when your unit test starts. Do it by writing a simple JPQL query and executing the query at @BeforeClass method in your unit test class.
Youness

walec51
Offline
Joined: 2010-03-17

Is there a TRUN DATABASE statement in JPA ?

Because doing a sequence of

DELETE FROM EntityCass1
DELETE FROM EntityCass2
...

is an issue form me as I would have to null'fy a large number circular references first in my schema.

youness_teimoury
Offline
Joined: 2010-02-23

Use Drop Table command instead. The next alternative is to delete derby database completely each time.
By default it is created in [Java User Home\Dir]\sun-appserv-samples folder.
Youness