-->
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.  [ 6 posts ] 
Author Message
 Post subject: Hibernate without ORM .. is it possible to use the API's??
PostPosted: Thu Sep 06, 2007 1:44 pm 
Newbie

Joined: Fri Jul 28, 2006 9:52 am
Posts: 12
I am trying to use hibernate without the object relational mapping. My current situation is to use hibernate just for executing the query and use the rest of the api for filtering and pagination. Since i have the SQL queries with me, by no other go i need to use

Code:
session.createSQLQuery(query);


thats fine. but what can i do if i want to use the other api's like i want to use the projection, restriction and all. These can be used only with the criteria, as far as i had gone through the documentation i couldnt find any api to set sql query for criteria. Criteria can be created only using the object representation.

Is there any solution for it???

Also is it possible to convert an query object to a criteria object??

One more question...

Is there anyway to get the query which is going to fire to the database??

getQueryString returns the query which we provieded as the input... any other api available to provide the converted query???


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 06, 2007 6:30 pm 
Expert
Expert

Joined: Tue Nov 23, 2004 7:00 pm
Posts: 570
Location: mostly Frankfurt Germany
Criteria and HQL requires mappings to translate a query in SQL.

_________________
Best Regards
Sebastian
---
Training for Hibernate and Java Persistence
Tutorials for Hibernate, Spring, EJB, JSF...
eBook: Hibernate 3 - DeveloperGuide
Paper book: Hibernate 3 - Das Praxisbuch
http://www.laliluna.de


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 07, 2007 5:02 am 
Newbie

Joined: Fri Sep 07, 2007 4:16 am
Posts: 16
use ResultSetTransformer


Top
 Profile  
 
 Post subject: could you please brief on that??
PostPosted: Fri Sep 07, 2007 9:47 am 
Newbie

Joined: Fri Jul 28, 2006 9:52 am
Posts: 12
dilembus.. could you please brief on that resultsettransformer??

is that can be used to retrieve the querystring or to create the criteria with SQL query???

do you have any sample code on that???


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 07, 2007 2:24 pm 
Newbie

Joined: Fri Sep 07, 2007 4:16 am
Posts: 16
Use methods aliasToBean of org.hibernate.transform.Transformers
public static ResultTransformer aliasToBean(Class target)

U create ur bean anf after using aliasToBean(Class target) u can manage it with criteria and hql.

Please rate me ; )


Top
 Profile  
 
 Post subject: That wont solve the problem.
PostPosted: Fri Sep 07, 2007 3:51 pm 
Newbie

Joined: Fri Jul 28, 2006 9:52 am
Posts: 12
hi dilembus , i think u didnt understood my question. The solution which you provided is to convert the resultset to any persistent class. But my requirement doesnt have the persistent class itself.

Imagine you have a StudentDTO class:

Code:
public class StudentDTO {
  private String studentName;
  private String courseDescription;
 
  public StudentDTO() { }
     
  ...
}


Then you can make the Criteria return non-entity classes instead of scalars or entities by applying a ResultTransformer:

Code:
List resultWithAliasedBean = s.createCriteria(Enrolment.class)
  .createAlias("student", "st").createAlias("course", "co")
  .setProjection( Projections.projectionList()
                   .add( Projections.property("st.name"), "studentName" )
                   .add( Projections.property("co.description"), "courseDescription" )
          )
          .setResultTransformer( Transformers.aliasToBean(StudentDTO.class) )
          .list();

StudentDTO dto = (StudentDTO)resultWithAliasedBean.get(0);


This is how we will use resultsettransformer right??

But how does it helps to solve my question????

I am still searching for a solution. Will let you know once i get it.

Also i am looking for an API which will give me the SQL query back to me.

Like after setting all the filters and where class in the Query object, when we do query.list() ... that time it converts the query based on the dialect and it fires the query. I am trying to find a way to get that firing query. Just help me out if you one.

Anyway thanks for your quick reply.


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