Web Development



I don't know how to write a sql command with list of objects....?

By sara_h ·
I am writing sql commands, with the use of hibernate, I want to retrieve objects named "LOAN", that have 2 or more lists, I want the lists' members, and performance is important for me.
I've already used this way.... At first I retrieve the LOAN objects with addEntity command, and then with iterating on lists, retrieve the Id of the members, and then retrieve each of the list members, with a sql command by sending its id as a parameter.
So a lot of commands are needed!
I wonder if it is better to retrieve all the list members with a uniqe command?
here is the code I've used:

((SqlQuery)session.createSqlQuery(sql)).addEntity("LOAN", Loan.class)

ps: My boss has forced me to use SQL instead of HQL with hibernate,
(because of HQL problems in performance!...) I don't know if this is right? I would be appreciated, if somebody could help me with this, too.

This conversation is currently closed to new comments.

Thread display: Collapse - | Expand +

All Answers

Collapse -


by TobiF In reply to I don't know how to write ...

One would need more information about the data structure to give a specific answer, but that information may be sensitive...

Anyway, yes, you should move the connection logics from repeating commands to one single SQL command, which will give you the information you actually need.

This way, the server will quickly extract the information you need and send it over, rather than first sending over a complete table to you and then do a whole bunch of separate lookups.

Say you have one table "loantypes", a second table "loans" and a third tabla "customers".

Then a command could look something like:
SELECT loantypes.description, customers.name WHERE loans.status = 'active' AND loantypes.id = loans.loantype.id AND loans.customerid = customers.id
FROM loantypes, loans, customers

That's the SQL part, then you'll have to package this neatly into whatever command you need to call the correct plugins etc.

Related Discussions

Related Forums