Caused by: org.hibernate.MappingException: Could not determine type for: Timestamp, for columns: [org.hibernate.mapping.Column(***)]

余生长醉 提交于 2019-12-12 04:08:28

问题


Using hibernate.. I am learning the technology at the moment.. Not sure where I m wrong...Pls guide on this..

I see the above error when trying to map a column from db of type - TIMESTAMP() to Pojo variable... I tried changing the variable type to Date...Calendar...Timestamp.. Nothing works here... The issue is seems to be with the mapping for the column... Any help on this is much appreciated...

My pojo class:

public class Pojo_****
{ ......... 
private Date C_TimeStamp; 
private Date L_TimeStamp;
}

My DB table:

Table_****
    ..........
    C_TimeStamp TIMESTAMP(6)
    L_TimeStamp TIMESTAMP(6)

My configuration xml:

 Pojo_****.hbm.xml
        ......
        <property name="C_TimeStamp" column="C_TimeStamp" />
        <property name="L_TimeStamp" column="L_TimeStamp" />

Error Logs:

In Main method of MainApp...
Mar 9, 2016 2:48:14 PM org.hibernate.cfg.Environment <clinit>
INFO: Hibernate 3.2 cr4
Mar 9, 2016 2:48:14 PM org.hibernate.cfg.Environment <clinit>
INFO: hibernate.properties not found
Mar 9, 2016 2:48:14 PM org.hibernate.cfg.Environment buildBytecodeProvider
INFO: Bytecode provider name : cglib
Mar 9, 2016 2:48:14 PM org.hibernate.cfg.Environment <clinit>
INFO: using JDK 1.4 java.sql.Timestamp handling
Mar 9, 2016 2:48:15 PM org.hibernate.cfg.Configuration configure
INFO: configuring from resource: hibernate.cfg.xml
Mar 9, 2016 2:48:15 PM org.hibernate.cfg.Configuration getConfigurationInputStream
INFO: Configuration resource: hibernate.cfg.xml
Mar 9, 2016 2:48:15 PM org.hibernate.cfg.Configuration addResource
INFO: Reading mappings from resource: Pojo_****.hbm.xml
Mar 9, 2016 2:48:15 PM org.hibernate.cfg.HbmBinder bindRootPersistentClassCommonValues
INFO: Mapping class: Pojo_****-> Table_****
Mar 9, 2016 2:48:15 PM org.hibernate.cfg.Configuration doConfigure
INFO: Configured SessionFactory: null
Failed to create sessionFactory object.org.hibernate.MappingException: Could not determine type for: Timestamp, for columns: [org.hibernate.mapping.Column(L_TimeStamp)]
Exception in thread "main" java.lang.ExceptionInInitializerError
    at tutorialspoint.example.MainApp.main(MainApp.java:29)
Caused by: org.hibernate.MappingException: Could not determine type for: Timestamp, for columns: [org.hibernate.mapping.Column(L_TimeStamp)]
    at org.hibernate.mapping.SimpleValue.getType(SimpleValue.java:266)
    at org.hibernate.mapping.SimpleValue.isValid(SimpleValue.java:253)
    at org.hibernate.mapping.Property.isValid(Property.java:185)
    at org.hibernate.mapping.PersistentClass.validate(PersistentClass.java:410)
    at org.hibernate.mapping.RootClass.validate(RootClass.java:192)
    at org.hibernate.cfg.Configuration.validate(Configuration.java:1026)
    at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1211)
    at tutorialspoint.example.MainApp.main(MainApp.java:21)

回答1:


Try this out to fill the DateTime to the Variable. I Faced Same Problem in Project Got Resolved by this.

  Pojo_Class obj_Pojo = new Pojo();

try {
            //Or Pass any Date Object.
        obj_Pojo.setC_TimeStamp(new SimpleDateFormat("yyyy/MM/dd HH:mm:ss").parse(String.valueOf(new Date().getTime()))); 

    } catch (ParseException e) {
        v_objBorrower.setCreationDate(new Date());
    }

Note: - Change your Database Column as DateTime. This might help you out. If any configuration issue is not there.




回答2:


Did you try adding the type="timestamp" in your .hbm.xml file, like this?

<property name="C_TimeStamp" column="C_TimeStamp" type="timestamp" />
<property name="L_TimeStamp" column="L_TimeStamp" type="timestamp" />

As far as I know Time isn't considered basic type in xml configuration and should be therefore part of the mapping file.



来源:https://stackoverflow.com/questions/35888301/caused-by-org-hibernate-mappingexception-could-not-determine-type-for-timesta

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!