java - Hibernate custom type access result set -



java - Hibernate custom type access result set -

my class implements hibernate custom user type. implements usertype, parameterizedtype.

public object nullsafeget(resultset resultset, string[] params, object owner) throws sqlexception {

i need access status fields via resultset parameter. have 2 ways of access.

by giving coloumn number resultset.getstring(17);

specifing colounm name. hiberbate returns resultset.getstring("status13_51_0_"); //status13_51_0_

hibernate generates query own alias , can access alias not column name.

the problem , class called different places need access each time status column.

as incoming query different receiving column number , generated field alias different.

what approach, solution can suggest me overcome situation ?

you should phone call resultset.getstring method on appropriate element param array. there no need utilize hardcoded aliases. e.g.

resultset.getstring(params[0]);

simple illustration mapping:

mapping

<property name="propertyname" type="yourusertype"> <column name="columnname1" /> <column name="columnname2" /> </property>

or

@type(type="com.package.usertypes.yourusertype") @columns(columns = { @column(name="columnname1"), @column(name="columnname2") }) private customclass propertyname;

user type

public object nullsafeget(resultset resultset, string[] params, object owner) throws sqlexception { resultset.getstring(params[0]); // value of 'columnname1' column resultset.getstring(params[1]); // value of 'columnname2' column // }

java hibernate

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -