简体   繁体   中英

Hibernate criteria query error: java.util.List cannot be converted to org.hibernate.mapping.List

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!

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.

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