Tobias - Have you tried the columnDefinition property?
http://openjpa.apache.org/builds/2.0.1/apache-openjpa-2.0.1/docs/manual/manual.html#jpa_overview_mapping_column

See if this gets you what you want:

     @Column(name = "PROD_VAR", columnDefinition = "CHAR(5)")
     private String produktVariante;

Thanks,
Lucas.



From:   Miłosz Tylenda <[email protected]>
To:     [email protected]
Date:   11/11/2010 12:10
Subject:        Re: Mapping CHAR column to String



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
> 







Unless stated otherwise above:
IBM United Kingdom Limited - Registered in England and Wales with number 
741598. 
Registered office: PO Box 41, North Harbour, Portsmouth, Hampshire PO6 3AU





Reply via email to