Hi Tobias,

Try Column#getType, Column#getTypeIdentifier / Column#getTypeName. If they 
contain something, it should differ for CHAR and VARCHAR.

Also, if you are annotating your fields with @Column anyway, you could skip 
"length" in @Column for the VARCHAR fields.

BTW, do you really need padding on INSERT/UPDATE? What happens if you don't 
pad? Won't the database do it for you?

Greetings,
Milosz

> 
> Kevin Sutter wrote:
> > 
> > The @Strategy annotation is defined to work at the type (Entity) level.
> > But, that would mean that all attributes in that entity would utilize your
> > defined Strategy.  I doubt that would work for your scenario.  Other than
> > that, the only currently defined means is to specify the Strategy as you
> > need it for each attribute.
> > 
> 
> I found a smart solution for this problem. It is possible to register field
> strategies per Java type. This is done via an OpenJPA property in
> persistence.xml:
> 
> <property
>    name="openjpa.jdbc.MappingDefaults"
>   
> value="FieldStrategies='java.lang.String=com.xxx.beispielanwendung.firmenverwaltung.entity.CharValueHandler'"
> />
> 
> Now all String attributes (in all entities) are processed by the
> CharValueHandler (without annotating any single attribute!). This is
> basically what we need.
> 
> But I like to narrow it down only the CHAR columns (with VARCHAR columns I
> don't need and want to pad the string with spaces before INSERT or UPDATE).
> Is there a way to extract the DB column type within a ValueHandler? The
> interface methods are provided with a ValueMapping. Column#getJavaType
> provides the type information on the Java side, not the DB column type. Any
> ideas?
> 
> TIA,
> Tobias
> 
> 

Reply via email to