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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T09:25:28+00:00 2026-05-26T09:25:28+00:00

i have one doubt, that is when we create one-to-many as bidirectional. we will

  • 0

i have one doubt, that is when we create one-to-many as bidirectional. we will put one parent class reference in child class.

see the code.

Person.java

@Entity
@Table(name="PERSON")
public class Person {
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Column(name="personId")
     private int id;
    @Column(name="personName")
    private String name;
    @OneToMany(cascade =CascadeType.ALL,fetch = FetchType.LAZY)
    @JoinColumn(name="personId") 
    private Set <Address> addresses;
         ....
         ....
}

Address.java

@Entity
@Table(name = "ADDRESS")
public class Address {
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Column(name = "addressId")
    private int id;
    @Column(name = "address",nullable=false)
    private String address;
    @ManyToOne(cascade =CascadeType.ALL)
    @JoinColumn(name="personId",nullable=false)
    private Person person;
           ....
           ....
    }

here Person.java is parent class and Address.java is child class.
when we fetch the parent object from data base it is loading child class. it is fine. no proble.

but in vice versa ie. if we are fetching child class it is also holding parent class (person).

eg: we fetch Address by address id. just assume retrieved 100 address from data base.

but in address class person variable hold the parent(Person) object aslo.

my doubt is here

is use different 100 memory of person. with same data. in Address class. ?

my dao is like this.

public List<Address> getAllAddressByPersonId(int personId) {
        List<Address> addressList =  null;
        try {
            DetachedCriteria criteria = DetachedCriteria.forClass(Address.class);
            criteria.createCriteria("person").add(Restrictions.eq("id", personId));
            addressList = getHibernateTemplate().findByCriteria(criteria);
        } catch (HibernateException e) {
            e.printStackTrace();
        } catch (DataAccessException e) {
            e.printStackTrace();
        }

        return addressList;

just assume the size of addrssList is 100.

like

per =  addressList.get(0).getPerson() , 

per 1 = addressList.get(1).getPerson(),

per2 = addressList.get(2).getPerson(),

....

per99 =  addressList.get(99).getPerson(). 

here per1, per2 …. and per 99 are using same memory or different.

if same it is ok.. else it may cause of any performing issue of more memory utilization.?

help pls…

  • 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-26T09:25:29+00:00Added an answer on May 26, 2026 at 9:25 am

    Hibernate does identity check. One hibernate session contains only single instance of an object with the same ID. So, if per, per1,…per99 is one person, you will have one object for it. Otherwise – different objects.

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

Sidebar

Related Questions

i have a doubt in sessionid. when user visit the site one sessionid will
I want to create custom Textbox control in asp.net.But i have one doubt when
I have one doubt that how to get other control's value when we select
I have one doubt regarding casting. public void Test(out T a, out T b)
I have one doubt in string . How can we acess the memory of
I have one doubt concerning c# method overloading and call resolution. Let's suppose I
In following program . I have one doubt. I have declared one global variable
I have a doubt in layouts.I have designed one layout using group layout using
I have one field that I need to sum lets say named items However
I have one thread that writes results into a Queue. In another thread (GUI),

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.