Hi Tobias,
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.

Kevin

On Thu, Nov 11, 2010 at 11:20 AM, Tobias Trelle <
[email protected]> wrote:

>
> Hi Milosz,
>
>
> Miłosz Tylenda-3 wrote:
> >
> > You might want to experiment with @Strategy or @Externalizer. See the
> > links below.
> >
>
> Thanks. I implemented a custom ValueHandler:
>
> public class CharValueHandler extends AbstractValueHandler {
>  ...
>    @Override
>    public Object toDataStoreValue(ValueMapping vm, Object val, JDBCStore
> store) {
>        if (val instanceof String) {
>            return pad((String) val, getLength(vm));
>        } else {
>            return val;
>        }
>    }
>
>    @Override
>    public Object toObjectValue(ValueMapping vm, Object val) {
>        if (val instanceof String) {
>            return trim((String) val);
>        } else {
>            return val;
>        }
>    }
>
> }
>
> where trim(..) and pad(...) are some string helper methods. This works
> fine.
> But I have to annotate every single attribute like this:
>
> @Column(unique = true, length = 50)
>
> @Strategy("com.xxxx.beispielanwendung.firmenverwaltung.entity.CharValueHandler")
> private String name;
>
> Is there a more generic way? I'd like to register this strategy for all
> columns of type CHAR or for all String attributes. Any hints?
>
> TIA,
> Tobias
>
> --
> View this message in context:
> http://openjpa.208410.n2.nabble.com/Mapping-CHAR-column-to-String-tp5727930p5729450.html
> Sent from the OpenJPA Users mailing list archive at Nabble.com.
>

Reply via email to