I am mapping many table of legacy system and I have a problem about timezone requisite.
My Table has this situation below:
Table Operation:
Ref_local (String)
Ref_Type (Enum)
O_D_local (String)
O_D_type (Enum)
DateIni (Calendar)
.....
other Properties.
These five properties are PK. The legacy system uses the column Ref_local in order to discover the DateIni timezone. I would like to create a UserType that load Calendar in correct TimeZone Automatically. For this, I need to get the Ref_local column as part of mapping.
The First idea was:
Code:
@Column(name="Ref_local", insertable/updatable=false)
@Column(name="Data_ini")
@Type(...CalendarUserType...)
private Calendar dataIni;
But I can't mix updatable e not updatable column in mapping. If I let both columns as updatables, the mapping fail in other places (of course).
I tried to create a CompositeUserType but passing just one column. Inside, I could get the ResultSet and getColumn(ColumnName), but I fall in two problems.
1 - The Hibernate put a alias in column, so I can't to discover this alias in RunTime and I Can't get the value in resultset directly.
2 - Even I get the value, when I use the sessionImplementor to find the timezone using the column value, the current resultset is closed.
Are there any way to solve my problem. My workaround was put this code in a method PostLoad inside each entity but in this way, I spread the requisite in application and become hard to refactor in the future.
A "possible" solution could be I use "@Column" as Parameter in CustomType but I don't know if is possible.
Example:
Code:
@Column(name = "Data_ini")
@Type(type = CalendarUserType.NAME, parameters = @Parameter(name=CalendarUserType.COLUMN,value=@Column(name="Ref_local")))
private Calendar dataIni;
Any suggestion?