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

  • Home
  • SEARCH
  • 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 46405
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T15:57:39+00:00 2026-05-10T15:57:39+00:00

For example I have such query: Query q = sess.createQuery(from Cat cat); List cats

  • 0

For example I have such query:

Query q = sess.createQuery('from Cat cat'); List cats = q.list(); 

If I try to make something like this it shows the following warning

Type safety: The expression of type List needs unchecked conversion to conform to List<Cat>   List<Cat> cats = q.list(); 

Is there a way to avoid it?

  • 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. 2026-05-10T15:57:39+00:00Added an answer on May 10, 2026 at 3:57 pm

    Using @SuppressWarnings everywhere, as suggested, is a good way to do it, though it does involve a bit of finger typing each time you call q.list().

    There are two other techniques I’d suggest:

    Write a cast-helper

    Simply refactor all your @SuppressWarnings into one place:

    List<Cat> cats = MyHibernateUtils.listAndCast(q);  ...  public static <T> List<T> listAndCast(Query q) {     @SuppressWarnings('unchecked')     List list = q.list();     return list; } 

    Prevent Eclipse from generating warnings for unavoidable problems

    In Eclipse, go to Window>Preferences>Java>Compiler>Errors/Warnings and under Generic type, select the checkbox Ignore unavoidable generic type problems due to raw APIs

    This will turn off unnecessary warnings for similar problems like the one described above which are unavoidable.

    Some comments:

    • I chose to pass in the Query instead of the result of q.list() because that way this ‘cheating’ method can only be used to cheat with Hibernate, and not for cheating any List in general.
    • You could add similar methods for .iterate() etc.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Say that I have LINQ query such as: var authors = from x in
I have a query that searches for clients using like with wildcard. For example:
I have found this example on StackOverflow: var people = new List<Person> { new
For example I have a simple class like public class Person{ public int Age
For example, I have a model Posts and Comments. Post.objects.annotate(Count('comment')) I am making such
I am new to php. I want to have a form such as this:
I have rows such as [ISSUE] This is a sample issue [WEBSITE] A bug
I'm having difficuly mapping a simple T-SQL query such as this select min(price) as
I have a very specific LINQ query. I would like to check the existence
I'm using the Silverlight UnitTest framerwork does anyone have a good example have how

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.