Is there a function of "drop table" or "delete from table"?


Besides the em.remove() one by one, is there a function of "drop table" or "delete from table"?


Institute of Computer Technologies

You can execute a DELETE query:

    em.createQuery("DELETE FROM MyEntity e").executeUpdate();

This is implemented since version 2.2.4 but the manual has not been updated yet.

ObjectDB Support
ObjectDB - Fast Object Database for Java (JPA/JDO)

Thanks. I never think it is "executeUpdate()", query.getresultlist() cause exceptions.

Yes, you'd better to put it into manual, since "drop table" is often in debugging. I can not find "drop table" in this site BTW.

Institute of Computer Technologies

The code “createQuery("DELETE FROM MyEntity e").executeUpdate();” works, but it can not reset id to zero!

"drop table" or "delete from table" or "truncate" can clear the id counting.

Any idea?

Institute of Computer Technologies

Resetting generated ID sequences is not supported by JPA and JDO.

The following non portable code, however, resets the global sequence IDs:

    javax.jdo.datastore.Sequence sequence =

Assuming you use JPA - you have to use the JDO ability to access sequences. The code above passes a negative allocation request to the allocate method in order to reset the current value. It will work only if the ID is still a 32 bit int value since the allocate methods receives an int value.

"$auto" is the name of the automatic global sequence.

The name of an identity sequence (specific per entity class) is entityName + "$identity".

User defined generators (sequence and table) have explicit names.

ObjectDB Support
ObjectDB - Fast Object Database for Java (JPA/JDO)

I agree, would be really useful to be able to clear a database during testing.

Perhaps, also setting a flag during startup to label the database as 'resettable' too.

Additionally, I was wondering if there is any way to get a list of the entity names in the database?




Clearing the database content is supported since build 2.2.9_05 and there is even a way to label databases as resettable by restricting this risky operation to databases with specified file extensions.

See this forum thread and the explanation of the ;drop connection url parameter in the manual.

About your other question - I will move it to a separate thread. Please follow the posting instructions and use separate threads for unrelated topics. This is essential in order to keep the forum organized and useful to other users.

ObjectDB Support
ObjectDB - Fast Object Database for Java (JPA/JDO)

Post Reply

To post a reply and/or subscribe to update notifications - please login