title: UTC Time is not getting stored in oracle column(TIMESTAMP WITH TIMEZONE) using JPA
body: <p>I am getting UTC time in string format that we need to persist into database.</p>
  
  <p>from UTC datetime string Calender object created using below code.</p>
  
  <pre><code>DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ssZ");
  
          OffsetDateTime dateTime = OffsetDateTime.parse(rqTime,formatter);
  
          System.out.println(dateTime);
  
          Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
          cal.setTime(Date.from(dateTime.toInstant()));
  </code></pre>
  
  <p>Then set above created calender instance to JPA</p>
  
  <pre><code>        EventDetails eventDetails = new EventDetails();
          eventDetails.setTimeWithZone(cal);
          event.insertEventDetails(eventDetails);
  </code></pre>
  
  <p>Entity class information </p>
  
  <pre><code>@Entity
  @Table(name="mytimestamptz")
  public class EventDetails implements Serializable{
      private static final long serialVersionUID = 1L;
  
  @Column(name ="made_on" , columnDefinition = "TIMESTAMP WITH TIME ZONE")
  @Type(type="com.elitecore.isl.bl.xlink.custom.UTCCalendarType")
  private Calendar timeWithZone ; 
  
  @Id
  @SequenceGenerator(name = "generator", sequenceName = "SEQ_EVENTID", allocationSize = 1)
  @Column(name ="id")
  @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "generator")
  private Long id;
  </code></pre>
  
  <p>This code insert UTC DAte String "2016-01-01T13:14:15+0000" as "01-JAN-2016 13:14:15 +0530" in database even if we have specified the timezone information (Refer UTCCalendarType).</p>
  
  <p>UTCCalendarType created to store datetime in UTC format in database </p>
  
  <pre><code>public class UTCCalendarType extends CalendarType {
  
  /**
   * 
   */
  private static final long serialVersionUID = 1L;
  private static final TimeZone UTC = TimeZone.getTimeZone("UTC");
  
  /**
   * This is the original code from the class, with two changes. First we pull
   * it out of the result set with an example Calendar. Second, we set the new
   * calendar up in UTC.
   */
  @Override
  public Object get(ResultSet rs, String name) throws SQLException {
      Timestamp ts = rs.getTimestamp(name, new GregorianCalendar(UTC));
      if (ts != null) {
          Calendar cal = new GregorianCalendar(UTC);
          cal.setTime(ts);
          return cal;
      } else {
          return null;
      }
  }
  
  @Override
  public void set(PreparedStatement st, Object value, int index) throws SQLException {
      final Calendar cal = (Calendar) value;
      cal.setTimeZone(UTC);
  
      System.out.println("IST TIME : "+cal.getTime());
  
      st.setTimestamp(index, new Timestamp(cal.getTime().getTime()),Calendar.getInstance(UTC));
  
  }
  </code></pre>
  
  <p>}</p>
  
  <p>I am not getting whats going wrong in this code.
  why it is storing ASIA/KOLKATA TIMEZONE in database.
  Kindly provide valuable input on this.</p>