Hibernate is not persisting the hierarchy when using Inheritance strategy JOINED with Batch size
Description
Activity
Show:
Former user September 6, 2019 at 11:52 PM
@red, this is a duplicate of HHH-12968. I'll use https://hibernate.atlassian.net/browse/HHH-12968#icft=HHH-12968 to backport to 5.3.
Thiago Hora September 4, 2019 at 5:53 AM
But in the case of Mysql, this property is used to make hibernate use the native auto_increment strategy, no?
Former user August 30, 2019 at 8:06 PMEdited
The issue seems to be unique not only to the use of JOINED
inheritance and batch_size
> 1 but also to the use of the legacy ID generation strategy (disabling normal generation using id.new_generator_mappings="false"
). Also found that when several entities are persisted in a transaction all but the final entity seem to be persisted correctly.
Duplicate
Assignee
Reporter
Thiago Hora
Thiago HoraComponents
Priority
Created August 28, 2019 at 9:06 PM
Updated September 6, 2019 at 11:59 PM
Resolved September 6, 2019 at 11:59 PM
Hibernate is not persisting the hierarchy when using Inheritance strategy JOINED and Batch size > 1. It is weird because it prints the SQL in the console, but just the first entity is persisted (the root entity), the other (the child) has the insert printed but nothing happens at database level.
Here are some information regarding the configuration:
configuration.setProperty( AvailableSettings.USE_NEW_ID_GENERATOR_MAPPINGS, "false" ); configuration.setProperty("hibernate.jdbc.batch_size", "20"); configuration.setProperty("hibernate.jdbc.batch_versioned_data", "true"); configuration.setProperty("hibernate.order_inserts", "true"); configuration.setProperty("hibernate.order_updates", "true");
The entities:
// Some comments here @MappedSuperclass public class BaseEntity implements Serializable { @Id @GeneratedValue @Column(name = "id") protected Long id; ... @Entity @Inheritance(strategy = InheritanceType.JOINED) @Table(name = "user") abstract class User extends BaseEntity { private final String type = getClass().getSimpleName(); protected String name; private String firstSurname; ... @Entity @Table(name = "customer") public class Customer extends User { @Column(unique = true) private String facebookId; ... @Entity @Table(name = "user_log") public class UserLog extends BaseEntity { @ManyToOne @JoinColumn(name = "customer_id", nullable = false) private Customer customer; private String text; ...
The test:
@Test public void hhh123Test() throws Exception { // BaseCoreFunctionalTestCase automatically creates the SessionFactory and provides the Session. Session s = openSession(); Transaction tx = s.beginTransaction(); Customer customer = new Customer(); customer.setName("Test"); customer.setFirstSurname("Hibernate"); customer.setEmail("test@test.com"); customer.setFacebookId("2132132132121"); User user = new CreateUserCommand(customer).execute(session); final UserRepo userRepo = new UserRepo(session); customer = userRepo.findById(user.getId()); userRepo.logUserCreation(customer); tx.commit(); s.close(); }
Also, here you will find the link to the test case following the template:
https://github.com/thiagohora/hibernate-test-case-issue-Inheritance-strategy-joined