openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From efenderbosch <>
Subject How to use Postgres inet data type with OpenJPA [2.2.2]?
Date Wed, 17 Jul 2013 18:57:19 GMT
I need to record IP addresses in a Postgres (9.0) table with OpenJPA (2.2.2).

I've got it working using a native query:

    EntityManager entityManager =
    int rows = entityManager.createNativeQuery("insert into click (ip)
values (?::inet)") //
        .setParameter(1, InetAddress.getLocalHost().getHostAddress()) //

But I'd prefer to figure out a way for OpenJPA to handle it w/o a native

I searched and found some other suggestions like annotating the column like

    @Column(length = -1, columnDefinition = "inet")

But that doesn't seem to do the cast. I get this exception:

    ERROR: column "ip" is of type inet but expression is of type character
    Hint: You will need to rewrite or cast the expression.
    Position: 32 {prepstmnt 1376458920 INSERT INTO Click (ip) VALUES (?)
[params=?]} [code=0, state=42804]

Can I annotate the field w/ @Strategy and implement a custom FieldStrategy
or ValueHandler? This seems like the right solution, but the documentation
is pretty light and I can't find a simple example to start from.

Any direction on fixing the annotations or implementing a FieldStrategy or
ValueHandler would be appreciated.

View this message in context:
Sent from the OpenJPA Users mailing list archive at

View raw message