cayenne-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Arturo Pérez <ape...@hayesinc.com>
Subject Re: PostgreSQL interval type handling?
Date Wed, 04 Oct 2006 12:09:42 GMT
In article <84F20BC6-F2D3-41EC-B55F-7AF0EE9058D1@objectstyle.org>,
 Andrus Adamchik <andrus@objectstyle.org> wrote:

> No dragons, just ExtendedType:
> 
> http://cwiki.apache.org/CAYDOC/extended-types.html
> 
> Andrus
> 
> 
> >>
> >> On Sep 20, 2006, at 11:20 PM, Arturo Pérez wrote:
> >>> Hi all,
> >>>
> >>> I would like to use the PostgreSQL interval type in Cayenne.
> >>> Do I need to create a custom type?  If so, are there any gotchas?
> >>>
> >>> tia,
> >>> arturo
> >>>
> >>>
> >
> >
> >
> > OK.  Turns out that the JDBC driver for PostgreSQL has a PGInterval
> > type.  I set the class attribute to that type
> > (org.postgresql.util.PGinterval) and the Java code was generated
> > correctly.  I haven't run it yet, though.  Is there anything else I
> > should do?
> >
> > There any dragons lurking in there that I should be aware of?
> >
> > tia,
> > arturo
> >
> >



Just to partially close the loop on this one.  For a read-only 
application the below recipe works fine.I ran into one teensy problem 
easily resolved.  The modeler only knows timestamps, not
intervals, and that fooled me for a bit.

To use/read PostgreSQL interval types with JDBC:

1.  You have to create the column by hand because the CayenneModeler
does not know the interval type.

2.  In the DbObject, set the column type to OTHER.

3.  In the ObjType set the attribute's class to 
org.postgresql.util.PGinterval.

Voila!  Cayenne can read interval types and return them no problem.  
Please note that intervals cannot be cast to timestamps (my teensy 
problem) but as the PostgreSQL JDBC driver provides a PGInterval type,
that's not a problem.

-arturo


Mime
View raw message