title: PostgreSQL and Hibernate: How do I format timestamp output?
body: <p>I have a Postgres DB, with a column named <code>t_time</code> of type <code>timestamp with time zone</code>.</p>
  
  <p>When I use the <code>psql</code> tool to see the contents of the column, I get, for example:</p>
  
  <pre><code>select t_time from table1 where  ...
  
         t_time      
  ---------------------
   2011-02-28 14:09:25
   2011-02-28 14:09:23
  </code></pre>
  
  <p>This is the format I want.</p>
  
  <p>However, when I run the same select query through my Java code, which uses Hibernate, I get the following:</p>
  
  <pre><code> 2011-02-28 14:09:25.0
   2011-02-28 14:09:23.0
  </code></pre>
  
  <p>As you can see, at the end a dot and a zero are added.</p>
  
  <p>My question is - how do I specify the format I want to use?</p>
  
  <p>Changing the query, for example like this, </p>
  
  <pre><code>select to_char(t_time, 'YYYY-MM-DD HH24:MI:ss') as t_time from table1 where ...
  </code></pre>
  
  <p>is possible, but less desired since I have a few places in the code that query for the data and I do not wish to change each of them, I would like the definition to be system-wide.</p>
  
  <p>Thanks for your help.</p>
  
  <hr>
  
  <p>EDIT:</p>
  
  <p>I wanted to add a clarification: When I wrote this, I was thinking of the direction of editing the mapping file. I thought that there might be a way to define the format there. That would mean changing in one place only, and not relying on any default format.</p>
  
  <p>Thanks.</p>