I have 2 entities User and Answer and many-to-many relationship between them:
Code:
@Entity
@Table(name="ANSWERS")
public class Answer implements java.io.Serializable {
@Id @GeneratedValue(strategy=GenerationType.AUTO)
@Column(name="ANSWER_ID")
private Long id;
private String name;
@ManyToOne
@JoinColumn(name="QUESTION_ID")
private
Question question;
@ManyToMany
@JoinColumn(name="USER_ID")
private
List<User> users;
...
Code:
@Entity
@Table(name="USERS")
public class User implements java.io.Serializable {
@OneToMany(mappedBy = "user")
private List<Task> tasks;
@ManyToMany(mappedBy = "users")
private List<Answer> answers;
@Id @GeneratedValue(strategy=GenerationType.AUTO, generator="USERS_ID")
@SequenceGenerator(sequenceName="SQ_USERS_ID", name="USERS_ID")
@TableGenerator(name="USERS_ID")
@Column(name="USER_ID")
private Long id;
@Temporal(value = TemporalType.TIMESTAMP)
@Column(nullable=false, updatable=false)
private Date created = new Date();
@Temporal(value = TemporalType.TIMESTAMP)
private Date updated;
@ManyToMany(mappedBy = "users")
private List<Group> groups;
@Embedded
@Column(nullable=false, unique=true)
private Email email;
@ManyToOne
@JoinColumn(name="ROLE_ID")
private Role role;
...
The task is bulk to insert / update records in db table in efficient way USER_ANSWER(USER_ID, ANSWER_ID) more then 100 records a time.
I have adding / updating of a big amount of records each time for each user.
What efficient way for it can you suggest?
Thx.