jackson.databind.ser.BeanSerializer.serialize Error - java

I am in a loop. My classes are dependent on each other, maybe I should have designed it differently, but it was working until recently, until I added #JsonBackReference and #JsonManagedReference to solve an error I got. But now I am getting this error:
at com.fasterxml.jackson.databind.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.java:728) ~[jackson-databind-2.13.3.jar:2.13.3]
at com.fasterxml.jackson.databind.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.java:774) ~[jackson-databind-2.13.3.jar:2.13.3]
at com.fasterxml.jackson.databind.ser.BeanSerializer.serialize(BeanSerializer.java:178) ~[jackson-databind-2.13.3.jar:2.13.3]
I have tried the solutions like adding value to #JsonManagedReference and #JsonBackReference. I added to #JsonIgnore to variables but these did not work.
These are my classes :
#Data
#Entity
public class Auction {
#Id
#GeneratedValue(strategy = GenerationType.IDENTITY)
private int id;
#Column(nullable = false)
private String explanation;
#Column(nullable = false)
private String title;
#Temporal(TemporalType.TIMESTAMP)
#Column(nullable = false)
private Date startDate;
#Temporal(TemporalType.TIMESTAMP)
#Column(nullable = false)
private Date endDate;
private int sellNowPrice;
#Column(nullable = false)
private int startPrice;
//------------------------
#OneToOne(mappedBy = "auction",
cascade = CascadeType.REMOVE)
private FileAttachment fileAttachment;
#OneToOne
private Category category;
#OneToMany(mappedBy = "auction", cascade = CascadeType.MERGE)
#JsonManagedReference(value="selling-item")
private List<Bid> bids;
#ManyToOne(cascade=CascadeType.ALL)
#JoinColumn(name = "creator_id")
#JsonBackReference(value="sell")
private User creator;
#ManyToOne(cascade=CascadeType.ALL)
#JoinColumn(name = "buyer_id")
#JsonBackReference(value="buyer")
private User buyer;
public Auction(AuctionVM auctionVM) {
this.explanation=auctionVM.getExplanation();
this.title=auctionVM.getTitle();
this.startDate=auctionVM.getStartDate();
this.endDate=auctionVM.getEndDate();
this.sellNowPrice=auctionVM.getSellNowPrice();
this.startPrice=auctionVM.getStartPrice();
}
public Auction() {}
}
.
#Data
#Entity
public class User implements UserDetails{
/**
*
*/
private static final long serialVersionUID = -2725432351214985546L;
#Id
#GeneratedValue(strategy = GenerationType.IDENTITY)
private long id;
#NotNull(message="Name can not be null")
#Size(min = 2, max=50, message = "Name must be more than 2 letters ")
#Column(nullable = false)
private String name;
#NotNull(message="Username can not be null")
#UniqueUsername
#Size(min=5,max=100 )
#Column(nullable = false)
private String username;
#NotNull(message="Email can not be null")
#Column(nullable = false)
private String email;
#NotNull(message="Password can not be null")
#Size(min = 4, max=16 , message = "Password must be a minimum of 4 characters and a maximum of 16 characters. ")
#Column(nullable = false)
#JsonIgnore
private String password;
#OneToMany(mappedBy = "buyer")
#JsonManagedReference(value="bidder")
private List<Bid> bids;
#OneToMany(mappedBy = "creator")
#JsonManagedReference(value="sell")
private List<Auction> productsOnSale;
#OneToMany(mappedBy = "buyer")
#JsonManagedReference(value="buyer")
private List<Auction> biddedProducts;
#ManyToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL)
#JoinTable(name = "users_roles",
joinColumns = #JoinColumn(name = "user_id"),
inverseJoinColumns = #JoinColumn(name = "role_id"))
private Collection<Role> roles;
private String image;
private boolean isApproved;
//------------------------------
public User() {
}
public User(UserWithoutRole user) {
this.name = user.getName();
this.email = user.getEmail();
this.username=user.getUsername();
this.image=user.getImage();
}
#Override
public Collection<? extends GrantedAuthority> getAuthorities() {
Collection<Role> roles = getRoles();
List<SimpleGrantedAuthority> authorities = new ArrayList<>();
for (Role role : roles) {
authorities.add(new SimpleGrantedAuthority(role.getName()));
}
return authorities;
}
#Override
#JsonIgnore
public boolean isAccountNonExpired() {
return true;
}
#Override
#JsonIgnore
public boolean isAccountNonLocked() {
return true;
}
#Override
#JsonIgnore
public boolean isCredentialsNonExpired() {
return true;
}
#Override
#JsonIgnore
public boolean isEnabled() {
return true;
}
}
.
#Data
#Entity
public class Bid {
#Id
#GeneratedValue(strategy = GenerationType.IDENTITY)
private int id;
#ManyToOne(cascade=CascadeType.ALL)
#JoinColumn(name = "buyer_id")
#JsonBackReference(value="bidder")
private User buyer;
#ManyToOne(cascade=CascadeType.MERGE)
#JoinColumn(name = "auction_id")
#JsonBackReference(value="selling-item")
private Auction auction;
#Temporal(TemporalType.TIMESTAMP)
#Column(nullable = false)
private Date bidTime;
#NotNull
#Column(nullable = false)
private int price;
}
Where is my mistake idk. If I have to use #JsonIgnore for getters should i delete #Data and where should i use #JsonIgnore. I tried like this but didn't work.
#ManyToOne(cascade=CascadeType.ALL)
#JoinColumn(name = "creator_id")
#JsonBackReference(value="sell")
#JsonIgnore
private User creator;

