HHH-15218 Add test for issue
This commit is contained in:
parent
98f52855c1
commit
0a013ed8a4
|
@ -0,0 +1,49 @@
|
|||
package org.hibernate.orm.test.cascade.circle.delete;
|
||||
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.GeneratedValue;
|
||||
import jakarta.persistence.Id;
|
||||
import jakarta.persistence.ManyToOne;
|
||||
|
||||
@Entity
|
||||
public class Address {
|
||||
@Id
|
||||
@GeneratedValue
|
||||
private Long id;
|
||||
|
||||
@ManyToOne
|
||||
private Person person;
|
||||
|
||||
private String description;
|
||||
|
||||
public Address() {
|
||||
}
|
||||
|
||||
public Address(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(final Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public Person getPerson() {
|
||||
return person;
|
||||
}
|
||||
|
||||
public void setPerson(Person person) {
|
||||
this.person = person;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,47 @@
|
|||
package org.hibernate.orm.test.cascade.circle.delete;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
import org.hibernate.testing.orm.junit.DomainModel;
|
||||
import org.hibernate.testing.orm.junit.SessionFactory;
|
||||
import org.hibernate.testing.orm.junit.SessionFactoryScope;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
@DomainModel(
|
||||
annotatedClasses = {
|
||||
Person.class,
|
||||
Address.class
|
||||
}
|
||||
)
|
||||
@SessionFactory
|
||||
@TestForIssue(jiraKey = "HHH-15218")
|
||||
public class CascadeDeleteTest {
|
||||
|
||||
@BeforeEach
|
||||
public void setUp(SessionFactoryScope scope) {
|
||||
scope.inTransaction(
|
||||
session -> {
|
||||
Person person = new Person();
|
||||
|
||||
Address currentAddress = new Address( "Localita S. Egidio Gradoli (VT)" );
|
||||
person.addCurrentAddress( currentAddress );
|
||||
|
||||
session.persist( person );
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDelete(SessionFactoryScope scope) {
|
||||
scope.inTransaction(
|
||||
session -> {
|
||||
List<Person> people = session.createSelectionQuery( "from Person", Person.class ).list();
|
||||
people.forEach( person -> {
|
||||
session.remove( person );
|
||||
} );
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,65 @@
|
|||
package org.hibernate.orm.test.cascade.circle.delete;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import jakarta.persistence.CascadeType;
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.GeneratedValue;
|
||||
import jakarta.persistence.Id;
|
||||
import jakarta.persistence.OneToMany;
|
||||
import jakarta.persistence.OneToOne;
|
||||
|
||||
import org.hibernate.annotations.DynamicUpdate;
|
||||
import org.hibernate.annotations.OptimisticLockType;
|
||||
import org.hibernate.annotations.OptimisticLocking;
|
||||
|
||||
@Entity
|
||||
@OptimisticLocking(type = OptimisticLockType.DIRTY)
|
||||
@DynamicUpdate
|
||||
public class Person {
|
||||
@Id
|
||||
@GeneratedValue
|
||||
private Long id;
|
||||
|
||||
private String name;
|
||||
|
||||
@OneToMany(cascade = CascadeType.ALL, mappedBy = "person")
|
||||
private final List<Address> addresses = new ArrayList<>();
|
||||
|
||||
@OneToOne(cascade = { CascadeType.ALL })
|
||||
private Address currentAddress;
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(final Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public List<Address> getAddresses() {
|
||||
return addresses;
|
||||
}
|
||||
|
||||
public Address getCurrentAddress() {
|
||||
return currentAddress;
|
||||
}
|
||||
|
||||
public void setCurrentAddress(Address currentAddress) {
|
||||
this.currentAddress = currentAddress;
|
||||
}
|
||||
|
||||
public void addCurrentAddress(Address currentAddress){
|
||||
this.addresses.add( currentAddress );
|
||||
currentAddress.setPerson( this );
|
||||
this.currentAddress = currentAddress;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue