-->
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: SQL in Hibernate
PostPosted: Fri Feb 15, 2008 8:50 am 
Beginner
Beginner

Joined: Thu Jun 29, 2006 8:41 am
Posts: 41
We're using Hibernate in our project, but we eventually found out that some kinds of queries were too complicated for it.

So, after studing a bit the Hibernate in Action book and the documentation chapter about SQL, I tried to use SQL queries in our project.

Anyway, Direct SQL queries work ok, but I'm having problems with the placeholders scheme.

Actually, our normal queries are built in a XML format and later transformed into HQL by some of our classes. This XML contain the classes and columns written in a especific format that's not useful to Hibernate. We pick them up, and adapt them to the HQL proper format.

The idea with the SQL is to use this specific format names inside the placeholder "{}" and modify and replace them on the fly.

Anyway, what I really need to know. is: Do I need to use the .addEntity() method together with the placeholders or not? Because as I have a variable amount of classes involved in the different classes, adding entities on the run would be very hard. I don't want to build the whole Hibernate query method for each of the queries (right now we just call the proper method and pass the query String to it).

We are working with the ResultSet full of scalars, not the especific entities.

P.s.: If I'm not being very clear about my problem, please tell me and I'll try to explain it better.

_________________
Falci - Heavy Worker!


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 18, 2008 9:54 am 
Beginner
Beginner

Joined: Thu Jun 29, 2006 8:41 am
Posts: 41
Ok... since no one answered, I suppose no one could figure out what I was asking.

I'll try a different aproach then.

My SQL queries are in a format similar to:

select {classA.classB.sequencial} from CLASS_A where {classA.classB.otherProp} = 'someStuff'

Class A has a many to one relation with Class B.

Now... how do I make this work? If I use a pure SQL query it works, but when trying this placeholders approach it simply won't work.

Sometimes it accuses part of the names inside the placeholders as an invalid SQL Token others it states it can't find the property classB.sequencial from classA.

I've read the entire Chapter 16 of the documentation and also the chapter about it in Hibernate in Action, but I still can't figure out what is going wrong.

In case you may want to ask: I am using the .setSqlQuery() command properly although I admit I still don't know if I'm going to need the .addEntity() and/or the .addJoin() methods. (I'm actually looking for the entries not the entire classes, so I can pretty much get only a ResultSet from the query).

I'm using Hibernate 3.1 by the way.

EDIT: Please note that while I'm trying to run simple queries right now, the objective is to run more complex queries that are not apropriate to use common HQL.

_________________
Falci - Heavy Worker!


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.