Related

Spring, Jpa : One To Many Error when the list contains values

I want to return a Profile Object in JSON containing a list of login details associated with a social network.
Everything works correctly when the "reseaux_sociaux" table is empty. For my status table I get my statuses in JSON format in my Profile object. However, when "reseaux_sociaux" contains values then I get the error below and my Profile object in JSON format is not returned...
(Logs)
https://cloudvyzor.com/logpad/?query&database=sandbox-7fb06b2c06f198a7c0e4ff7c74d659e0
Profil Class
#Entity
#Table(name = "Profil")
public class Profil {
#Id
#GeneratedValue(strategy = GenerationType.IDENTITY)
private Long Id;
#ManyToOne(fetch = FetchType.LAZY, optional = false)
#JoinColumn(name = "IdComptes", nullable = false)
private Comptes IdComptes;
private String Avatar;
private String Banniere;
private String Pseudo;
private String MailPro;
private String Bio;
#ManyToMany(cascade = CascadeType.ALL,fetch = FetchType.EAGER)
#JoinTable(name = "Statut_Profil", joinColumns = #JoinColumn(referencedColumnName = "Id"),inverseJoinColumns = #JoinColumn(referencedColumnName ="Id"))
private List<Statut> Statut;
#OneToMany( mappedBy = "IdProfil")
#JsonManagedReference("id_profil")
private List<ReseauxSociaux> Reseaux;
public Profil(){}
public Profil(Long id, Comptes idComptes, String avatar, String banniere, String pseudo, String mailPro, String bio) {
Id = id;
IdComptes = idComptes;
Avatar = avatar;
Banniere = banniere;
Pseudo = pseudo;
MailPro = mailPro;
Bio = bio;
}
}
ReseauxSociaux Class
#Entity
#IdClass(ReseauxId.class)
public class ReseauxSociaux {
#Id
private int Id;
#Id
private Long IdProfil;
#ManyToOne(cascade = CascadeType.ALL)
#JoinColumn(name = "IdProfil", insertable = false, updatable = false)
#JsonBackReference("id_profil")
private Profil Profil;
#ManyToOne
#JoinColumn(name = "Id", insertable = false, updatable = false)
#JsonBackReference("id")
private Reseau Reseau;
private String Identifiant;
private ReseauxSociaux()
{}
public ReseauxSociaux(int id, Long idProfil, String identifiant) {
Id = id;
IdProfil = idProfil;
Identifiant = identifiant;
}
}
Reseau class
#Entity
public class Reseau {
#Id
#GeneratedValue(strategy = GenerationType.IDENTITY)
private int Id;
private String Nom;
private String Couleur;
//I tried it with and without and it made no difference
#OneToMany( mappedBy = "Id")
#JsonManagedReference("id")
private List<ReseauxSociaux> Reseaux;
public Reseau(){}
public Reseau(int id, String nom, String couleur) {
Id = id;
Nom = nom;
Couleur = couleur;
}
//Get Set
}
Profil Controller
#RestController
#RequestMapping("/profil")
public class ProfilController {
private final ProfilRepository profilRepository;
public ProfilController(ProfilRepository profilRepository) {
this.profilRepository = profilRepository;
}
#PostMapping("/getprofil/{idCompte}")
Profil GetProfil(#PathVariable("idCompte") Long idCompte)
{
Profil profil= profilRepository.findProfilById(idCompte);
return profil;
}
}
I finally succeeded... The cause of the problem remains unclear but I have two hypotheses: the first is the use of capital letters on variable names; the second is the use of a list with the onetomany with the same name in two entities.
Profil class
#Entity
#Table(name = "Profil")
public class Profil {
#Id
#GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
#ManyToOne(fetch = FetchType.LAZY, optional = false)
#JoinColumn(name = "idComptes", nullable = false)
#JsonBackReference("id_comptes")
private Comptes idComptes;
private String avatar;
private String banniere;
private String pseudo;
private String mailPro;
private String bio;
#ManyToMany(cascade = CascadeType.ALL,fetch = FetchType.EAGER)
#JoinTable(name = "statut_profil", joinColumns = #JoinColumn(referencedColumnName = "id"),inverseJoinColumns = #JoinColumn(referencedColumnName ="id"))
private List<Statut> statut;
#OneToMany( mappedBy = "idProfil")
#JsonManagedReference("id_profil")
private List<ReseauxSociaux> lstprofil;
public Profil(){}
public Profil(Long id, Comptes idComptes, String avatar, String banniere, String pseudo, String mailPro, String bio) {
this.id = id;
this.idComptes = idComptes;
this.avatar = avatar;
this.banniere = banniere;
this.pseudo = pseudo;
this.mailPro = mailPro;
this.bio = bio;
}
//get set
}
ReseauxSociaux class
#Entity
#IdClass(ReseauxId.class)
public class ReseauxSociaux {
#Id
private int id;
#ManyToOne
#JoinColumn(name = "id", insertable = false, updatable = false)
#JsonBackReference("id_reseau")
private Reseau reseau;
#Id
private Long idProfil;
#ManyToOne
#JoinColumn(name = "idProfil", insertable = false, updatable = false)
#JsonBackReference("id_profil")
private Profil profil;
private String identifiant;
private ReseauxSociaux()
{}
public ReseauxSociaux(int id, Reseau reseau, Long idProfil, String identifiant) {
this.id = id;
this.reseau = reseau;
this.idProfil = idProfil;
this.identifiant = identifiant;
}
}
Reseau class
#Entity
public class Reseau {
#Id
#GeneratedValue(strategy = GenerationType.IDENTITY)
private int id;
private String nom;
private String couleur;
#OneToMany( mappedBy = "id")
#JsonManagedReference("id_reseau")
private List<ReseauxSociaux> lstreseau;
public Reseau(){}
public Reseau(int id, String nom, String couleur) {
this.id = id;
this.nom = nom;
this.couleur = couleur;
}
}

Spring boot write predicate to retrieve user from given role list

I am trying to create a predicate to retrieve users having certain Role list (Role is a separate Table )
I have created predicate for other fields in User entity only unable to create the proper criteria for the above mentioned scenario.
below are the 2 entity classes
User:
#Entity
#Table(name = "user")
#Data
public class User implements Serializable {
public User() {
}
public User(User user) {
this.username = user.getUsername();
this.password = user.getPassword();
this.email = user.getEmail();
this.fullName = user.getFullName();
this.address = user.getAddress();
this.contactNo = user.getContactNo();
this.enabled = user.isEnabled();
this.accountNonExpired = user.isAccountNonExpired();
this.credentialsNonExpired = user.isCredentialsNonExpired();
this.accountNonLocked = user.isAccountNonLocked();
this.roles = user.getRoles();
}
#Id
#GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
#Column(name = "username")
private String username;
#Column(name = "fullName")
private String fullName;
#Column(name = "contactNo")
private String contactNo;
#Column(name = "address")
private String address;
#Column(name = "password")
private String password;
#Column(name = "email")
private String email;
#Column(name = "enabled")
private boolean enabled;
#Column(name = "accountNonExpired")
private boolean accountNonExpired;
#Column(name = "credentialsNonExpired")
private boolean credentialsNonExpired;
#Column(name = "accountNonLocked")
private boolean accountNonLocked;
#ManyToMany(fetch = FetchType.EAGER)
#JoinTable(name = "role_user", joinColumns = {#JoinColumn(name = "user_id", referencedColumnName = "id")},
inverseJoinColumns = {
#JoinColumn(name = "role_id", referencedColumnName = "id")})
private List<Role> roles;
}
Role
#Entity
#Table(name = "role")
#Data
public class Role implements Serializable {
#Id
#GeneratedValue(strategy = GenerationType.AUTO)
private Integer id;
#Column(name = "name")
private String name;
#ManyToMany(fetch = FetchType.EAGER)
#JoinTable(name = "permission_role", joinColumns = {
#JoinColumn(name = "role_id", referencedColumnName = "id")}, inverseJoinColumns = {
#JoinColumn(name = "permission_id", referencedColumnName = "id")})
private List<Permission> permissions;
}
I have to use predicates No other option.
guide me how to write a predicate to get users who are having given Role list.
If you refer to Java 8 Predicate class:
Predicate<User> userPredicate = user -> user.getRoles().equals(roleListArg);
If you want a more complex predicate:
Predicate<User> userPredicate = user -> {
... your code here
};
Take care while comparing List objects like that. Should be better to check if the user has certains roles (user.getRoles().contains(role))
If you refer to JPA Specification:
public Specification<User> getUserByRoles(List<Role> roles) {
return (root, query, criteriaBuilder) => {
Join<Role, User> join = root.join("role");
//Return the condition you want to build, this is an example to get by role id
return criteriaBuilder.in(join.get(id), roles.get(0).getId());
}
}

More than one row with the given identifier was found: 1, for class: mz.co.zonal.models.Product

I'm trying to get All Product into database, it seems well but always i have this error of integrity.
More than one row with the given identifier was found: 1, for class: mz.co.zonal.models.Product; nested exception is org.hibernate.HibernateException: More than one row with the given identifier was found: 1, for class: mz.co.zonal.models.Product
My Classes is
public class Product implements Serializable {
#Id
#GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
#NotNull
private String title;
#NotNull
private String description;
#NotNull
private double price;
#ManyToOne(fetch = FetchType.EAGER)
private Category category;
private boolean sold;
#ManyToOne(fetch = FetchType.EAGER, optional = false)
private Currency currency;
#ManyToOne
#CreatedBy
private User user;
#Nullable
#OneToMany(mappedBy = "product",
cascade = CascadeType.ALL, orphanRemoval = true)
private List<Images> images;
private Date createdDate = new Date();
#OneToMany(fetch = FetchType.LAZY,
cascade = CascadeType.ALL,
mappedBy = "product")
private List<View> view;
#OneToOne(fetch = FetchType.EAGER)
#JoinColumn(name="type_id")
private Type type;
private Long viewCount;
#ManyToOne(fetch=FetchType.EAGER, cascade={CascadeType.ALL})
#JoinColumn(name="brand_id")
private Brand brand;
#Nullable
#OneToMany(mappedBy = "product",
cascade = CascadeType.ALL, orphanRemoval = true)
private List<ProductLikes> productLikes;
#Nullable
#Column
#ElementCollection(targetClass=byte.class)
private List<byte[]> imagesByte;}
#Entity
#JsonIgnoreProperties({"hibernateLazyInitializer", "handler"})
public class Category implements Serializable {
#Id
#GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
#NotNull
private String name;
#NotNull
private String imagePath;
#OneToMany(cascade = CascadeType.ALL,
mappedBy = "category")
#JsonIgnore
private List<Product> product;
#Nullable
private byte[] categoryImage;}
#Entity
public class Currency implements Serializable {
#Id
#GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
#NotNull
private String code;
#NotNull
private String currency;
#NotNull
private String region_country;
#JsonIgnoreProperties({"hibernateLazyInitializer", "handler"})
#OneToMany(mappedBy = "currency", cascade = CascadeType.ALL, fetch = FetchType.LAZY)
#JsonIgnore
private List<Product> products;
}
#Entity
public class ProductLikes {
#Id
#GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private Boolean isLike;
#ManyToOne(fetch = FetchType.LAZY)
#JoinColumn(name = "user_id")
#JsonIgnore
private User user;
#ManyToOne(fetch = FetchType.LAZY, optional = false)
#JoinColumn(name = "product_id", nullable = false)
#JsonIgnore
private Product product;}
#Entity
public class Images implements Serializable {
#Id
#GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private String imagePath;
#JsonIgnore
#ManyToOne(fetch = FetchType.LAZY)
#JoinColumn(name = "product_id")
private Product product;
}
#Entity
public class Type implements Serializable {
#Id
#GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
#NotNull
private String name;
#OneToOne(fetch = FetchType.LAZY,
cascade = CascadeType.ALL,
mappedBy = "type")
#JsonIgnore
private Product product;
}
#Entity
public class User implements UserDetails, Serializable {
#Id
#GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
#NotEmpty
private String fullName;
#NotEmpty
#Email
#Column(unique = true)
private String email;
#NotNull
#Column(unique = true)
private int phoneNumber;
#NotEmpty
#Size(min = 5)
private String password;
private Date createAt = new Date();
#Nullable
private String picPath;
#Nullable
private String token;
#ManyToMany
#JoinTable(name = "user_roles", joinColumns = {#JoinColumn(
name = "user_id")},
inverseJoinColumns = {#JoinColumn(name = "role_id")})
private List<Role> roles;
#OneToOne(fetch = FetchType.EAGER,
cascade = CascadeType.ALL,
mappedBy = "user")
#JsonIgnore
private Product product;
#OneToOne(fetch = FetchType.LAZY,
cascade = CascadeType.ALL,
mappedBy = "user")
private View view;
}
#Entity
public class View implements Serializable {
#Id
#GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
#OneToOne(fetch = FetchType.LAZY, optional = false)
#JoinColumn(name = "user_id", nullable = false)
#JsonIgnore
private User user;
#OneToOne(fetch = FetchType.LAZY, optional = false)
#JoinColumn(name = "product_id", nullable = false)
#JsonIgnore
private Product product;
}
#Entity
public class Brand implements Serializable {
#Id
#GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
#NotNull
private String name;
#OneToMany(fetch=FetchType.EAGER, mappedBy="brand", cascade={CascadeType.ALL})
#JsonIgnore
private List<Product> products;}
I'm not sure if this is the only cause of problems, but you have mapped the relation between Product and Type as 1:1 but the rows in the database both reference the same type_id 1.

Jackson failed to deserialization OneToMany objects

I have faced with the problem that converter can't handle JSON object.
I have two objects in data base. Relationship OneToMany.
I have a AutoService with many services.
And wnen i am trying to send JSON object using postman to my server - I am getting an error:
WARN org.springframework.http.converter.json.MappingJackson2HttpMessageConverter - Failed to evaluate Jackson deserialization for type [[simple type, class com.webserverconfig.user.entity.AutoService]]: java.lang.IllegalArgumentException: Can not handle managed/back reference 'defaultReference': no back reference property found from type [collection type; class java.util.List, contains [simple type, class com.webserverconfig.user.entity.Service]]
Next two classes represents my model:
Class AutoService:
#Entity
#Table(name = "AutoRate")
public class AutoService {
public AutoService() {
}
#Id
#GeneratedValue(generator = "increment")
#GenericGenerator(name = "increment", strategy = "increment")
private long id;
#Column(name = "serviceName", nullable = false)
private String serviceName;
#Column(name = "imageURL", nullable = false)
private String imageURL;
#Column(name = "mapCoordinate", nullable = false)
private String mapCoordinate;
#Column(name = "websiteURL", nullable = false)
private String websiteURL;
#Column(name = "phoneNumber", nullable = false)
private String phoneNumber;
#JsonManagedReference
#OneToMany(fetch = FetchType.EAGER)
#JoinColumn(name = "autoServiceId")
private List<Service> services;
public long getId() {
return id;
}
public String getServiceName() {
return serviceName;
}
public String getImageURL() {
return imageURL;
}
public String getMapCoordinate() {
return mapCoordinate;
}
public String getWebsiteURL() {
return websiteURL;
}
public String getPhoneNumber() {
return phoneNumber;
}
public List<Service> getServices() {
return services;
}
}
Class service:
#Entity
#Table(name = "Service")
public class Service {
public Service() {
}
#Id
#GeneratedValue(generator = "increment")
#GenericGenerator(name = "increment", strategy = "increment")
#Column(name = "serviceId", unique = true, nullable = false)
private long serviceId;
#Column(name = "serviceName", nullable = false)
private String serviceName;
#Column(name = "category", nullable = false)
private String category;
#Column(name = "price", nullable = false)
private int price;
#Column(name = "autoServiceId", nullable = false)
private long autoServiceId;
public long getId() {
return serviceId;
}
public String getCategory() {
return category;
}
public int getPrice() {
return price;
}
public String getServiceName() {
return serviceName;
}
public long getAutoServiceId() {
return autoServiceId;
}
}
Asking for help. Am i missing some annotation ?
Also Controller class:
#RestController
#RequestMapping("/directory")
public class ServiceController {
#Autowired
private AutoRateService dataBaseService;
#RequestMapping(value = "/get", method = RequestMethod.GET)
#ResponseBody
public AutoService getData(){
AutoService dataList = dataBaseService.getById(1);
return dataList;
}
#RequestMapping(value = "/saveService", method = RequestMethod.POST)
#ResponseBody public AutoService saveAutoService(#RequestBody AutoService autoService){
return dataBaseService.save(autoService);
}
}
You could add #JsonBackReference to the other site of the relation. Which by the way is missing or not correct implemented. Add:
#JsonBackReference
#ManyToOne
#JoinColumn(name = "autoServiceId", nullable = false)
private AutoService autoService;
instead of private long autoServiceId;.
Also the AutoService needs to be adjusted with:
#JsonManagedReference
#OneToMany(mappedBy = "autoService", fetch=FetchType.EAGER)
private List<Service> services = new ArrayList<>();
Solution #1 :
- add #JsonIgnore where you have attributes with #OneToMany
Example:
class User {
#OneToMany(mappedBy = "user", fetch = FetchType.LAZY, cascade = CascadeType.ALL)
#JsonManagedReference
#JsonIgnore
private List<Comment> comments;
}
class Comment {
#ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
#JoinColumn(name = "user_id")
#JsonBackReference
private User user;
}
Solution #2:
- use on your class #JsonIgnoreProperties({"name-of-your-attribute"}), for example "comments"

