|
I have One Main entity called Report. I have several entities connect to Report with ManyToMany Relation. The connection is done via extra table. i.e with @JoinTable annotation. each relation is lazy.
I have a function that fetch the report with all its relations. now, if i do fetch by accessing the property (i.e mark the function as @Transcational and access to each one of the property) everything works as expected. But, if I do
Report r = null; CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<Report> query = cb.createQuery(Report.class); Root<Report> report = query.from(Report.class); ArrayList<Predicate> preds = new ArrayList<Predicate>(); DomainSpecification.<Report>eager().toPredicate(report, query, cb); preds.add(DomainSpecification.<Report>idIsEqual(id).toPredicate(report, query, cb)); query.where(cb.and(preds.toArray(new Predicate[preds.size()]))); query.select(report); List<Report> results = em.createQuery(query).setMaxResults(1).get
i get all the relations as well but One of the relation (that has been connected to another table NOT by primary key) is fetching 13823 times this means that the length of r.getProjects() is 13823 of the same Project. I attaching here the source of Domain Specification/Report.java/Project.java and Keyword.java (the keyword is just to show an example for an entity that works good with this kind of fetching) Maybe one can throw some light on this issues
|