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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T11:54:49+00:00 2026-05-15T11:54:49+00:00

Ok so I’m having bit of a problem with my Hibernate mappings and getting

  • 0

Ok so I’m having bit of a problem with my Hibernate mappings and getting the desired behavior.

Basically what I have is the following Hibernate mapping:

<hibernate-mapping>
    <class name="com.package.Person" table="PERSON" schema="MYSCHEMA" lazy="false">
        <id name="personId" column="PERSON_ID" type="java.lang.Long">
            <generator class="sequence">
                <param name="sequence">PERSON_ID_SEQ</param>
            </generator>
        </id>

        <property name="firstName" type="string" column="FIRST_NAME">
        <property name="lastName" type="string" column="LAST_NAME">
        <property name="age" type="int" column="AGE">

        <set name="skills" table="PERSON_SKILL" cascade="all-delete-orphan">
            <key>
                <column name="PERSON_ID" precision="12" scale="0" not-null="true"/>
            </key>
            <many-to-many column="SKILL_ID" unique="true" class="com.package.Skill"/>
        </set>
    </class>
</hibernate-mapping>


<hibernate-mapping>
    <class name="com.package.Skill" table="SKILL" schema="MYSCHEMA">
        <id name="skillId" column="SKILL_ID" type="java.lang.Long">
            <generator class="sequence">
                <param name="sequence">SKILL_ID_SEQ</param>
            </generator>
        </id>
        <property name="description" type="string" column="DESCRIPTION">
    </class>
</hibernate-mapping>

So lets assume that I have already populated the Skill table with some skills in it. Now when I create a new Person I want to associate them with a set of skills that already exist in the skill table by just setting the ID of the skill. For example:

Person p = new Person();
p.setFirstName("John");
p.setLastName("Doe");
p.setAge(55);

//Skill with id=2 is already in the skill table
Skill s = new Skill()
s.setSkillId(2L);

p.setSkills(new HashSet<Skill>(Arrays.asList(s)));
PersonDao.saveOrUpdate(p);

If I try to do that however I get an error saying:

WARN (org.slf4j.impl.JCLLoggerAdapter:357) - SQL Error: 1407, SQLState: 72000
ERROR (org.slf4j.impl.JCLLoggerAdapter:454) - ORA-01407: cannot update ("MYSCHEMA"."SKILL"."DESCRIPTION") to NULL

ERROR (org.slf4j.impl.JCLLoggerAdapter:532) - Could not synchronize database state with session
org.hibernate.exception.GenericJDBCException: Could not execute JDBC batch update

The reason I am getting this error I think is because Hibernate sees that the Skill with Id 2 has ‘updated’ its description to null (since I never set it) and tries to update it. But I don’t want Hibernate to update this. What I want it to do is insert the new Person p and insert a record into the join table, PERSON_SKILL, that matches p with the skill in the SKILL table with id=2 without touching the SKILL table.

Is there anyway to achieve this behavior?

  • 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-15T11:54:50+00:00Added an answer on May 15, 2026 at 11:54 am

    Instead of creating the Skill object yourself:

    //Skill with id=2 is already in the skill table
    Skill s = new Skill()
    s.setSkillId(2L);
    p.setSkills(new HashSet<Skill>(Arrays.asList(s)));
    

    You should be retrieving it from the Hibernate Session:

    Skill s = (Skill) session.get(Skill.class, 2L);
    p.setSkills(new HashSet<Skill>(Arrays.asList(s)));
    

    This way the Session thinks that the skill contained in p.skills is persistent, and not transient.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I have just tried to save a simple *.rtf file with some websites and
I have a small JavaScript validation script that validates inputs based on Regex. I
I have a jquery bug and I've been looking for hours now, I can't
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have a French site that I want to parse, but am running into

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.