1

In postgres 9.2 i have a column with a timestamp

CREATE TABLE pilot
(
  id bigint NOT NULL,
  birthdate timestamp without time zone NOT NULL,
  firstname character varying(50) NOT NULL,
  CONSTRAINT pilot_pkey PRIMARY KEY (id )
)

I inserted some rows directly with a java main with Hibernate :

    for (int i = 0; i < 10; i++) {
        Pilot p = new Pilot();
        p.setBirthdate(new Date());
        p.setFirstname("Johnson_" +tabchar[i] );
        em.persist(p);
    }

My property looks like this :

@Temporal(TemporalType.TIMESTAMP)
@Column(name = "birthdate", nullable = false, unique = false)
public java.util.Date getBirthdate() {
    return birthdate;
}

And some rows are inserted by JSF2 relaying to hibernate : I 'm using JSF 2.1.13

    <h:form id="formPilot">
        <h:panelGrid columns="2">
            <h:outputLabel value="#{appMsg['pilot.firstname']}" />
            <h:inputText id="firstname" label="#{appMsg['pilot.firstname']}" value="#{pilotHolder.pilot.firstname}"
                required="true" />

            <h:outputLabel value="#{appMsg['pilot.birthdate']}" />
            <h:inputText id="birthdate" label="#{appMsg['pilot.birthdate']}" value="#{pilotHolder.pilot.birthdate}"
                required="true">
                <f:convertDateTime pattern="dd/MM/yyyy HH:mm:ss" timeZone="GMT+1"/>
            </h:inputText>

        </h:panelGrid>
        <h:commandButton id="merge" action="#{pilotAction.doMerge}"
            value="#{pilotHolder.pilot.id ne null ? appMsg['pilot.update'] : appMsg['pilot.create']}" />
    </h:form>   

In the DB all is OK, all the dates are correct (with the hours ok)

BUT When I show the list of Pilots though and show them on a page the date which were inserted by Hibernate without JSF have an error of 1 hour less, not the timestamps that i inserted with JSF ?

        <h:column>
            <f:facet name="header">
                <h:outputText value="#{appMsg['pilot.birthdate']}" />
            </f:facet>
            <h:outputText value="#{p.birthdate}" >
               <f:convertDateTime pattern="dd/MM/yyyy HH:mm:ss" timeZone="GMT+1"/>
            </h:outputText>
        </h:column>

What is strange is that i can't any difference in the DB using DBvisualizer, they all look similar, If I print the date after Hibernate has fetch them, all is ok.

If i look closer at the dates inserted by Hibernate and fetched back, they contain a field cdate not null of type Gregorian$Date. The dates inserted by JSF and fetched back have a cdate=null.

Why? and why are they interpreted differently by JSF2 ?

1 Answer 1

3

I think it is DAYLIGHT SAVING TIME related

Try this in your web.xml

<context-param>
    <param-name>javax.faces.DATETIMECONVERTER_DEFAULT_TIMEZONE_IS_SYSTEM_TIMEZONE</param-name>
    <param-value>true</param-value>
</context-param>

Or you can tell the f:dateTimeConverter which timeZone to use. Just use a Time Zone that doesn't use daylight savings.

Sign up to request clarification or add additional context in comments.

1 Comment

it works for me. With this global param, javax.faces.DATETIMECONVERTER_DEFAULT_TIMEZONE_IS_SYSTEM_TIMEZONE set to true, JSF does not take into account the Timezone of the java.util.Date. I still don't understand 2 things : 1-why is postgres keeping the timezone info with the database type : timestamp without time zone ? 2-why does JSF treats differently date with and without timezone whrn using timeZone="GMT+1" ? I 'll have to look further ...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.