File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Object Relational Mapping and the fly likes [JPA 2.0] Redoploying app deletes my database? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "[JPA 2.0] Redoploying app deletes my database?" Watch "[JPA 2.0] Redoploying app deletes my database?" New topic
Author

[JPA 2.0] Redoploying app deletes my database?

Abdullah Dokuyucu
Greenhorn

Joined: Apr 27, 2010
Posts: 24

Hello all,

I'm using Glassfish v3 as app server, Java EE 6 Web, JSF and EclipseLink (JPA 2.0). My project was working just fine, redeploying was no problem, even if I deleted a table from my database EclipseLink would regenerate it without any hassle. But now when I drop a table from my database it will give me the following error:

com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table 'dkyc.question' doesn't exist

when it used to simply remake the table from the Entity. Also, when I undeploy the application, all my tables get dropped! Redeploying remakes the tables but of course the data is lost then.

If someone can helping in this it would be much appreciated.

My persistence.xml:


And this is the sun-resources.xml


Freelancer for life!
James Sutherland
Ranch Hand

Joined: Oct 01, 2007
Posts: 553
In your persistence.xml you have,

<property name="eclipselink.ddl-generation" value="drop-and-create-tables"/>

This will cause your database to be dropped and re-created when this persistent unit is initialized. If you do not want this, then remove this setting.

EclipseLink will never drop your database on undeploy.

The ddl-generation of "create" should create any missing tables, but this depends on the changes and constraints from existing tables.

What did you change from when it was working?

TopLink : EclipseLink : Book:Java Persistence : Blog:Java Persistence Performance
Abdullah Dokuyucu
Greenhorn

Joined: Apr 27, 2010
Posts: 24

I deleted and remade my persistance units, which didn't seem to affect. I had an unused realm defined on the server, I deleted that. It's back to normal now... I had that realm defined since a while but looks like it messed with my Glassfish-v3 at some point.

I still couldn't figure out what exactly coused it.
Abdullah Dokuyucu
Greenhorn

Joined: Apr 27, 2010
Posts: 24



I have a persistance unit that has table generation strategy as "Create" and a version of it with the "Drop and Create". Now most tables have the Create one and then another one has got

So I cannot use them together?

I think this problem started after I tried to have a third persistence unit that used a different JNDI and Connection pool (which was for another schema). I was trying to have my application persist from 2 different schemas (from same MySQL server though).
James Sutherland
Ranch Hand

Joined: Oct 01, 2007
Posts: 553
If they have different schema/tables it is fine. But if they share the same tables, then one will be dropping the others tables.
 
 
subject: [JPA 2.0] Redoploying app deletes my database?
 
Similar Threads
Problem with schema/postgres
EJB & JPA Unexpected Results
EclipseLink1.1 inserts no data..
javax.persistence. TransactionRequiredException
GF2 JPA Closed Connection