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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T21:54:42+00:00 2026-05-27T21:54:42+00:00

Using Hibernate 3.6.8.Final and Spring 3.0.5.RELEASE , I’m trying to add some Common DAO

  • 0

Using Hibernate 3.6.8.Final and Spring 3.0.5.RELEASE , I’m trying to add some Common DAO functionality for classes that have multiple implementations overridden higher up to implement the specific classes however it doesn’t work for DetachedCriteria.

Example:

In base class:

public interface ICat {
    public void setMeowSound(String meow);
    public String getMeowSound();
}

Then each inherited project would define the hibernate annotations.

e.g.

@Entity
@Table(name="SQUAWKY_CATS")
public class SquawkyMeowingCat implements ICat, Serializable {
    @Id
    @Column(name="SQUAWK_NAME")
    private String meow;

    public String getMeowSound() {
        return meow;
    }

    public void setMeowString(String meow) {
        this.meow = meow;
    }
}

This means I can use:

Criteria criteria = Session.createCriteria(ICat.class);

And Spring/Hibernate knows that it pulls the annotations for ICat from the concrete inheritance in the particular project.

However if I try to do:

DetachedCriteria subQuery = DetachedCriteria.forClass(ICat.class,"inner"); // etcetera

then I get an Unknown entity at runtime for ICat.

Now this makes sense as in the first instance is creating it off the Session so it has all the configuration that it needs whereas the DetachedCriteria is a static method however it errors when trying to do the

criteria.list()

by which time it has picked up the Session and should know that ICat is actually a SquawkyMeowingCat which has all the annotations.

So my questions are two part:

1) Is this known behaviour and will be like this forever more?

2) Can anyone think of a simple way around it without using an Interface and concrete ClassHolder which hands back the instance of the class it needs to create?

  • 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-27T21:54:42+00:00Added an answer on May 27, 2026 at 9:54 pm

    I’m not sure about the case of the DetachedCriteria, but one way to avoid explicit dependence on the concrete class might be to query Hibernate’s metadata using the interface:

    public <T> Class<? extends T> findEntityClassForEntityInterface(
        SessionFactory sessionFactory, 
        Class<T> entityInterface
    ) {
        for (ClassMetadata metadata : sessionFactory.getAllClassMetadata().values()) {
            Class entityClass = metadata.getMappedClass(EntityMode.POJO);
            if (entityInterface.isAssignableFrom(entityClass)) {
                return entityClass;
            }
        }
        return null;
    }
    

    With the usual caveats about the robustness of illustrative code spippets.

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

Sidebar

Related Questions

I'm using Hibernate 4.0.1.Final. I'm trying to run a JUnit test on my DAO
I'm using Spring 3.1.0.RELEASE with Hibernate 4.0.1.Final. Although my application functions when I deploy
I'm using Spring 3.1.0.RELEASE, Hibernate 4.0.1.Final, and MySQL 5.1. What is the pooled data
I'm using Hibernate 3.6.7-Final and Spring 3.0.5. I have entity like this @Entity public
We are using Spring MVC 3.0.5.RELEASE with Hibernate 3.5.4-Final without transactions. Every time we
i am using hibernate 3.5.1-Final , with spring 3.0.5.RELEASE and i am using the
We have created a spring web app. using: Spring 3.1.0 Hibernate 3.5.4 final tomcat
Running JBoss 4.2.3.GA and trying to deploy a WAR that is using Spring/Hibernate/JPA. I'm
I have Roo-generated Spring MVC application connected to PostgreSQL using Hibernate. I am trying
I'm using Hibernate 4.0.1.Final. I have a table with a unique constraint column …

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.