|How to load all objects in JPA 2.0 using Criteria [message #521226]
||Tue, 16 March 2010 15:34
Registered: March 2010
I have the following code using JPA 2.0 with Criteria:|
EntityManagerFactory emf = Persistence.createEntityManagerFactory("TestPU");
EntityManager em = emf.createEntityManager();
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<System> c = cb.createQuery(System.class);
Root<System> r = c.from(System.class);
ListJoin<System, Report> reports = r.joinMap("reports");
List<Predicate> list = new ArrayList<Predicate>();
Path<String> nameField1 = r.get("name");
ParameterExpression<String> param1 = cb.parameter(String.class,
Path<String> nameField2 = reports.get("name");
ParameterExpression<String> param2 = cb.parameter(String.class,
TypedQuery<System> t = em.createQuery(c);
The code works well. However, I'm having a problem to retrieve all reports from system. My goal is to get always all entitie objects according to my needs, without having to load them in "lazy" mode. This would be independent of join quantities.
I've tried several alternatives like using "fetch of Root interface". However, when the query is showed on log, I note that the table "Report" is showed twice in the "from" clause. I can't find a solution to solve it.
For that reason, I'd like to know if somebody should help me with this question. Even through an EclipseLink native solution. I know it isn't the better alternative but would immediately solve my problem.
Powered by FUDForum
. Page generated in 0.02862 seconds