私は2つのクラスを持っています
GenericDaoWithObjectId.class
public abstract class GenericDaoWithObjectId<T extends IEntity, Z extends Serializable> extends GenericDao<T> {
public Map<Object, T> findByIdsAsMap(List<Object> ids, boolean addNonDeletedConstraint) throws DaoException {
String query = addNonDeletedConstraint ? QUERY_FIND_NON_DELETED_BY_IDS : QUERY_FIND_BY_IDS;
query = query.replaceAll("\\{type\\}", type);
Query q = getSession().createQuery(query);
q.setParameterList("ids", ids);
List<T> entities = (List<T>) q.list();
if (entities.size() != ids.size()) {
throw new DaoException(DaoErrorCodes.OBJECT_NOT_FOUND);
}
Map<Object, T> result = new HashMap<Object, T>(); // I would've done that in query (using SELECT new map(u.id, u), but hibernate has a bug...
// (https://hibernate.onjira.com/browse/HHH-3345)
for (T e : entities) {
result.put(e.getId(), e);
}
return result;
}
}
GenericDao.class
public abstract class GenericDao<T extends IEntity> {
public Map<Long, T> findByIdsAsMap(List<Long> ids, boolean addNonDeletedConstraint) throws DaoException {
String query = addNonDeletedConstraint ? QUERY_FIND_NON_DELETED_BY_IDS : QUERY_FIND_BY_IDS;
query = query.replaceAll("\\{type\\}", type);
Query q = getSession().createQuery(query);
q.setParameterList("ids", ids);
List<T> entities = (List<T>) q.list();
if (entities.size() != ids.size()) {
throw new DaoException(DaoErrorCodes.OBJECT_NOT_FOUND);
}
Map<Long, T> result = new HashMap<Long, T>(); // I would've done that in query (using SELECT new map(u.id, u), but hibernate has a bug...
// (https://hibernate.onjira.com/browse/HHH-3345)
for (T e : entities) {
result.put((Long) e.getId(), e);
}
return result;
}
}
そして、GenericDaoWIthObjectId のメソッドで GenericDao のメソッドをオーバーライド (または単に作成) したいと考えています。問題が発生するのは、JVM を読んでいるときに、それとList<Long>
リスト<Object>
とおそらく同じMap<Long,T>
であると「考える」ためMap<Object,T>
です。どうすればそれを機能させることができますか?