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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T20:07:11+00:00 2026-06-07T20:07:11+00:00

I discovered this problem today and haven’t found any solution yet, I’m kind of

  • 0

I discovered this problem today and haven’t found any solution yet, I’m kind of learning how to use hibernate at this point so I’ll try my best to explain the situation.

I have a this very simple class:

public class Descripcion {
    private long id;
    private String descripcion;
    private AuxTitularidad titularidad = new AuxTitularidad();
    private AuxTitularidad titularidad2 = new AuxTitularidad();

    //getters and setters below... all of them auto-generated
}

And this is my mapping file

<class name="Descripcion" table="DESCRIPCION">
    <id name="id" type="long" column="id">
        <generator class="identity"></generator>
    </id>
    <property name="descripcion" column="descripcion"/>
    <many-to-one name="titularidad" class="AuxTitularidad" column="id_titularidad1"  />
    <many-to-one name="titularidad2" class="AuxTitularidad" column="id_titularidad2"/>
</class>

This mapping worked for me, no problems at all unless “titularidad” and “titularidad2” have the same value (reference the same object). When this happens, hibernate just fetch a single object of the class AuxTitularidad and uses it for both “titularidad” and “titularidad2”.

It shouldn’t be a problem if I was fetching them just for reading, but I need to make the update using an HTML form, and since the instance of “Descripcion” is holding two references to the same instance of “AuxTitularidad”, it just keeps a single value.

Examples:

Number 1: These are the values stored in my DB:

 titularidad: 17
 titularidad2: 23

So I use the HTML form to make the update, and assign them these new values:

 titularidad: 30
 titularidad2: 28

Works!

Number 2: These are the values stored in my DB:

 titularidad: 18
 titularidad2: 18

So I use the HTML form to make the update, and assign them these new values:

 titularidad: 12
 titularidad2: 32

Doesn’t work. It saves this in the DB:

 titularidad: 32
 titularidad2: 32

I’ve checked the binding of the object from the HTML form and it is correct, I know for sure the problem is that both “titularidad” and “titularidad2” hold a reference to the same object (even looked at the ids of the objects). ¿Is there anyway to tell hibernate to get these into separate objects? ¿Some configuration or parameter?

Thanks in advance!

  • 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-07T20:07:13+00:00Added an answer on June 7, 2026 at 8:07 pm

    That’s expected behavior. In a given session, a given entity exists only once.

    If you want to assign another titularidad to your descripcion entity, you shouldn’t modify the fields of the existing titularidads. Instead, you should get a reference to the titularidad you want to assign, and assign this reference:

    Titularidad newTitularidad = session.load(Titularidad.class, newTitularidadId);
    Titularidad newTitularidad2 = session.load(Titularidad.class, newTitularidad2Id);
    descripcion.setTitularidad(newTitularidad);
    descripcion.setTitularidad2(newTitularidad2);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I just discovered this problem today, and I had no idea what caused this
An issue I discover today is similar to this unanswered problem ; though not
This problem was discovered when I tried to run the Android emulator in Eclipse.
This question is already answered. I discovered what the problem is. But, I'm posting
UPDATE & SOLUTION : Everyone, for whoever has this problem in the future, I
I am new to flash, so the solution to this problem may be simple.
I just discovered this component and started working with it. I understand that the
Possible Duplicate: Python or Ruby Interpreter on iOS I just discovered this apps pypad
I am working with zend just recently. I discovered this ViewScript decorator for form
I've seen a plugin for Vim called AutoClose (discovered from this post) which automatically

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.