How to map the PostgreSQL Interval column type in Hibernate?

后端 未结 5 1805
耶瑟儿~
耶瑟儿~ 2020-12-16 14:45

Under PostgreSQL, I\'m using PersistentDuration for the mapping between the sql type interval & duration but it doesn\'t work.

Another user found th

5条回答
  •  自闭症患者
    2020-12-16 15:26

    According to the link you should have a day followed by hours:minutes:seconds. So changing the code to something like the following assuming you never need to have more then 23 hours 59 minutes in the interval.

    statement.setString(index, "'0 "+ hours +":" 
    + intervalFormat.format(minutes) + ":" 
    + intervalFormat.format(secondes)+"'"); 
    

    I am not able to test this code since I don't have PostGreSql installed. For another discussion on this same issue see the following link, although you would have to modify the code provided to handle seconds. That shouldn't be much of a problem though.

    https://forum.hibernate.org/viewtopic.php?p=2348558&sid=95488ce561e7efec8a2950f76ae4741c

提交回复
热议问题