Handle a ternary relationship using Javax annotation and Hibernate

I'm making an application that use a Rest Api to handle the communication between front and database.
Spring is used for the Java Api and Postgres as database.
The point is that I need a ternary relationship between three table. I explain myself, I have three table :
- user
- role
- project
Every user have a specific role depending on the project.
When I select a Project (in front), I need to display all the participants with their respective project.
Those are my classes :
#Entity
#Table(name = "users")
public class User {
#Id
#GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
#NotNull
private String email;
#NotNull
#Column(name = "last_name")
private String lastName;
#NotNull
#Column(name = "first_name")
private String firstName;
#NotNull
private String password;
private String image;
#Entity
#Table(name = "projects")
public class Project {
#Id
#GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
#NotNull
private String name;
#NotNull
private Long version;
#NotNull
private Date date;
#ManyToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
#JoinTable(name = "user_profile_project", joinColumns = #JoinColumn(name = "project_id", referencedColumnName = "id"), inverseJoinColumns = #JoinColumn(name = "user_id", referencedColumnName = "id"))
private List<User> participants;
#Entity
#Table(name = "profiles")
public class Profile {
private Long id;
private String name;
private Set<Permission> permissions = new HashSet<Permission>(0);
public Profile(){}
public Profile(String name) {
this.name = name;
}
public Profile(String name, Set<Permission> permissions) {
this.name = name;
this.permissions = permissions;
}
#Id
#GeneratedValue(strategy = GenerationType.IDENTITY)
#Column(name = "id", unique = true, nullable = false)
public Long getId() {
return this.id;
}
public void setId(Long id) {
this.id = id;
}
#Column(name = "name", nullable = false)
public String getName() {
return this.name;
}
public void setName(String name) {
this.name = name;
}

Categories

Resources