openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From MiƂosz Tylenda <mtyle...@o2.pl>
Subject Re: Mapping CHAR column to String
Date Thu, 11 Nov 2010 12:09:32 GMT
Hi Tobias,

You might want to experiment with @Strategy or @Externalizer. See the links below.

http://openjpa.apache.org/builds/latest/docs/manual/manual.html#ref_guide_pc_extern
http://openjpa.apache.org/builds/latest/docs/manual/manual.html#ref_guide_mapping_custom_field
https://issues.apache.org/jira/browse/OPENJPA-1687

Regards,
Milosz

> 
> Hi,
> 
> I have to access a legacy DB2 schema where text is stored in fixed length
> CHAR columns. We are using OpenJPA 2.0 on WebSphere 7. I face two problems:
> 
> a) when loading an entity, I always read a fixed length String of size N
> with trailing spaces (that's how a CHAR column works). I trim the spaces
> before they are display and edited in a web frontend.
> 
> b) when updating the entity, the trimmed string values are updated because
> of the missing trailing spaces, even when the string itself didn't change.
> 
> This seems to me like a common problem when dealing with legacy schemas with
> CHAR columns. Is there a common solution for this problem? Can I register
> some kind of TypeMapper for CHAR columns?
> 
> If a have a column like
> 
>     @Column(name = "PROD_VAR", length = 5)
>     private String produktVariante;
> 
> this mapper should be able to honour the length attribute. After reading the
> value from the ResultSet, the mapper just trims the string. When writing the
> value, the string has to be padded up to length. Is this possible with
> OpenJPA?
> 
> TIA,
> Tobias
> 

Mime
View raw message