小编Ene*_*cio的帖子

Hibernate JPA删除分离的对象

我在服务层中有这些代码:

@Override
public <T extends BaseEntity> T find(Long id, Class<? extends BaseEntity> clazz) throws Exception {
    BaseEntity e = em.find(clazz, id);
    if (e != null) {
        deserialize(e, e.getClass());
    } else
        LOG.error("Found null for id " + id);
    return (T) e;
}

public void delete(BaseEntity e, String index, String type) throws Exception {
    if (e == null)
        return;
    if (e.getId() == null)
        return;
    Delete delete = new Delete.Builder(e.getId().toString()).index(index).type(type).build();
    getJestClient().execute(delete);
    if (em.contains(e)) {
        em.remove(e);
    } else {
        BaseEntity ee = find(e.getId(), e.getClass()); …
Run Code Online (Sandbox Code Playgroud)

java spring hibernate jpa web

3
推荐指数
1
解决办法
3475
查看次数

标签 统计

hibernate ×1

java ×1

jpa ×1

spring ×1

web ×1