-->
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.  [ 4 posts ] 
Author Message
 Post subject: Using non managed entities
PostPosted: Tue Jul 08, 2008 11:32 am 
Newbie

Joined: Tue Jul 08, 2008 11:16 am
Posts: 2
Hi all,

I would like to call stored procedures/function (from Oracle database).
Using entitymanager, I know I can map a native sql query to my entities.
The problem is, I can't map the results of my function to none of my entities, since the refcursor that is returned is too 'complicated' (mixed results from many tables, even from tables accessed via a dblink).

So, I would like to know if it is possible to create an non-managed entity (aka my simple mapping object), to which I can attach a native sql query (and results mapped with @SqlResultSetMapping).

As a hook, I'm getting the delegate hibernate session from my entitymanager :

Code:
        org.hibernate.Session session = (org.hibernate.Session) entityManager.getDelegate();
        quantiemes = session.getNamedQuery("MY_FUNCTION_FROM_HBM_XML")
                        .setParameter("p1", "US")
                        .setParameter("p2", "ALABAMA")
                        .setResultTransformer(Transformers.aliasToBean(SimplePojo.class))
                        .list();



Hibernate version:
Hibernate EntityManager 3.3.1.GA

Name and version of the database you are using:
Oracle 8.1.7.4 - 10g

Thanks for helping !


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 08, 2008 11:59 am 
Hibernate Team
Hibernate Team

Joined: Thu Apr 05, 2007 5:52 am
Posts: 1689
Location: Sweden
Hi,

I am not sure whether I understand your problem correctly.
@SqlResultSetMapping does only apply to mapped entities, but is a custom ResultTransformer exactly what you need?

--Hardy


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 09, 2008 4:13 am 
Newbie

Joined: Tue Jul 08, 2008 11:16 am
Posts: 2
Hi !
Thanks for your reply.

Yes, the ResultTransformer does the job. But I'm stick to using Transformers.aliasToBean ; with this method, I'm forced to have getter/setter = column_name.

Afaik, using @SqlResultSetMapping to a "not-mapped entity" would be more flexible.

Btw, you're talking about "custom" ResultTransformer ... what do you mean ?


Thanks !


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 09, 2008 4:36 am 
Hibernate Team
Hibernate Team

Joined: Thu Apr 05, 2007 5:52 am
Posts: 1689
Location: Sweden
Hi,

Transformers.aliasToBean is a predefined transformer, however you could also implement a completely different transformer by just implementing the ResultTransformer interface.

You could for example use the AliasToBeanConstructorResultTransformer. The name is a little bit misleading. You can easily check out the implementation on the publicly available fisheye instance - http://fisheye.jboss.org/browse/Hibernate/core/trunk/core/src/main/java/org/hibernate/transform/AliasToBeanConstructorResultTransformer.java?r=11588.

Also have a look at the other result transformers:
http://fisheye.jboss.org/browse/Hibernate/core/trunk/core/src/main/java/org/hibernate/transform.

--Hardy


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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.