hibernate - how to insert data in one to many relationship in spring jpa through REST api -


i have 2 entity user , audit insert audit witch associated user' how can insert data in audit through rest api in spring boot when user logging , logout particular information inserted in audit not sure how take particular audit repository. below code

user entity:

@table(name="user") public class user {  @id @generatedvalue(strategy=generationtype.auto) @column(name="userid") private long id;  private string username;  private string email;  private long phone;  private string password;  private int otp;  private boolean activation_flag;  @onetomany(cascade=cascadetype.all) @joincolumn(name="userid") private set<audit> audit;  @manytoone @joincolumn(name="addressid") private address address;  @manytomany(fetch = fetchtype.eager) @jointable(         name = "user_authority",         joincolumns = {@joincolumn(name = "user_id", referencedcolumnname = "userid")},         inversejoincolumns = {@joincolumn(name = "authority_id", referencedcolumnname = "id")}) private list<authority> authorities; 

audit entity:

@entity @table(name="audit") public class audit {  @id @generatedvalue(strategy=generationtype.auto) @column(name="auditid") private long auditid;  @column(name="geolocation") private string geolocation;  @column(name="action") private string action;  @column(name="datetime") private date datetime;  @column(name="deviceid") private long deviceid;  @column(name="actionsuccess_fail") private boolean actionsuccess_fail;  @column(name="jwt_token") @type(type="text") private string jwt_token;  @manytoone private user user; 

the audit repository:

public interface auditrepository extends jparepository<audit, long> { } 

the user repository:

public interface userrepository extends jparepository<user, long> {  user findbyusername(string username); user findbyemail(string email); user findbyphone(long phone); user findbyid(long id);  } 


Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -