views:

239

answers:

5
+1  Q: 

Hibernate, aliases

Hello!

I noticed that hibernate generates different aliases for the same columns each time i try to access the same table:

Hibernate: select person0_.id as id0_0_, person0_.nam as nam0_0_, person0_.fam as fam0_0_, person0_.otc as otc0_0_ from web_db.Person person0_ where person0_.id=?
Hibernate: select person0_.id as id4_0_, person0_.nam as nam4_0_, person0_.fam as fam4_0_, person0_.otc as otc4_0_ from web_db.Person person0_ where person0_.id=?

Is there any way to get to hibernate to generate identical aliases for identical queries? For example:

Hibernate: select person0_.id as id0_0_, person0_.nam as nam0_0_, person0_.fam as fam0_0_, person0_.otc as otc0_0_ from web_db.Person person0_ where person0_.id=?
Hibernate: select person0_.id as id0_0_, person0_.nam as nam0_0_, person0_.fam as fam0_0_, person0_.otc as otc0_0_ from web_db.Person person0_ where person0_.id=?
A: 

Short answer: nope

Why?
That's the whole point isn't it? You are abstracted from the actual query statements.

o.k.w
And you are also abstracted away from the fact that Oracle considers this two different SQL statements, causing hard parsing and a decrease in performance.
ObiWanKenobi
+2  A: 

First, I'm using Oracle 9i.

Different queries causes server to do hard parse. If there are many such queries, database server responsibility is falling down. We have to use bind variables to avoid this problem.

dya-victor
Is this an answer? Don't use answers to post comments/details, update your question instead.
Pascal Thivent
+1  A: 

Anyway, my solution - named queries, where I will specify how to select data explicitly...

dya-victor
+1  A: 

Have a look at HHH-2448 which covers this topic and has a patch for deterministic alias generation.

Pascal Thivent
A: 

Thank you are, Pascal Thivent! It is exactly what i need!

P.S. Sorry, i have no reputation yet to increase your rating :)

dya-victor