0

In reverse engineering process, I have a requirement to change type of DATE object to SQL Date,for this I have added

<sql-type jdbc-type="DATE" hibernate-type="java.sql.Date">      </sql-type>

in reveng.xml file.

But still Date type is java.util.Date in my pojos.

Even I have added same in Dialect,but no luck

registerHibernateType(Types.DATE, java.sql.Date.class.getName());

But when I mapped Date to String,it seems mapping is working

<sql-type jdbc-type="DATE" hibernate-type="java.lang.String">       </sql-type>

I dont what is wrong with my mapping,please correct me if I am wrong.

Sunil Kumar
  • 5,477
  • 4
  • 31
  • 38
  • Please add your pojo and respected mapping file? and there is a bit confusion for me what i understand is you are trying to get data of DATE (oracle DB type) into java.sql.Date, is that what you trying to do? – Amogh Jul 09 '15 at 19:57
  • Let me explain my requirement,I have a table with a column type is Date. I am generating POJO classes using POJOExporter with above DB configuration and pojos are generating fine.But in my pojos date field is imported as java.util.date and i want date to be java.sql.date.So in my reveng xml i have mapped java.util.date to java.sql.date,but is not working.Hope you are clear. – Sunil Kumar Jul 10 '15 at 05:27

1 Answers1

0

I have resolved this issue by extending pojoFields.ftl file. pojoFields.ftl file is used by hibernate in reverse engineering process to generate java fields of a java class.

Below are the changes did in pojoFields.ftl

<#-- // Fields -->

<#foreach field in pojo.getAllPropertiesIterator()>
<#if pojo.getMetaAttribAsBool(field, "gen-property", true)>
<#if pojo.hasMetaAttribute(field, "field-description")>    /**
${pojo.getFieldJavaDoc(field, 0)}
*/
</#if>
<#assign javaType = pojo.getJavaTypeName(field, jdk5)>
<#if javaType?has_content && javaType == "Date" >
${pojo.getFieldModifiers(field)} java.sql.Date ${field.name}<#if pojo.hasFieldInitializor(field, jdk5)> = ${pojo.getFieldInitialization(field, jdk5)}</#if>;
<#else>
${pojo.getFieldModifiers(field)} ${pojo.getJavaTypeName(field, jdk5)} ${field.name}<#if pojo.hasFieldInitializor(field, jdk5)> = ${pojo.getFieldInitialization(field, jdk5)}</#if>;
</#if>
    </#if>
</#foreach>
Sunil Kumar
  • 5,477
  • 4
  • 31
  • 38