|
I ran in to this exact problem as well. We're using Spring Data Jpa 1.4.2.RELEASE (or 1.5.1.RELEASE) with JPA 2.1 and Hibernate 4.3.5.Final. We upgraded from 4.1.0.Final along with using JPA 2.1 and our base repository.findOne(..) stopped working for repositories tracking entities with inheritance.
Our entity setup is:
@MappedSuperclass
public class A {}
@Entity
@Inheritance(strategy = InheritanceType.JOINED)
public abstract class User extends A {}
@Entity
public class SimpleUser extends B {}
@Entity
public class ComplexUser extends B {
@NotNull
@ManyToOne
private OtherEntity otherEntity;
}
With a repository class like so:
public interface UserRepository extends JpaRepository<User, Long>, QueryDslPredicateExecutor<User> {
}
Calling
UserRepository.findOne(1L)
should look through the SimpleUser and ComplexUser entities but instead always returned null. Tracking through the SQL, there is indeed an INNER JOIN on the OtherEntity table instead of a LEFT OUTER JOIN.
After implementing the proposed in https://hibernate.atlassian.net/browse/HHH-8830?focusedCommentId=57088&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-57088 like the following:
LocalContainerEntityManagerFactoryBean factoryBean = new LocalContainerEntityManagerFactoryBean();
...
Map<String, Object> properties = new HashMap<>();
properties.put("hibernate.batch_fetch_style", "PADDED");
factoryBean.setJpaPropertyMap(properties);
...
The SQL correctly uses LEFT JOINs. I would say that this is a pretty big issue that needs resolving!
|