@Type annotation in Hibernate does not work. I am using @SQLInsert

I have a model class in sleep mode with a field of type Calendar. The corresponding DB column has a timeline (6). I am using custom @SQLInsert. The class looks lower -

@Entity
@SQLInsert("insert into EMPLOYEE (STARTDATETIME) values (TO_TIMESTAMP_TZ(?,'DD-     MM-YY HH.MI.SS PM TZHTZM '))" )
@Table(
    name = "EMPLOYEE",
     )
public class Employee {
@Column(
        name = "STARTDATETIME",
        nullable = false
       )
@Type(type = "com.myPackage.TimeStampTypeImpl")
private Calendar startDateTime;

public Calendar getStartDateTime() {
    return this.startDateTime;        
}

public void setStartDateTime(Calendar startDateTime) {
    this.startDateTime = startDateTime;

}
}

In the TimeStampTypeImpl class that implements Usertype, the necessary conversion of the Calendar to the appropriate string, which must be specified in the input parameter of the insert request, in the nullSafeSet method is performed. But the problem I am getting - it seems that the custome TimestampImpl class is not working - the nullSafeSet method is not called. Therefore, the insert request does not work.

The libraries I use are

Hibernate, for Wikimedia Commons annotations-4.0.1.Final-RedHat-2.jar

hibernation-kernel-4.2.7.SP1-RedHat-3.jar

hibernation-jpa-2.0-api-1.0.1. final-redhat-2.jar

TimeStampTypeImpl:

    public void nullSafeSet(PreparedStatement st, Object value, int index)
        throws HibernateException, SQLException {

    Calendar cal = (Calendar) value;
    log.debug("TIMESTAMPIMPL2");
    tring dateTime = getOracleFormattedTimeWithZone(cal);
    log.debug("TIMESTAMPIMPL3");
    st.setString(index, dateTime);

}

    private static String getOracleFormattedTimeWithZone(Calendar timeWithZone) {

    String dateFormat = "dd-MM-yy hh.mm.ss a Z";
    DateFormat df = new SimpleDateFormat(dateFormat);
    String dateTime = df.format(timeWithZone.getTime());
    System.out.println("()()()()()()()()()"+dateTime);
    return dateTime;

}

+4

All Articles