0

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!

1
  • Change org.hibernate.mapping.List to java.util.List in your Resource class. Commented Jun 12, 2015 at 12:33

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Yep, that was it. I got thrown by the fact that none of the examples appear to work that way and that the list() method seemed to want to return org.hibernate.maping.list. Many thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.