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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T01:35:01+00:00 2026-05-19T01:35:01+00:00

Hi I got a problem with mapping my entities. I’m using JPA2 and Hibernate

  • 0

Hi I got a problem with mapping my entities. I’m using JPA2 and Hibernate implementation. I got tables with @ManyToMany annotation

http://img204.imageshack.us/img204/7558/przykladd.png

I mapped it with :

@Entity
@Table("employee")
class Employee {
      @Id
      @GeneratedValue(strategy = GenerationType.IDENTITY)
      private Integer id;

  @Column
  private String name; 

  @ManyToMany
  @JoinTable(name = "proj_emp",
             joinColumns = @JoinColumn(name = "employee_id", referencedColumnName = "id"),
             inverseJoinColumns = @JoinColumn(name = "project_id", referencedColumnName = "id"), 
             uniqueConstraints = @UniqueConstraint(columnNames = {"employee_id", "project_id"})) 
  private List<Project> projects;                ...}


@Entity
@Table("project")
class Project {
   @Id
   @GeneratedValue(strategy = GenerationType.IDENTITY)
   private Integer id; 

   @Column  
   private String name;    
      
   @Column    
   private Integer budget;        

   @ManyToMany(mappedBy = "projects")     
   private List<Employee> employees;                ...}

Now I would like to have a cascade deleting from table proj_emp when I delete records from Employee, but nothing from table Project can be deleted.

What is the best way to acquire that?

Thanks
Dawid

  • 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-19T01:35:02+00:00Added an answer on May 19, 2026 at 1:35 am

    You can split your @ManyToMany into a @OneToMany-ManyToOne and set up a cascading style as shown here Although the question uses Hibernate’s session, you can use JPA EntityManager. Or use the new JPA feature @ElementCollection (Only JPA 2) to map your joined class. See here how to. Just replace Hibernate’s @CollectionOfElements by @ElementCollection

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

Sidebar

Related Questions

I've got a problem with fluent nhibernate table per class hierarchy mapping. I've got
i got problem with a query, got something like this command.CommandText = SELECT +
everyone I got problem here I need to update a plist data in a
I've got a problem with Symfony2.0 BETA3 and MongoDB. I want create a Document,
I've got a problem I've been going round and round on, and every time
I've just started using Linq and at the moment I've got a database ready
Got a problem here. I'm creating a MAAttachedWindow , then hiding it when a
I got a problem with NERD-commenter. If I <leader>cu the following code: /*function func(arg)
i got some problem with vector of vector. in my program, i have defined
I've got a problem with Zend_Session. I need to know, if the Session for

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.