Reputation: 71
I am new to both Java and Hibernate. I am following the most rudimentary examples for doing a query with criteria that I find in the Hibernate documentation and a number of tutorials. With this code:
public void simpleQuery()
{
Criteria criteria = sessionFactory.getCurrentSession().createCriteria(Resource.class);
criteria.add(Restrictions.eq("Name","NTO"));
List result = criteria.list();
}
I get the following error:
Error:(30, 44) java: incompatible types: java.util.List cannot be converted to org.hibernate.mapping.List
Resource is a plain Hibernate entity. I generated it with hbm2java and have used it successfully in a unit test to insert into the corresponding teable.
I have tried
List<Object> result = criteria.list();
but that also results in a cast exception.
I am working in IntelliJ 14.1.3 with JDK 1.8.
Thanks for your help!
Upvotes: 0
Views: 1195
Reputation: 691635
You have incorrect imports at the top of the class. Replace
import org.hibernate.mapping.List;
by
import java.util.List
And don't use raw types. Use List<Resource>
and not List
, since your query is supposed to return a list of instances of Resource.
Upvotes: 1