javajpajpa-buddy

How can I auto create the associative (or junction) table in many-to-many relationship using JPA Buddy


I am using the JPA Buddy plugin in IntelliJ, and I want to quickly create sql script (MySQL) from the entity class of Student and Course (many-to-many relationship).

I have successfully created the course and student table, but look like JPA Buddy does not have the option to create the associative (junction) table "student_course" (as showed in picture below)? Can JPA Buddy create the associative (junction) table in many-to-many relationship? create table in jpa buddy

Student and Course class for code references:

Student.java

@Table(name = "student")
@Entity
@Getter
@Setter
public class Student {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "id", nullable = false)
    private Long id;

    @Column(name = "name")
    private String name;

    @ManyToMany
    @JoinTable(name = "student_course",
            joinColumns = @JoinColumn(name = "student_id"),
            inverseJoinColumns = @JoinColumn(name = "courses_id"))
    private Set<Course> courses;
}

Course.java

import lombok.Getter;
import lombok.Setter;

import javax.persistence.*;
import java.util.Set;

@Table(name = "course")
@Entity
@Getter
@Setter
public class Course {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "id", nullable = false)
    private Long id;

    @Column(name = "name")
    private String name;

    @ManyToMany(mappedBy = "courses")
    private Set<Student> students;
}

Solution

  • Thanks for reporting! JPAB-1448 и JPAB-1469 tickets were closed and it works since the 2022.1.0 version of JPA Buddy