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

  • Home
  • SEARCH
  • 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 7811213
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T04:04:36+00:00 2026-06-02T04:04:36+00:00

I have a ‘Login’ domain object: public class Login extends AuditEntity { private static

  • 0

I have a ‘Login’ domain object:

public class Login extends AuditEntity {

private static final long serialVersionUID = -309839789761736747L;

private String userName;
private String password;
private Timestamp lastLogin;
private Set customers = new HashSet(0);
private Set addresses = new HashSet(0);

public Set getCustomers() {
    return this.customers;
}

public void setCustomers(Set customers) {
    this.customers = customers;
}

public Set getAddresses() {
    return this.addresses;
}

public void setAddresses(Set addresses) {
    this.addresses = addresses;
}
   //Other setter, getters

Here’s the snippet from hibernate mapping file :

        <set name="customers" fetch="select" lazy="false">
        <key>
            <column name="LoginID" />
        </key>
        <one-to-many class="com.domain.Customer" />
    </set>
    <set name="addresses" fetch="join" lazy="false">
        <key>
            <column name="LoginID" />
        </key>
        <one-to-many class="com.domain.Address" />
    </set>

The Address.hbm.xml mapping for the login reference looks like this :

    <many-to-one name="login" class="com.domain.Login"
        fetch="join" lazy="false">
        <column name="LoginID" />
    </many-to-one>

Here’s my spring test:

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = { "/applicationContext.xml" })
public class LoginDaoTest {

@Autowired
private BaseDao<Login, Integer> loginDao;

@Autowired
private BaseDao<Address, Integer> addressDao;

@Test
public void testLoginDao() {
    Login login = loginDao.load(1);
    Set<Address> addresses = login.getAddresses();

    System.out.println("size Before save..." + addresses.size());

    Address address = new Address();
    address.setCity("Kew gardens");
    address.setCreatedBy("user");
    address.setCreatedDate(new Timestamp(Calendar.getInstance().getTime().getTime()));
    address.setHouseNumber("1-2-3");
    address.setLogin(login);
    address.setLocality("Queens blvd");
    address.setState("NY");
    address.setStreetName("Some Street");
    address.setZipCode("11415");

    addressDao.save(address);

    System.out.println("size After save..." + addresses.size());

}

}

Here’s the output:

size Before save...14
size After save...14

Question/problem I was expecting to see the address set in the login object grow by one after i add a new address since I am not loading lazyly. Why isn’t the size of my set growing? Is it because I am running the queries in the same transaction?

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-06-02T04:04:38+00:00Added an answer on June 2, 2026 at 4:04 am

    You are responsible for maintaining the in-memory state of your objects. Hibernate will not automagically stick that address into the list for you. To write strictly correct code you should add the new address to the list when you create it, so that your in memory state matches what you intend to have persisted.

    You can then use Transitive Persistence to have the new address created, no need to call ‘save’ on the address at all.

    Conceptually it works the other way around from what you are expecting. The purpose of the framework is not to magically ‘bind’ the database onto your objects. It’s to let you use ordinary objects in the same way you would if there were no database (e.g., putting things into the lists they go in them), and have the persisting of your object states happen magically.

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

Sidebar

Related Questions

have next code: class GameTexture { private: LPDIRECT3DTEXTURE9 texture; unsigned char *alphaLayer; UINT width,
Have following setup: MainActivity class - extends activity MyLayout class - extends View Prefs
Have a look at this picture alt text http://www.abbeylegal.com/downloads/2009-04-01/web%20part%20top%20line.jpg Does anyone know what css
Have a SomeLib.pro file that contains: CONFIG += debug TEMPLATE = lib TARGET =
Have someone tried out DeCAL in Delphi 2009? I'm thinking about upgrading from 2007,
Have a matrix report now that has Position, Hours and Wages for a location
Have you ever obfuscated your code before? Are there ever legitimate reasons to do
Have you ever created or encountered a self modifying code in Java? If yes,
Have you ever tried learning a language while on a project? I have, and
have not tested on windows. but in ubuntu when u disconnect from the network,

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.