Bartosz Herczyk (
https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=70121%3...
) *created* an issue
Hibernate ORM (
https://hibernate.atlassian.net/browse/HHH?atlOrigin=eyJpIjoiOTJkOGQ4YWIx...
) / Bug (
https://hibernate.atlassian.net/browse/HHH-16204?atlOrigin=eyJpIjoiOTJkOG...
) HHH-16204 (
https://hibernate.atlassian.net/browse/HHH-16204?atlOrigin=eyJpIjoiOTJkOG...
) [EntityGraph] Does not fetch 4-level data (
https://hibernate.atlassian.net/browse/HHH-16204?atlOrigin=eyJpIjoiOTJkOG...
)
Issue Type: Bug Affects Versions: 6.1.6, 6.1.7 Assignee: Unassigned Created: 20/Feb/2023
06:49 AM Priority: Major Reporter: Bartosz Herczyk (
https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=70121%3...
)
I migrated hibernate *5.6.14.Final* to *6.1.7.Final* and I noticed a problem with
entityGraph.
I have entities:
@Entity
public class Company {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@ManyToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
private Factory factory;
}
@Entity
public class Factory {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
private CarFactory carFactory;
}
public class CarFactory {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@OneToMany(mappedBy = "carFactory" , cascade = CascadeType.ALL, orphanRemoval
= true )
Set<Car> cars = new HashSet<>();
}
@Entity
public class Car {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@OneToMany(mappedBy = "car" , cascade = CascadeType.ALL, fetch =
FetchType.LAZY, orphanRemoval = true )
private Set<Feature> features = new HashSet<>();
@ManyToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
private CarFactory carFactory;
@ManyToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
private Info info;
}
@Entity
public class Feature {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@ManyToOne(fetch = FetchType.LAZY)
private Car car;
@OneToOne(fetch = FetchType.LAZY)
private Factory factory;
}
@Entity
public class Info {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
}
When I want to fetch all these entities in one query using @EntityGraph :
@Query( "select c from Company c where c.id = :id" )
@EntityGraph(attributePaths = { "factory" , "factory.carFactory" ,
"factory.carFactory.cars" ,
"factory.carFactory.cars.features" ,
"factory.carFactory.cars.info"
})
Optional<Company> findByIdCustomEntityGraph( long id);
or using fetchGraph hint:
@Transactional(readOnly = true )
public Company getFetchGraphHint( long id) {
var companyGraph = entityManager.createEntityGraph(Company.class);
var factoryGraph = companyGraph.addSubgraph( "factory" );
var carFactoryGraph = factoryGraph.addSubgraph( "carFactory" );
var carsGraph = carFactoryGraph.addSubgraph( "cars" );
carsGraph.addAttributeNodes( "features" , "info" );
return entityManager.createQuery( "select c from Company c where c.id =
:id" , Company.class)
.setParameter( "id" , id)
.setHint(SpecHints.HINT_SPEC_FETCH_GRAPH, companyGraph)
.getSingleResult();
}
The features and info data are not fetched.
Example project:
* hibernate 6.1.7 - tests failed
https://github.com/bherczyk/hibernate_6_bugs/blob/master/src/test/java/co...
(
https://github.com/bherczyk/hibernate_6_bugs/blob/master/src/test/java/co...
)
* hibernate 5.6.14 - tests passed
https://github.com/bherczyk/hibernate_6_bugs/blob/hibernate-5/src/test/ja...
(
https://github.com/bherczyk/hibernate_6_bugs/blob/hibernate-5/src/test/ja...
)
(
https://hibernate.atlassian.net/browse/HHH-16204#add-comment?atlOrigin=ey...
) Add Comment (
https://hibernate.atlassian.net/browse/HHH-16204#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=Em...
) This message was sent by Atlassian Jira (v1001.0.0-SNAPSHOT#100217- sha1:d96fecc )