-->
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.  [ 3 posts ] 
Author Message
 Post subject: How to store the result in non managed bean (non entity)
PostPosted: Tue Dec 16, 2008 6:08 am 
Newbie

Joined: Mon Dec 15, 2008 11:53 am
Posts: 6
Hello all. Could you help me with subject. I have many stored procedures in Oracle. Now I use SQL Query and manual extract the resultSet to custom bean.

I would like to use hbm mapping file as used for entity. but want to extract in custom non managed bean. for example:


<sql-query name="getSomething" callable="true">
<return class ="MyNonManageBean">
<return-property name="prop1" column="PROP1"/>
<return-property name="prop2" column="PROP2"/>
</return>
{ call PROCEDURE_NAME(?, :param) }
</sql-query>

Class {
String prop1;
String prop2;

....

getters/setters
}

Or how can I use mapping instead of manual extracting resultSet?

Thanks for any answers!


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 16, 2008 2:48 pm 
Newbie

Joined: Mon Dec 15, 2008 2:28 pm
Posts: 8
Not sure if this will help, but it seems similar to a problem that I had in which I was obtaining multiple types of entities out of one HQL query.

Something like:
Code:
select s.courses, s.name
from Student s


As it is, the above code will return me a Java List, and each member of that list will be List<Course> and a String.

This was not convenient to me. So I created a non-entity POJO as below:
Code:
class NameAndCourse {
   private List<Course> studentCourses;
   private String studentName;

   //Getters and Setters for the above
}


In order to use the POJO above, my HQL query will now read as:
Code:
select s.courses as studentCourses, s.name as studentName
from Student s


And the code that executes the query would read:
Code:
session.createQuery(hql.toString())
  .setResultTransformer(org.hibernate.transform.Transformers.aliasToBean(NameAndCourse.class))
.list()


So now, I get a List<NameAndCourse> when the query gets executed.

Again, I haven't tried this with stored procedures, so this might not help you out.

_________________
Naresh
Please rate replies if they've helped you out.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 16, 2008 3:05 pm 
Newbie

Joined: Mon Dec 15, 2008 11:53 am
Posts: 6
I've found how to map the result to POJO.

mapping xml

Code:
<sql-query name="getSomething" callable="true">
    <return-scalar column="PROP1"/>
    <return-scalar column="PROP2"/>
{ call PROCEDURE_NAME(?, :param) }
</sql-query>


In DAO I use
Code:
Session.getNamedQuery("getSomething").setParameter("param", value).setResultTransformer(new AliasToBeanResultTransformer(POJO.class));


this works but I need something else. I want to control mapping columns on POJO's properties. I want to determine which column should map to the POJO's property. (If column in database is renamed I'll can easy map it by changing alias)
So I want to find out how can I use alias mapping with stored procedure.
All these things present, if bean is entity, but if not, I don't know how can I do this.[/code]


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