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:
@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 {
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 |