Hi, Andrea, I oversimplified the test case when I initially reported this bug. I apologize for my mistake. The missing piece is the Agency object. The object hierarchy is like this: each Agency can have 0 or more Users, and each User must belong to an Agency and each user can have 0 or more roles. Here is the Agency table: AGENCY table: Columns: AGENCY_ID integer not null primary key, AGENCY_NAME varchar(256) not null, Rows: (100, 'Test Agency'); USER table (add the AGENCY_ID column): Columns: USER_ID integer not null primary key, USER_NAME varchar(256) not null, AGENCY_ID integer not null, Rows: (1, 'Ann', 100); (2, 'Bob', 100); Here is the Agency entity bean:
@Entity@Table(name = "AGENCY", schema = "TEST")
public class Agency {
private Integer agencyId = null;
private String agencyName = null;
private Set<User> users;
@Id
@Column(name = "AGENCY_ID")
public Integer getAgencyId() {
return agencyId; }
public void setAgencyId(Integer roleId) {
this.agencyId = roleId; }
@Column(name = "AGENCY_NAME")
public String getAgencyName() {
return agencyName; }
public void setAgencyName(String roleName) {
this.agencyName = roleName; }
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER, mappedBy = "agency")
@Fetch(FetchMode.SELECT)
public Set<User> getUsers() {
return users; }
public void setUsers(Set<User> users) {
this.users = users; }
@Override public boolean equals(Object o) {
if (this == o) {
return true; }
if (o == null || getClass() != o.getClass()) {
return false; }
Agency that = (Agency) o;
return Objects.equals(agencyId, that.agencyId) && Objects.equals(agencyName, that.agencyName); }
@Override public int hashCode() {
return Objects.hash(agencyId, agencyName); }
Here are the updated User entity bean:
@Entity@Table(name = "USER", schema = "TEST")
public class User {
private Integer userId = null;
private String userName = null;
private Agency agency = null;
private Set<Role> roles = null;
@Id
@Column(name = "CRIS_USER_ID")
public Integer getUserId() {
return userId; }
public void setUserId(Integer userId) {
this.userId = userId; }
@Column(name = "IDP_USER_ID")
public String getUserName() {
return userName; }
public void setUserName(String userName) {
this.userName = userName; }
@ManyToOne
@JoinColumn(name = "AGENCY_ID")
public Agency getAgency() {
return agency; }
public void setAgency(Agency agency) {
this.agency = agency; }
@ManyToMany(cascade = CascadeType.PERSIST, fetch = FetchType.EAGER)
@JoinTable(
name = "UM_USER_ROLE",
joinColumns = @JoinColumn(name = "CRIS_USER_ID"),
inverseJoinColumns = @JoinColumn(name = "ROLE_ID"))
@Fetch(FetchMode.SUBSELECT)
public Set<Role> getRoles() {
return roles; }
public void setRoles(Set<Role> roles) {
this.roles = roles; }
I am able to reproduce the reported java.lang.NullPointerException. |