[JIRA] (HHH-16169) NullPointerException when merging detached collections due to LOG.debugf
by Alina Ricciuti (JIRA)
Alina Ricciuti ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=61fb92a... ) *created* an issue
Hibernate ORM ( https://hibernate.atlassian.net/browse/HHH?atlOrigin=eyJpIjoiMDMxNWIyYTg4... ) / Bug ( https://hibernate.atlassian.net/browse/HHH-16169?atlOrigin=eyJpIjoiMDMxNW... ) HHH-16169 ( https://hibernate.atlassian.net/browse/HHH-16169?atlOrigin=eyJpIjoiMDMxNW... ) NullPointerException when merging detached collections due to LOG.debugf ( https://hibernate.atlassian.net/browse/HHH-16169?atlOrigin=eyJpIjoiMDMxNW... )
Issue Type: Bug Assignee: Unassigned Created: 10/Feb/2023 09:21 AM Environment: Hibernate: 6.1.6, 6.1.7
Postgresql: 11
Spring Data JPA: 3.0.1
Spring Boot: 3.0.2
JDK: Oracle OpenJDK 17.0.2
OS: Windows 11 Priority: Major Reporter: Alina Ricciuti ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=61fb92a... )
I have difficulties migrating my backend application from hibernate 5.4.32 to hibernate 6 due to :
java.lang.NullPointerException: Cannot invoke "org.hibernate.persister.collection.CollectionPersister.getRole()" because "this.loadedPersister" is null
Please find below a simplified datamodel explaining my issue. Note that I am using Lombok / Spring Data.
* Customer having Sales
@Getter
@Setter
@Entity
@Table(name = "CUSTOMER")
@SequenceGenerator(name = "SEQ_CUSTOMER_ID", allocationSize = 10, sequenceName = "SEQ_CUSTOMER_ID")
public class Customer {
@Id
@Column(name = "ID")
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "SEQ_CUSTOMER_ID")
private Long id;
@Column(name = "NAME")
private String name;
@OneToMany(mappedBy = "customer", cascade = CascadeType.ALL, orphanRemoval = true)
private List<Sale> sales = new ArrayList<>();
}
* Sale
@Getter
@Setter
@Entity
@Table(name = "SALE")
@SequenceGenerator(name = "SEQ_SALE_ID", allocationSize = 10, sequenceName = "SEQ_SALE_ID")
public class Sale {
@Id
@Column(name = "ID")
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "SEQ_SALE_ID")
private Long id;
@Column(name = "INDENTIFIER")
private String indentifier;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "ID_CUSTOMER")
private Customer customer;
@OneToMany(mappedBy = "sale", cascade = CascadeType.ALL)
private List<SaleLine> saleLines = new ArrayList<>();
}
* SaleLine
@Data
@ToString(exclude = {"sale"})
@Entity
@Table(name = "SALELINE")
@SequenceGenerator(name = "SEQ_SALELINE_ID", allocationSize = 10, sequenceName = "SEQ_SALELINE_ID")
public class SaleLine {
@Id
@Column(name = "ID")
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "SEQ_SALELINE_ID")
private Long id;
@Column(name = "INDENTIFIER")
private String identifier;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "ID_SALE", nullable = false)
private Sale sale;
}
My unit test is trying to create a customer in 2 steps : first, creating the customer, then adding the sale with a sale line.
@Test
public void add_customer_sale_ko_collection() {
// first creating the customer
Customer customer = new Customer();
customer.setName("Customer Z");
customer = customerRepository.save(customer);
// then adding the sale
Sale sale = new Sale();
sale.setIndentifier("Customer Z sale");
SaleLine saleLine = new SaleLine();
saleLine.setIdentifier("some product sold");
saleLine.setSale(sale);
sale.getSaleLines().add(saleLine);
customer.getSales().add(sale);
sale.setCustomer(customer);
customerRepository.save(customer);
}
The framework throws a NullPointerException when logging the CollectionEntry due to null values. I have attached the full stack. If needed, I cas share my sample project.
( https://hibernate.atlassian.net/browse/HHH-16169#add-comment?atlOrigin=ey... ) Add Comment ( https://hibernate.atlassian.net/browse/HHH-16169#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=EmailN... ) This message was sent by Atlassian Jira (v1001.0.0-SNAPSHOT#100215- sha1:a0f3b6a )
1 year, 11 months