简体   繁体   中英

Get current object ID in Generic DAO. Hibernate

I want to delete all objects by their IDs in Hibernate Generic Dao implementation.

For now I created method like this:

  @Override
    public void deleteByIds(Collection<Serializable> ids) {
        getSession()
                .createQuery("delete from " + getDomainClass() + " where id in (:ids)")
                .setParameter("ids", ids)
                .executeUpdate();
    }

but id propery in query is undefined. It's mean I can have this method only on entities using @NamedQueries and it impossible to extract this method to Generic DAO?

Assuming id is available in your hibernate entity, you need to change

setParameter("ids", ids)

to

setParameterList("ids", ids)

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