开发者

querying a table using JPA and populating a bean corresopind to a table

I have a project already developed using java,jsp and JPA (open jpa).Now i want to add a new API to retrieve data from DB.Am not much familiar with JPA.Now i want to take a join of 3 tables Atbl , Btbl, and Ctble ,then check for some conditions and finally populate bean corresopnding to table Atble.I saw a a API as follows

String sql = "SELECT A.* FROM Atble A, Btbl B WHERE A.xyz = B.pqr 
        AND A.field1 = ?  AND B.field2 = 'SubComponent' AND B.field3 = ? ";
        Query q = em.createNativeQuery(sql, A.class);
        q.setParameter(1,"aa");
        q.setParameter(2, "aa");
        q.setParameter(3, "cc");

        List<A> a = (List<A>) q
            .getResultList();

Does it populate bean for A directly?If not how开发者_JS百科 can i populate bean for A


This will return a List, so should work fine.

You may also consider using JPQL instead of a native SQL query, but if you are more comfortable with SQL that is fine.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