-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: createNativeQuery and map result to simple bean
PostPosted: Thu Feb 19, 2009 5:15 am 
Newbie

Joined: Wed Feb 18, 2009 6:29 am
Posts: 2
Hi ..

Using OpenJPA I have code running that implement a FastLaneReader pattern using createNativeQuery and a simple databean to be used in the UI layer. The case could be : I need to query a customer table in a separate schema (not managed by my application) and just display a list for selection.

I am unable to make this work using Hibernate (tried several versions inkl. latest )
Code:
...
String sql = "select custno at1, fullname at2, address at3 from customer";
EntityManager entityManager = factory.createEntityManager();
List<TestBean> items = new ArrayList<TestBean>();
   try {
      Query q = entityManager.createNativeQuery(sql, TestBean.class);
      items = q.getResultList();
   } catch (Exception e) {
       e.printStackTrace();
   }
...


The code above works fine in OpenJPA, but Hibernate reports
"Unknown entity: org.domain.test.dao.TestBean"

Is this working as designed, should'nt I be able to map to a simple non-managed bean? If not which is the best way to implement this scenario using hibernate entitymanager ?

Thanks
Anders Monrad


Top
 Profile  
 
 Post subject:
PostPosted: Sun Feb 22, 2009 2:20 am 
Newbie

Joined: Wed Feb 18, 2009 6:29 am
Posts: 2
I guess the hibernate way of doing this is using something like this

Session session = (Session)entityManager.getDelegate();
Query q = session.createSQLQuery(sql).setResultTransformer(Transformers.aliasToBean(TestBean.class));
List l = q.list();

IsĀ“nt there any way to do this in a JPA-only way, when using hibernate as the jpa provider?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.