I am working with Spring 3.2 and Hibernate 4. I am writing the persistence layer access with dao. Here is the dao interface code :
public interface AbstractDao<E, I extends Serializable> {
public E findById(I id);
public void saveOrUpdate(E e);
public void delete(E e);
public List<E> findByCriteria(Criterion criterion);
}
Just after I have written following the abstract class which implements the interface :
public abstract class AbstractDaoImpl<E, I extends Serializable> implements AbstractDao<E,I> {
private Class<E> entityClass;
protected AbstractDaoImpl(Class<E> entityClass) {
this.entityClass = entityClass;
}
@Autowired
private SessionFactory sessionFactory;
public Session getCurrentSession() {
return sessionFactory.getCurrentSession();
}
@Override
public E findById(I id) {
return (E) getCurrentSession().get(entityClass, id);
}
@Override
public void saveOrUpdate(E e) {
getCurrentSession().saveOrUpdate(e);
}
@Override
public void delete(E e) {
getCurrentSession().delete(e);
}
@Override
public List<E> findByCriteria(Criterion criterion) {
Criteria criteria = getCurrentSession().createCriteria(entityClass);
criteria.add(criterion);
return criteria.list();
}
}
I am getting some compilation errors on all methods that i have implemented in the abstract class : findById(I id)
, saveOrUpdate(E e)
, delete(E e)
, findByCriteria(Criterion criterion)
.
The error message is :
Multiple markers at this line
- implements com.startup.app.models.hibernate.dao.AbstractDao.findById
- The method findById(I) of type AbstractDaoImpl must override a superclass method
What wrong, I don't understand. thanks.
Make sure that you are using atleast Java 1.6 inorder to use @Override
in this case.
In Java 1.5, @Override
could only be applied to methods overriding a superclass method.
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.