0

I'm writing a Java application that uses PostgreSQL as its RDBMS back end. I'm using Hibernate to create the DB schema (actually I already created the db schema myself but I got rid of that because I wanted to make sure my app would be able to understand it properly...).

I'd like to use some of Java 8's new types - specifically, the Duration type, and I'd like this to map to a column of type Interval. However, when Hibernate generates my schema it creates the column with type bytea, which is not going to be useful when I try to load in data from CSV files. A column of type interval, on the other hand, is able to read time formats like 01:23:45 from csv files and persist it just fine.

So how can I tell Hibernate that this Java field of type Duration should be mapped to a column of type Interval?

Thanks.

Edit: Note that this is not a question of how do I hook my app up to hibernate and postgresql. I already have it hooked up and configured for the most part. I am asking how to define custom type mappings so that my java Duration gets mapped to a PostgreSQL interval rather than a byeta.

tytk
  • 2,082
  • 3
  • 27
  • 39
  • possible duplicate of [Connecting PostgreSQL 9.2.1 with HIbernate](http://stackoverflow.com/questions/16572039/connecting-postgresql-9-2-1-with-hibernate) – mazaneicha Apr 11 '15 at 02:04
  • Definitely not a duplicate of that question. I already have my hibernate configuration set up and it's configuring the database just fine for the most part. I'm asking how to map a specific Java type to a specific postgresql type because the type that hibernate is mapping it to by default is not going to work for me. Also, I configured hibernate using an application.configuration not XML. – tytk Apr 11 '15 at 02:21
  • I expect you'll need to add support for that type in Hibernate using a custom type implementation, or wait for Hibernate to support it properly. Have you read the manual? http://docs.jboss.org/hibernate/orm/4.2/manual/en-US/html/ch06.html#types-custom – Craig Ringer Apr 11 '15 at 11:56
  • check out http://impossibl.github.io/pgjdbc-ng/ has some pg types for jdbc – Neil McGuigan Apr 11 '15 at 19:08

0 Answers0