Puhong You (
https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=557058%...
) *commented* on HHH-15453 (
https://hibernate.atlassian.net/browse/HHH-15453?atlOrigin=eyJpIjoiY2MyMW...
)
Re: java.lang.NullPointerException: Cannot invoke
"org.hibernate.engine.spi.EntityEntry.getEntityKey()" because
"ownerEntry" is null (
https://hibernate.atlassian.net/browse/HHH-15453?atlOrigin=eyJpIjoiY2MyMW...
)
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.
(
https://hibernate.atlassian.net/browse/HHH-15453#add-comment?atlOrigin=ey...
) Add Comment (
https://hibernate.atlassian.net/browse/HHH-15453#add-comment?atlOrigin=ey...
)
Get Jira notifications on your phone! Download the Jira Cloud app for Android (
https://play.google.com/store/apps/details?id=com.atlassian.android.jira....
) or iOS (
https://itunes.apple.com/app/apple-store/id1006972087?pt=696495&ct=Em...
) This message was sent by Atlassian Jira (v1001.0.0-SNAPSHOT#100205- sha1:6417f3f )