java - JPA : Additional fields in @JoinTable -


I'm trying to create a one-to-many relationship with @JoinTable . The code works and what it does, but, is there a way to add more columns to the table joining? It is in areas such as creating a business application that will need some sort of history, so I add_user , update_user , timestamp in / update Will the join table be a great way to do this with Java, while adding additional fields through changing tables? If there is, how can that data be edited beautifully, I say that I should add new relationships, how will the value of the mentioned areas be changed? I say elegant , because you can always do something ugly, what are you doing in this case - to make the connection, the update of the relationship based on both ID , I'm interested in it so beautiful, more like a way to go, the way

code for both organizations:

  @Entity @Table (name = "those") public class user {int id; String user name; Private listing & lt; Jobs & gt; Jobs; @OneToMany @JoinTable (name = "users_jobs_rel", joinColumns = @JoinColumn (name = "user_id", referencedColumnName = "user_id"), inverseJoinColumns = @JoinColumn (name = "job_id", referencedColumnName = "job_id")) from the public list & Lt; Jobs & gt; GetJobs () {Return Jobs; } Public Zero Setjobs (List & Jobs> Jobs> Jobs) {this.jobs = jobs; } @ Id @ generated value (strategy = Id) @ Column (name = "Ughr_aidi" unique = true, tap qualified = false) public Attiaiaiaidi () {return id; } Public Zero setId (int id) {this.id = id; } Public string getUsername () {back username; } Public Zero Set USUN (String Username) {this.username = Username; }} @ Entity @Table (name = "jobs") Public Class Jobs {int id; String title; @ManyToOne personal user user; @ Id @ generated value (strategy = Id) @ Column (name = "Naukri_aidi" unique = true, tap qualified = false) public int getId () {return id; } Public Zero setId (int id) {this.id = id; } @column public string getTitle () {return title; } Public Zero Sattitles (String title) {this.title = title; Thanks in advance.   

Usually, when you are using several-to-many You need to create an additional table for this connection, but now, I have no idea why you are using one to many to create a new table (why? It is unnecessary) and yes its answer yes You can join some extra columns in your table with the @JoinColumn annotation. And to pay attention, then you really need bidirectional relationship :) Good luck

Edit:

  There is a beautiful way to do this with Java, shuffle tables Without adding additional fields through?  

What does it mean by 'shuffle'? Do not you give hibernate to make it automatically by using HBM 2LD?


Comments