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 396739
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T16:34:54+00:00 2026-05-12T16:34:54+00:00

In java application I use hibernate criteria queries, for example: Criteria criteria = session.createCriteria(Any.class);

  • 0

In java application I use hibernate criteria queries,
for example:

Criteria criteria = session.createCriteria(Any.class);
...

List<?> list = criteria.list();

and I definetly know that result list contains only objects of type Any but
I don’t know if it’s possible to get list of type defined above?

In this case, if I want to use foreach it’s necessary to convert type from object to type Any

for(Object object : list) {
    ...
    ((Any)object).
    ...
}

Or if I need to get an array I have to do something like this:

list.toArray(new Any[]{});

Do you have any ideas?

  • 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-12T16:34:55+00:00Added an answer on May 12, 2026 at 4:34 pm

    Hibernate does not support generics. So the following code is the “best” you get:

    @SuppressWarnings("unchecked")
    List<Any> resultList = criteria.list();
    
    for(Any any : resultList){ ... }
    

    Maybe

    List<Any> resultList = criteria.list();
    for(Any any : resultList){ ... }
    

    is better as the type warning is still there. This convertion cannot be checked by the compiler. So the warning is ok.

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

Sidebar

Related Questions

I am working on a Java application that will use some Hibernate (annotated by
Using mysql 5.5.2 on windows (Wamp) I'm writing a Java application that use several
I have a Java application that makes heavy use of a large file, to
I am searching for free event sources that I can use within my java-application.
We've got a Spring based web application that makes use of Hibernate to load/store
We have a Hibernate/Spring application that have the following Spring beans: <bean id=transactionManager class=org.springframework.orm.hibernate3.HibernateTransactionManager
Hi I experience a strange phenomena. I have a Java application that queries DB
I have an open source Java application that uses Hibernate and HSQLDB for persistence.
We are using Hibernate with Spring for our Java application. We find out that
I have a Java EE application and I use Hibernate. The domain objects, I

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.