I have a problem: I can't know, how edit primary key, if this key is a foreign key...
ER:
I want to edit curseId, but I can't...
User.java
Code:
@Entity
@Table(name = "USERS")
public class User implements Serializable
{
@Id
@Column(name = "USER_ID", nullable = false, length = 10)
private String userId;
@Column(name = "NAME_AT_BIRTH", nullable = false)
private String nameAtBirth;
@Column(name = "LAST_NAME", nullable = false)
private String lastName;
@Column(name = "FIRST_NAME", nullable = false)
private String firstName;
@Column(name = "MOTHERS_NAME", nullable = false)
private String mothersName;
@Column(name = "PERM_ADDRESS", nullable = false)
private String permAddress;
@Column(name = "TEMP_ADDRESS")
private String tempAddress;
@Temporal(value = TemporalType.DATE)
@Column(name = "BIRTHDATE", nullable = false, length = 7)
private Date birthdate;
@Column(name = "PASSWORD", nullable = false, length = 32)
private String password;
@Column(name = "EMAIL", length = 320)
private String email;
@Temporal(value = TemporalType.DATE)
@Column(name = "START_DATE", nullable = false, length = 7)
private Date startDate;
@Temporal(value = TemporalType.DATE)
@Column(name = "END_DATE", length = 7)
private Date endDate;
@Column(name = "TYPE", length = 16)
private String type;
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "user")
private List<UserCheck> checks = new ArrayList<UserCheck>();
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "user")
private List<UserCurse> curses = new ArrayList<UserCurse>();
}
Curse.java
Code:
@Entity
@Table(name = "CURSES")
public class Curse implements Serializable
{
@EmbeddedId
@AttributeOverrides(
{
@AttributeOverride(name = "curseId", column = @Column(name = "CURSE_ID", nullable = false, length = 16)),
@AttributeOverride(name = "semesterId", column = @Column(name = "SEMESTER_ID", nullable = false, length = 10))
})
private CurseId id;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "SEMESTER_ID", nullable = false, insertable = false, updatable = false)
private Semester semester;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "ROOM_ID", nullable = true)
private Room room;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "SUBJECT_ID", nullable = false)
private Subject subject;
@Column(name = "TIME", nullable = true, length = 32)
private String time;
@Column(name = "STUDENTS_LIMIT", precision = 10, scale = 0, nullable = true)
private Long studentsLimit;
@OneToOne
@JoinColumns(value =
{
@JoinColumn(name = "CURSE_ID", referencedColumnName = "CURSE_ID", nullable = false, insertable = false, updatable = false),
@JoinColumn(name = "SEMESTER_ID", referencedColumnName = "SEMESTER_ID", nullable = false, insertable = false, updatable = false)
})
private CurseUserCountView curseUserCountView;
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "curse")
private List<UserCurse> users = new ArrayList<UserCurse>();
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "curse")
private List<Check> checks = new ArrayList<Check>();
}
CurseId.java
Code:
@Embeddable
public class CurseId implements Serializable
{
@Column(name = "CURSE_ID", nullable = false, length = 16)
private String curseId;
@Column(name = "SEMESTER_ID", nullable = false, length = 10)
private String semesterId;
}
UserCurse.java
Code:
@Entity
@Table(name = "USERS_CURSES")
public class UserCurse implements Serializable
{
@EmbeddedId
@AttributeOverrides(
{
@AttributeOverride(name = "userId", column = @Column(name = "USER_ID", nullable = false, length = 16)),
@AttributeOverride(name = "curseId", column = @Column(name = "CURSE_ID", nullable = false, length = 16)),
@AttributeOverride(name = "semesterId", column = @Column(name = "SEMESTER_ID", nullable = false, length = 10))
})
private UserCurseId id;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "USER_ID", nullable = false, insertable = false, updatable = false)
private User user;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumns(value =
{
@JoinColumn(name = "CURSE_ID", referencedColumnName = "CURSE_ID", nullable = false, insertable = false, updatable = false),
@JoinColumn(name = "SEMESTER_ID", referencedColumnName = "SEMESTER_ID", nullable = false, insertable = false, updatable = false)
})
private Curse curse;
@Column(name = "PERFORMED", precision = 1, scale = 0)
private Boolean performed;
}
UserCurseId.java
Code:
@Embeddable
public class UserCurseId implements Serializable
{
@Column(name = "USER_ID", nullable = false, length = 16)
private String userId;
@Column(name = "CURSE_ID", nullable = false, length = 16)
private String curseId;
@Column(name = "SEMESTER_ID", nullable = false, length = 10)
private String semesterId;
}
Thanks for helping!