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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T10:42:22+00:00 2026-06-11T10:42:22+00:00

I have an Employee class which has a unidirectional many to many relationship with

  • 0

I have an Employee class which has a unidirectional many to many relationship with Technology class. When I add technologies to Employee and merge the employee, the records are added to the join table.

But, when I try to delete the technologies by merging the employee, the changes do not reflect on the database.

Employee.class

@Entity
@Table(name = "EMPLOYEES")
public class Employee implements Serializable {

    @JoinTable(name = "EMPLOYEES_TECHNOLOGIES",
    joinColumns =
    @JoinColumn(name = "EMP_USERNAME", referencedColumnName = "USERNAME", table = "EMPLOYEES"),
    inverseJoinColumns =
    @JoinColumn(name = "TEC_ID", referencedColumnName = "ID", table = "TECHNOLOGIES"))
    private List<Technology> technologies;

EmployeeEAOImpl.class

@Stateless(name = "EmployeeEAO")
public class EmployeeEAOImpl implements EmployeeEAO {

    @PersistenceContext(unitName = "ManagedITest")
    private EntityManager em;

    @Override
    public void update(Employee employee) {
        if (employee != null) {
            try {
                em.merge(employee);
                em.flush();
            } catch (RuntimeException ex) {
                em.clear();
                throw ex;
            }
        }
    }

Seems pretty standard to me. I checked the generated queries and when I create/update an Employee with technologies I get this:

INSERT INTO EMPLOYEES_TECHNOLOGIES (TEC_ID, EMP_USERNAME) VALUES (?, ?)
    bind => [99, TEST]

But when I delete technologies from Employee and merge, I get either this wrong query:

DELETE FROM EMPLOYEES_TECHNOLOGIES WHERE ((TEC_ID = ?) AND (EMP_USERNAME = ?))
    bind => [99, null]

Or I get an exception:


Exception Description: The attribute [id] of class [be.brail.entities.Employee] is mapped to a primary key column in the database. Updates are not allowed.

This makes me think that the employee is getting created since I’m not altering the ID, so the exception is thrown because the employee with that particular id already exists. At least, that’s what I think.

Why the username parameter in the DELETE query is null, I don’t know. But I’d like to 🙂

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-11T10:42:24+00:00Added an answer on June 11, 2026 at 10:42 am

    It appears that using only entity id’s on the join table fixed it. Not sure why there can’t be references to foreign keys, but it works! It’s a better design anyways since id’s cannot be altered.

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

Sidebar

Related Questions

I have Employee class, which has 3 properties, ID, Name, HireDate. var employees =
I have class Employee which is something like this. class Emp { int EmpID;
I have a Employee class with many attributes. One of the attributes is employeeId
I have a Task object which has a property of Employee. Im trying to
I have a couple of simple objects that have a many-to-many relationship. Django has
I have ViewModel, Which has a ObservableCollection[Employee] EmpCol , now that ViewModel is bind
I have an interface (say Employee) which has 2 classes that implements it (say
I have class which has a method that needs to return three DataTables. I
I have a common superclass (suppose it's Employee ), which has (amongst others) subclasses
I have a simple class which has a static constructor and a instance constructor.

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.