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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T01:06:16+00:00 2026-06-18T01:06:16+00:00

I am pretty new to Hibernate. I am having problem understanding these simple logics.

  • 0

I am pretty new to Hibernate. I am having problem understanding these simple logics. I have understood that @Repository is used by Spring for accessing objects. Also, Hibernate uses @Entity to denote entities which are mapped into database tables. I was just wondering if a single class can be annotated with both @Repository and @Entity as they more or less imply the same.

  • 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-06-18T01:06:17+00:00Added an answer on June 18, 2026 at 1:06 am

    NO.

    Hibernate entities are managed by Hibernate ORM framework, they(and their proxies) are created by hibernate when you access them via get() or load(). They have a completely different (and complex) lifecycle than the Spring beans(they can be attached/detached/proxied/pending for removal)

    Spring repositories are singletons, managed by Spring framework. Typically they exist as long as the container instance exists. New Hibernate sessions may be opened and closed, new user sessions engaged and then expired, but there still will be the same singleton instances of repositories.

    Please see http://docs.jboss.org/hibernate/orm/3.3/reference/en/html/objectstate.html#objectstate-overview for the possible hibernate object states.

    As for the repository instances – typically they are stateless, as they are services.

    RE: they more or less imply the same. No they are not the same. There was an old joke

    How many C++ programmers does it take to change a light bulb? You’re
    still thinking procedurally. A properly designed light bulb object
    would inherit a change method from a generic light bulb class, so all
    you would have to do is send a light-bulb-change message.

    But good OOP programmers do not think that way, according to single responsibility principle objects should should have a single reason to change. Repository works with the infrastructure and has nothing to do with the business rules. Infrastructure may change(you may need for example to store you object in XML instead of RDBMS), but this should not affect the classes encapsulating the state of business objects.

    You can possibly mitigate this problem by making a reference from the entity class to an abstract repository interface(implement an infamous Active Record pattern – it will be like referencing some abstract bulb socket from the bulb, this does not seem to be a good solution because bulb sockets and bulbs have different lifecycles).

    That is where High Cohesion principle starts to play, according to which it’s just illogical for an object, whose role is to reflect the abstractions from the model, to perform some completely unrelated things like persistence or transmitting over the network. It’s weird when Student class will have print(), saveToXml() or transmitByHttp() methods.

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

Sidebar

Related Questions

I'm pretty new to Hibernate. In my situation I have a concrete table with
I'm pretty new to NHibernate and am having a problem getting this kind of
I am pretty new to automapping through have used nhibernate mapping earlier. This is
I have a repository class that defines some basic Get/Save/Delete methods. Inside these, I
I'm pretty new to NHibernate. I have working many to many mappings. they look
Pretty new to MVC and the like. I have a class the looks like
I'm still pretty new to ObjC. I noticed that it's pretty standard everywhere to
I'm pretty new to PHP, but I decided to try and make a simple
I'm pretty new with hibernate, and I'm trying to transform a JDBC project I
Please help me with this hibernate problem, I'm new to hibernate and still trying

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.