Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6600491
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T18:37:47+00:00 2026-05-25T18:37:47+00:00

I have a model class with a persisted DateTime field that is only interacted

  • 0

I have a model class with a persisted DateTime field that is only interacted via getters/setters for Transient properties, String date; and String time;. The do some very specific formatting to create the DateTime object that will be persisted or retrieved when need be.

The problem is that when my model’s loaded from the yaml file, the setter for the time field receives a String value that doesn’t correspond at all to anything in my project/code.

Here’s the class with only relevant members:

package models;

import javax.persistence.*;
import org.hibernate.annotations.*;
import org.joda.time.*;
import org.joda.time.format.*;

import play.db.jpa.*;

@javax.persistence.Entity
public class Booking extends Model {

  @Column
  @Type(type = "org.joda.time.contrib.hibernate.PersistentDateTime")
  public DateTime datetime;
  public Integer duration;
  @Transient
  public String date;
  @Transient
  public String time;    

  //default constructor called by play's model loader that sets default values that are required for the getters and setters to work.
  public Booking() {
    DateTimeFormatter fmt = DateTimeFormat.forPattern("'ISO8601':yyyy-MM-dd'T'HH:mm:ssZ");
    this.datetime = fmt.parseDateTime("ISO8601:1970-01-01T00:00:00+0200");
    //this.datetime = fmt.parseDateTime(this.date+"T"+this.time);
  }

  public void setDate(String dateStr) {    
    this.date = dateStr;
    if (dateStr.contains("ISO")) {
      DateTimeFormatter dt = DateTimeFormat.forPattern("'ISO8601':yyyy-MM-dd'T'HH:mm:ssZ");
      DateTime tmp = dt.parseDateTime(dateStr);
      this.datetime = toDateTime(tmp.toString("yyyy-MM-dd"), getTime());
    } else {
      this.datetime = toDateTime(dateStr, getTime());
    }

  }

  public void setTime(String timeStr) {
    this.time = timeStr; //timeStr = "780" for some reason?!
    if (timeStr.contains("ISO")) {
      DateTimeFormatter dt = DateTimeFormat.forPattern("'ISO8601':yyyy-MM-dd'T'HH:mm:ssZ");
      DateTime tmp = dt.parseDateTime(timeStr);
      this.datetime = toDateTime(getDate(), tmp.toString("HH:mm"));
    }
    this.datetime = toDateTime(getDate(), timeStr);
  }

  public String getDate() {
    DateTimeFormatter format = DateTimeFormat.forPattern("yyyy-MM-dd");
    return this.datetime.toString(format);
  }

  public String getTime() {
    DateTimeFormatter format = DateTimeFormat.forPattern("HH:mm");
    return this.datetime.toString(format);
  }

  private DateTime toDateTime(String dateStr, String timeStr) {
    DateTimeFormatter fmt = ISODateTimeFormat.dateHourMinute();
    DateTime dt = fmt.parseDateTime(dateStr + "T" + timeStr);
    return dt;
  }

When I run through the debugger, the timeStr parameter that setTime receives when it’s first called is "780". There is no such value in my yaml file as the model is injected like this:

Booking(bobBooking):
  date: 2011-09-16
  time: 13:00
  duration: 30
  headcount: 10
  room: b
  user: bob
  description: Bob's Booking.

The additional fields are omitted.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T18:37:48+00:00Added an answer on May 25, 2026 at 6:37 pm

    Try using quotes for time value in yaml file. There could be some issue in parsing colon fields using SnakeYAML parser (which is the default in Play)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have one grails application.In that I have one model class named Book. From
I have a model called Booking which has a persistent DateTime field. However I
I have a model: class Example(models.Model): unique_hash = models.CharField(max_length=32,unique=True) content = models.FileField(upload_to='source',blank=True,verbose_name=HTML Content File)
I have a model class like this: class Note(models.Model): author = models.ForeignKey(User, related_name='notes') content
Assume I have a Model class called Bird and a instance of Bird called
Let's say I have a model class called Project, but instead of this: class
I have a class Model: class Model { ... boost::shared_ptr<Deck> _deck; boost::shared_ptr<CardStack> _stack[22]; };
I have this Task model: class Task < ActiveRecord::Base acts_as_tree :order => 'sort_order' end
I have a following model: class Car(models.Model): make = models.CharField(max_length=40) mileage_limit = models.IntegerField() mileage
I have a simple model class (Part), which pulls from it's information from a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.