GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Example from Baeldung guide

This view

  • Original page
  • New address

GeezerVison is showing robbmalexander.github.io — robbmalexander.github.io

Web App Security

Many-To-Many

  • In Spring MVC, Many-to-many relationships are established with the annotation @ManyToMany

  • For an SQL database, a join table must be created that includes the respective values used to relate the resources.

  • Within the related Java classes, one will define the join table with @JoinTable annotation and accompanying code block which defines the name of the relational table as well as the respective properties to be included. The class including this annotation with be the joinColumn resource, while the other will be the inverseJoinColumn resource

    • Example from Baeldung guide:

First related class:

@Entity
@Table(name = "Employee")
public class Employee { 
    // ...
 
    @ManyToMany(cascade = { CascadeType.ALL })
    @JoinTable(
        name = "Employee_Project", 
        joinColumns = { @JoinColumn(name = "employee_id") }, 
        inverseJoinColumns = { @JoinColumn(name = "project_id") }
    )
    Set<Project> projects = new HashSet<>();
   
    // standard constructor/getters/setters
}

Second related class:

@Entity
@Table(name = "Project")
public class Project {    
    // ...  
 
    @ManyToMany(mappedBy = "projects")
    private Set<Employee> employees = new HashSet<>();
    
    // standard constructors/getters/setters   
}

###

You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.