I am trying to use HibernateCompositeUser type to handle i18n specific data in my application. i am trying to use the below approach.
I have a table named master table which contains all locale independent data while i have created another table master_translation which contains all locale sensitive information. Master table contains a reference to the master_translation.here is the detailed table structure
master
---ID
---master_translation
---Other locale independent fields.
master_translation
---ID
---language_id
---Other locale sensitive fields
now i am using HibernateCompositeUser type to handle this internal process. here is the mapping for master class.
<hibernate-mapping>
<class name="Master"
table="MASTER">
<id name="uuid" type="java.lang.String">
<column name="UUID" />
<generator class="uuid" />
</id>
<property name="master_i18n" type="masteri18n">
<column name="NAME"/>
<column name="SHORTDESCRIPTION"/>
<column name="LONGDESCRIPTION"/>
</class>
</hibernate-mapping>
where type="masteri18n" is hibernate CompositeUserType.now when i am fetching the master content it is correctly fetching the data based on the language and my Master class contain a reference to the Master_translation which holding locale specific data
i am handling this case
public Object nullSafeGet(ResultSet rs, String[] arg1,
SessionImplementor arg2, Object arg3) throws HibernateException,
SQLException {
Master_i18n master_i18n=Master_i18n.getInstance();
master_i18n=dao.getMaster_i18n(rs.getString(arg1[0]), "nl_NL");;
//return Master_i18n.getName();
return Master_i18n;
}
@Override
public void nullSafeSet(PreparedStatement ps, Object arg1, int index,
SessionImplementor arg3) throws HibernateException, SQLException {
if(arg1==null){
ps.setNull(index, Hibernate.STRING.sqlType());
//ps.setNull(index+1, Hibernate.STRING.sqlType());
//ps.setNull(index+2, Hibernate.STRING.sqlType());set
}
else{
Master_i18n des=(Master_i18n)arg1;
des=dao.saveMaster_i18n(des);
ps.setString(index, des.getUuid());
ps.setString(index+1, des.getUuid());
ps.setString(index+2, des.getUuid());
ps.setString(index+3, des.getUuid());
}
}
Somehow i am not sure not feeling confident about my approach.my query is if i am implementing it in right way or not?