openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Tobias Trelle <tobias.tre...@codecentric.de>
Subject Mapping CHAR column to String
Date Thu, 11 Nov 2010 08:34:44 GMT

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
-- 
View this message in context: http://openjpa.208410.n2.nabble.com/Mapping-CHAR-column-to-String-tp5727930p5727930.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.

Mime
View raw message