Reputation: 835
I have a Entity that represents a resource and I save it to the database with hibernate. Now i have users and I want another table that determines whether or not a user has access to the resource. The users are not saved in the database.
In normal SQL i would just have a second table where a line with the resourceid and userid means that the user has access to the resource. But Hibernate seems to make this task really complicated and I cannot figure out what a good way to do this would be.
Upvotes: 0
Views: 105
Reputation: 98
I don't understand ,,The users are not saved in the database."Why? But it is like in SQL
import javax.persistence.*;
@Entity
@Table(name="UserResource")
public class UserResource {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private int id;
@ManyToOne
private Resource resource;
@ManyToOne
private User user;
}
Upvotes: 2