My database has the following two tables:
Calendar (id, name, user_id)
User (id, name, ...)
Each calendar belongs to one user, each user can have several calendars. Therefore, there is a many-to-one relationship from the Calendar to the User. Now I would like to insert a dataset into my calendar table, my calendar object is as follows:
@Entity @Table(name = "calendar") public class Calendar { @Id @GeneratedValue(generator = "uuid2") @GenericGenerator(name = "uuid2", strategy = "uuid2") @Column(name = "id", columnDefinition = "BINARY(16)") private UUID id; @Column(name = "name") private String name; @ManyToOne @JoinColumn(name = "owner", referencedColumnName = "id") private User owner; ... }
However, when I insert the data set, I know the owner ID, but I do not have the corresponding User
object. Should I get a User
object, set owner
for it, and then insert a dataset?
This sounds a little inconvenient for me, is there a way to insert a dataset using the User
identifier, since it will be stored in the database, as opposed to using the User
object?
source share