Darth Blue Ray
Darth Blue Ray

Reputation: 9745

JPA persist a time duration

I need to persist a time duration e.g. 5 d 4 h

I was thinking of using a convertion (Duration / Calendar / Date class) where I than can persist it as a long (millisec) to the db (MySql). Like that I can easily convert and work with it.

Is this a good way to do this?

Upvotes: 1

Views: 1886

Answers (2)

GreyBeardedGeek
GreyBeardedGeek

Reputation: 30088

For the Hibernate 4.0 JPA provider, you can use the Usertype project to get JPA persistence for Joda Time classes, and then use the @Type annotation.

Upvotes: 1

DataNucleus
DataNucleus

Reputation: 15577

JodaTime (and forthcoming javax.time) provide a Duration class, and JPA providers such as DataNucleus JPA provide persistence for them out of the box without the need to play around with conversions.

Upvotes: 1

Related Questions