persistence icon indicating copy to clipboard operation
persistence copied to clipboard

What should root.getJoins return after a root.get("x")?

Open lukasj opened this issue 6 years ago • 3 comments

I just found out that the following leads to different results in EclipseLink and Hibernate. And I can't decide from looking at the Spec which is the correct behavior:

CriteriaBuilder builder = em.getCriteriaBuilder();
CriteriaQuery<User> query = builder.createQuery(User.class);
Root<User> root = query.from(User.class);

root.get("manager");

// this returns 1 in EclipseLink and 0 in Hibernate.
root.getJoins()

User is an entity with manager being a self-reference (I don't think the "self" part is relevant here).

@Entity
public class User {
	@Id @GeneratedValue(strategy = GenerationType.AUTO) private Integer id;
	@ManyToOne private User manager;
        // getters and setters omitted for brevity.
}

Please clarify in the specification and in the TCK which one it should be.

lukasj avatar Jun 11 '18 12:06 lukasj

  • Issue Imported From: https://github.com/javaee/jpa-spec/issues/169
  • Original Issue Raised By:@schauder
  • Original Issue Assigned To: Unassigned

lukasj avatar Aug 31 '18 17:08 lukasj

Related issue in the EclipseLink issue tracker: https://bugs.eclipse.org/bugs/show_bug.cgi?id=413892

schauder avatar Mar 02 '21 09:03 schauder

This seems like low-hanging fruit that could be looked at in the next release and resolved one way or the other? I would say this is not that high of a priority either way.

Reza Rahman Jakarta EE Ambassador, Author, Blogger, Speaker

Please note views expressed here are my own as an individual community member and do not reflect the views of my employer.

m-reza-rahman avatar May 06 '21 22:05 m-reza-rahman