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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T22:09:18+00:00 2026-05-10T22:09:18+00:00

We have a Hibernate/Spring application that have the following Spring beans: <bean id=transactionManager class=org.springframework.orm.hibernate3.HibernateTransactionManager

  • 0

We have a Hibernate/Spring application that have the following Spring beans:

<bean id='transactionManager' class='org.springframework.orm.hibernate3.HibernateTransactionManager' /> <bean id='sessionFactory' class='org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean' /> 

When wiring the application together we get the following error when using private constructors in our hibernate entities:

Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: No visible constructors in class 'ourclass' 

The entities are typical domain objects such as an Employee or the like.

When changing the constructor’s visibility modifier to package (or public) the application runs fine and the entities gets stored/loaded in the database. How do we/can we use private constructors/static factory methods with Spring/Hibernate transaction management?

We use Hibernate annotations to map the entities/relationships. No bean definitions are declared in the applicationContext.xml for the domain class that is related to the problem. It is a pojo that should have a static factory method and a private constructor.

How can we make Hibernate (org.springframework.spring-orm.hibernate3 classes i guess) make use of the static factory method instead of the constructor? Or possibly make it call a private constructor if necessary?

Using the spring factory-method configuration would make sense but the entities are not mapped as beans in our applicationContext.xml. They are only annotated with the @Entity annotation for Hibernate persistence.

Hope this edit clearifies (rather than mystifies) the question. 🙂

  • 1 1 Answer
  • 1 View
  • 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-10T22:09:19+00:00Added an answer on May 10, 2026 at 10:09 pm

    While I haven’t used Spring, I have used Hibernate in a project which has classes which must either be instantiated by factory methods or through multiple argument constructors.

    You can do this through an Interceptor, which is a class which listens in to several key hibernate events, such as when an object needs to be instantiated or when an object is loaded.

    To make Hibernate use your own means of instantiating the object, do something like this:

    public class MyInterceptor extends EmptyInterceptor {      public Object instantiate(String entityName, EntityMode entityMode, Serializable id) {         if(entityName.equals(Foo.class.getName())              return Foo.create();         return null;     } } 

    I’m a little suprised that you are having issues with Hibernate not instantiating objects with a non visible constructor, considering that it can be worked around with reflection and I haven’t had that issue in my project (non of the classes actually have visible constructors). It may be something with Spring. Check which version of hibernate you are using as well.

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

Sidebar

Related Questions

In my Spring application (which is deployed on WebLogic server) I have the following
I'm writing a rather simple application that uses GWT, Hibernate and Google Guice (with
I would like to develop a web application in Java/Spring/Hibernate serving as a business
I'm currently writing a tool to plug into an existing enterprise application that uses
Im working on developing a webapplication with MySQL Server 5.1, Spring 3.0.5 and Hibernate
I have written an application which is using NHibernate to provide the underlying object
I have a working knowledge of Struts2 and Spring. I want to develop an
At work we are trying to simplify an application that was coded with an
Long story below short question: How can I get Spring's NamedParameterJDBCTemplate join Hibernate's session?
Is there is anything in the JPA specification that describes what a valid @Embeddable

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.