Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hibernate, aliases

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=?
like image 344
dya-victor Avatar asked Nov 29 '09 12:11

dya-victor


2 Answers

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

like image 154
Pascal Thivent Avatar answered Oct 17 '22 11:10

Pascal Thivent


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

like image 1
dya-victor Avatar answered Oct 17 '22 12:10

dya-victor