java - Convert JPA model classes into the MongoDB model class? -
i new mongodb , looking implement below 3 classes in mongodb. have annotated model class @document, not sure how can implement relationship ?
how can implement relationship here ?
authority.java
@entity @table(name = "authority") public class authority { @id @column(name = "id") @generatedvalue(strategy = generationtype.sequence, generator = "authority_seq") @sequencegenerator(name = "authority_seq", sequencename = "authority_seq", allocationsize = 1) private long id; @column(name = "name", length = 50) @notnull @enumerated(enumtype.string) private authorityname name; @manytomany(mappedby = "authorities", fetch = fetchtype.lazy) private list<user> users;
user.java
@entity @table(name = "user") public class user { @id @column(name = "id") @generatedvalue(strategy = generationtype.sequence, generator = "user_seq") @sequencegenerator(name = "user_seq", sequencename = "user_seq", allocationsize = 1) private long id; @column(name = "username", length = 50, unique = true) @notnull @size(min = 4, max = 50) private string username; @column(name = "password", length = 100) @notnull @size(min = 4, max = 100) private string password; @column(name = "firstname", length = 50) @notnull @size(min = 4, max = 50) private string firstname; @column(name = "lastname", length = 50) @notnull @size(min = 4, max = 50) private string lastname; @column(name = "email", length = 50) @notnull @size(min = 4, max = 50) private string email; @column(name = "enabled") @notnull private boolean enabled; @column(name = "lastpasswordresetdate") @temporal(temporaltype.timestamp) @notnull private date lastpasswordresetdate; @manytomany(fetch = fetchtype.eager) @jointable( name = "user_authority", joincolumns = {@joincolumn(name = "user_id", referencedcolumnname = "id")}, inversejoincolumns = {@joincolumn(name = "authority_id", referencedcolumnname = "id")}) private list<authority> authorities;
authorityname.java
public enum authorityname { role_user, role_admin }
Comments
Post a Comment