Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » How to load all objects in JPA 2.0 using Criteria
How to load all objects in JPA 2.0 using Criteria [message #521226] Tue, 16 March 2010 15:34 Go to previous message
Nobili  is currently offline Nobili
Messages: 6
Registered: March 2010
Junior Member
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");
c.select(r);

List<Predicate> list = new ArrayList<Predicate>();

Path<String> nameField1 = r.get("name");
ParameterExpression<String> param1 = cb.parameter(String.class,
"param1");
lista.add(cb.equal(cb.upper(nameField1), param1));

Path<String> nameField2 = reports.get("name");
ParameterExpression<String> param2 = cb.parameter(String.class,
"param2");
lista.add(cb.equal(nameField2, param2));

c.where(cb.and(lista.toArray(new Predicate[0])));

TypedQuery<System> t = em.createQuery(c);
t.setParameter("param1", "MySystem");
t.setParameter("param2", "Developer");


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.
 
Read Message
Read Message
Previous Topic:Can eclipselink log entity changes?
Next Topic:External file to specify DB information
Goto Forum:
  


Current Time: Wed May 22 01:36:44 EDT 2013

Powered by FUDForum. Page generated in 0.01668 seconds