0
EntityManager em;
em = this.getEntityManager();
CriteriaBuilder builder = em.getCriteriaBuilder();
CriteriaQuery<Date> criteria = builder.createQuery(Date.class);
Root<News> newsRoot = criteria.from(News.class);
criteria.select(newsRoot.get(News_.date)).distinct(true);
List<Date> newsList = em.createQuery(criteria).getResultList();
return newsList;

The News_.date is not working I don't know why but in other project it's working.

The error is I need to create a class for News_. but before it's working .

Someone encounter this problem?

Lion
  • 18,729
  • 22
  • 80
  • 110
Carlo Adap
  • 69
  • 1
  • 11
  • I don't have that News_ only News – Carlo Adap Jul 09 '13 at 05:36
  • As long as your metamodel class(News_) is set up correctly and is in your classpath it should be fine. Docs on meta-model: http://docs.jboss.org/hibernate/orm/4.0/hem/en-US/html/metamodel.html – Durandal Jul 09 '13 at 05:37
  • 1
    Where are you using `Metamodel`? `News_` refers to a class in Metamodel. – Lion Jul 09 '13 at 05:38
  • 1
    If you don't want to consider `Metamodel` immediately (of course, one must use it for type safe criteria queries), then you can pass a String name of your property in the entity class `News` like, `newsRoot.get("yourDateProperty")`. This will, however be a type unsafe query. – Lion Jul 09 '13 at 05:49
  • Yes I have News_class but can't import it i don't know why – Carlo Adap Jul 09 '13 at 06:28

1 Answers1

1

I have already solved my problem

In AppData and select NetBeans/. metadata - there is a blank .txt file. This file blocks your classes. So When I delete it. I can now access the classes.

Carlo Adap
  • 69
  • 1
  • 11