Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6974451
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T17:14:20+00:00 2026-05-27T17:14:20+00:00

Is it possible to avoid cast warnings after using createQuery().list? //Type safety: The expression

  • 0

Is it possible to avoid cast warnings after using createQuery().list?

//Type safety: The expression of type List needs unchecked conversion to conform to List<User>
List<User> user = (List<User>) session.createQuery("select u from User u").list();

I expected to find a method that specified the target object via generic parameter or method parameter such as the following:

List<User> user = session.createQuery("select u from User u").list(User.class);
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T17:14:21+00:00Added an answer on May 27, 2026 at 5:14 pm

    The most important thing to remember is that warnings are due to your compiler, not hibernate – you can tell your compiler to ignore unimplemented generics. By using HQL, we are querying for data in a type safe way that, unfortunately, java does not have the ability to verify.

    There are a lot of ways to get around the syntactical ugliness of hibernate casting , like :

    1) use @suppressWarnings where casting or

    2) use the Collections.checkedList method to create the new list.

    See also : How to avoid type safety warnings with Hibernate HQL results?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Eclipse is giving me a warning of the following form: Type safety: Unchecked cast
Is it possible to avoid list property tags when serializing? //[Serializable()] - removed, unnecessary
Is it possible to avoid the automatic collapse of a Silverlight ComboBox after LostFocus?
I'm trying to avoid using Interface Builder as much as possible. At the moment
Is it possible to avoid deploying the artifact that is built according to the
Is it possible to avoid the more tab to show up in my tab-based
Just an academical question: Is it possible to avoid int casting when comparing Enum
I would like to avoid redistributing .NET runtime if possible with my application since
Is it possible to avoid having to put DLLs in the same directory as
I do not believe that it is possible to completely avoid C-style casts when

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.