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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T07:12:17+00:00 2026-05-23T07:12:17+00:00

I have 2 classes like this : Message(id, title, content) MessageEmployee(id, messageId, employeeId, readFlag)

  • 0

I have 2 classes like this :

Message(id, title, content)

MessageEmployee(id, messageId, employeeId, readFlag)

and 2 tables like this :

MESSAGE(mess_id, mess_title, mess_content)

MESSAGE_EMPLOYEE(mess_empl_id, mess_id, empl_id, read_fg)

Mapping files :

    <hibernate-mapping package="core">
        <class name="Message" table="MESSAGE">
            <!-- class id -->
            <id name="id" type="int" column="MESS_ID" length="11">
                <generator class="native"/>
            </id>

            <property name="content" type="string" column="MESS_CONTENT" />
            <property name="title" type="string" column="MESS_TITLE" /> 
        </class>
    </hibernate-mapping>


    <hibernate-mapping package="core">
        <class name="MessageEmployee" table="MESSAGE_EMPLOYEE">
            <!-- class id -->
            <id name="id" type="int" column="MESS_EMPL_ID" length="11">
                <generator class="native"/>
            </id>

            <!-- employee -->
            <many-to-one name="employee" class="core.Employee"
                column="EMPL_ID" cascade="save-update,merge" lazy="false" />

            <!-- message -->
            <many-to-one name="message" class="core.Message"
                column="MESS_ID" cascade="save-update,merge" lazy="false" />

            <property name="readFlag" type="character" column="READ_FG" />      
        </class>
    </hibernate-mapping>

Here is my problem :
let’s say I already have a message in database, and I want to create a messageEmployee and save it.

Code snippet :

    Message sent = new Message(content, title);
    Employee e = employeeDao.loadEmployeeWithId(Integer.valueOf(to));

    messageDao.merge(sent)

    MessageEmployee m = new MessageEmployee(sent, e, null);
    m.setReadFlag('N');
    messageEmployeeDao.mergeMessageEmploye(m);

When I merge(messageEmployee), it creates a new message and a new messageEmployee in database, but I don’t want it to create a new message.

I’m quite sure my mapping is wrong since I am no expert, so what could I change to get the behaviour I want ?

  • 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-23T07:12:18+00:00Added an answer on May 23, 2026 at 7:12 am

    It will create a new Message object because you are not providing id in your message object sent. When you execute messageDao.merge(sent), the sent object doesn’t have and id to merge with. It is pure transient object. Try loading it from database like Employee.

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

Sidebar

Related Questions

I have a number of static classes that contain tables like this: using System;
Let's say I have some classes like this: abstract class View(val writer: XMLStreamWriter) {
I have two classes declared like this: class Object1 { protected ulong guid; protected
I have some classes layed out like this class A { public virtual void
I have trouble when designing classes like this class C1 { public: void foo();
I currently have service classes that look something like this public class UserService :
I have two classes, Foo and Bar, that have constructors like this: class Foo
I have some message elements like this... <span class=error message>Whoops! Don't forget your name.</span>
I have a function like this in one of my classes and then I
I have a DLL made in C#, this DLL contains some clases like Creator.

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.