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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T02:03:34+00:00 2026-05-27T02:03:34+00:00

Using hibernate @Any mapping to map multiple entities in the same, I haven’t be

  • 0

Using hibernate @Any mapping to map multiple entities in the same, I haven’t be able to build a request to fetch all the objects of a specific class.

Hibernate doesn’t seem to be capable to handle this kind of request.

My application doesn’t start and throw the following error :

Invocation of init method failed; nested exception is java.lang.ClassCastException: org.hibernate.type.AnyType cannot be cast to org.hibernate.type.ComponentType

removing the part “left join fetch ic.item i” in the request solve this error.

For example, I’ve got the following model:

@Entity
@NamedQueries({
@NamedQuery(name = "GET_ITEMS", query = "from ItemContainer ic left join fetch ic.item i where ic.id=:containerId and ic.class=:clazz")})
public class ItemContainer {
.... 
    @Any(metaColumn = @Column(name = "TYPE"), fetch = FetchType.LAZY)
    @AnyMetaDef(idType = "long", metaType = "string", metaValues = { @MetaValue(targetEntity = Item1.class, value = "I1") })
    @JoinColumn(name = "TYPE_ID")
    private IItem item;
...
}

(with Item1 implements IItem)

And here is my DAO :

@Override
@SuppressWarnings("unchecked")
public List<ItemContainer> getItem1s(final Long containerId) {
return getHibernateTemplate().findByNamedQueryAndNamedParam("GET_ITEMS", new String[] { "containerId", "clazz" },
        new Object[] { containerId, Item1.class });
}

Is it just impossible, or am I missing something ?

Thanks

  • 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-27T02:03:35+00:00Added an answer on May 27, 2026 at 2:03 am

    I had a similar issue, and after much headbanging I discovered that the “class” Hibernate was expecting was a class identifier, in this case the descriminator value.

    So using the above example, the solution was to query the class property as being I1:

    @Override
    @SuppressWarnings("unchecked")
    public List<ItemContainer> getItem1s(final Long containerId) {
    return getHibernateTemplate().findByNamedQueryAndNamedParam("GET_ITEMS", new String[] { "containerId", "clazz" },
            new Object[] { containerId, "I1" });
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using Dozer to map Hibernate entities to their DTOs. A simplified example class
Reverse engineering an existing database to map with N-Hibernate using Fluent N-Hibernate. How can
Build fails with Groovy 1.8, Hibernate JPA annotations I've been stuck using Groovy 1.7.0
I'm trying to map two domain entities to the same table. We're doing a
These are the tables I want to map using Hibernate: user (PK UserId) article
I've got a curious puzzle with an object-relational mapping, using Java and Hibernate. We
I'm using Fluent NHibernate (Auto Mapping) to map my domain objects to database tables.
I am using Hibernate 3.6 with Spring 3.0.5. I have the following mapping for
Am I right that using NHibernate (or any other ORM) removes the necessity of
Does anyone have any good sources of information of using NHibernate with Sql Azure

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.