Using truncate table alongside Hibernate?
Posted
by Marcus
on Stack Overflow
See other posts from Stack Overflow
or by Marcus
Published on 2010-05-25T16:58:29Z
Indexed on
2010/05/25
17:01 UTC
Read the original article
Hit count: 729
Is it OK to truncate tables while at the same time using Hibernate to insert data?
We parse a big XML file with many relationships into Hibernate POJO's and persist to the DB.
We are now planning on purging existing data at certain points in time by truncating the tables. Is this OK?
It seems to work fine. We don't use Hibernate's second level cache. One thing I did notice, which is fine, is that when inserting we generate primary keys using Hibernate's @GeneratedValue
where Hibernate just uses a key value one greater than the highest value in the table - and even though we are truncating the tables, Hibernate remembers the prior value and uses prior value + 1 as opposed to starting over at 1. This is fine, just unexpected.
Note that the reason we do truncate as opposed to calling delete()
on the Hibernate POJO's is for speed. We have gazillions of rows of data, and truncate is just so much faster.
© Stack Overflow or respective owner