Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

select new constructor in JPA/Hibernate

 
nimo frey
Ranch Hand
Posts: 580
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I have something like this:

List<User> users= (List<User>) entityManager.createQuery("select new com.object.User(...) ...");

This works without problems, when I run the application. But in Eclipse the just-in-time-compiler/debugger tells me an ERROR:

Multiple markers at this line
- Unable to locate class [com.object.User] [select new
ccom.object.User(...)...]

- Type safety: Unchecked cast from List to List<User>

I guess, the compiler complains it, because the User-Object is not a Entity-Object - it s a common Object.
The query is executed well, so Hibernate/JPA can find the com.object.User (Hence, the Reference is right!).
So why does Eclipse says me that this is an error ? How can I switch this particular Error off?

I have the @SuppressWarnings("unchecked") in java.lang,
but I cannot find any @SuppressErrors("unchecked")
(- though it s not an error, as JPA/Hibernate can execute the query well and gives me all my instances of the Object 'User').
 
nimo frey
Ranch Hand
Posts: 580
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have declared the full reference with package-name in my select new-query. Maybe, I should also declare my Object 'User' (which is NOT a Entity!) in the HQL namespace?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic