简体   繁体   中英

Delete/Remove entities with JPA- remain in database

My JPA entity:

@Entity
public class Test implements Serializable {

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private long id;

    @Lob
    public byte[] data;

}

Now, let's say I store 100 entries in my database and each entry contains 3 MB.

SELECT x FROM Test x returns 100 entries and the database (on the file system) has a size of about 300 MB (as expected).

The next step is deleting all 100 entries by calling: entityManager.remove(test) for each entry.

SELECT x FROM Test x now results in an empty table, BUT the database still has got a size of 300 MB! First if I drop the table, the database will shrink to the initial state.

What's going wrong here? If I delete entries, they won't really get removed?!

I tried with JavaDB and Oracle XE and I'am using EclipseLink.

For me I will see whether the JPA transaction was committed successfully and select entity counts from database console to double check.

If table records not really gone it means you might have some trouble deleting the records. Try commit trasnaction or flush it.

If the table records already gone but database disk space remains occurred, means it might be becoz of the database space associate management policies, then check your database configuration see how to get the space released once records are gone.

The database does not delete the data physically (obviously). When and how this is done depends on the database and its setup, eg it could be triggered by certain file size thresholds, manual compact commands or scheduled maintance tasks. This is completely independent of JPA.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM