【问题标题】:Caused by: org.hibernate.MappingException: Could not determine type for: Timestamp, for columns: [org.hibernate.mapping.Column(***)]引起:org.hibernate.MappingException:无法确定类型:时间戳,列:[org.hibernate.mapping.Column(***)]
【发布时间】:2016-06-23 15:12:23
【问题描述】:

使用休眠..我现在正在学习技术..不确定我错在哪里...请指导..

我在尝试将 TIMESTAMP() 类型的 db 中的列映射到 Pojo 变量时看到上述错误... 我尝试将变量类型更改为 Date...Calendar...Timestamp.. 这里没有任何作用... 问题似乎与列的映射有关......非常感谢任何帮助......

我的 pojo 课:

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

我的数据库表:

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

我的配置 xml:

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

错误日志:

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)

【问题讨论】:

    标签: java mysql oracle hibernate mappingexception


    【解决方案1】:

    尝试将 DateTime 填充到变量中。我在项目中遇到了同样的问题得到了解决。

      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());
        }
    

    注意:将您的数据库列更改为DateTime。如果不存在任何配置问题,这可能会对您有所帮助。

    【讨论】:

    • 我尝试从我的主要方法中注释掉打印这些字段......并使用其他类型的变量 - string/int... 以及来自 pojo 类/ **** hbm。 xml 文件...但问题存在...
    【解决方案2】:

    您是否尝试像这样在 .hbm.xml 文件中添加 type="timestamp"?

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

    据我所知 Time 在 xml 配置中不被视为基本类型,因此应该是映射文件的一部分。

    【讨论】:

    • 代码 sn-p 1: 代码 sn-p 2: 上述代码 sn-ps 的用途相同。有/没有明确提及类型。我按照你的建议尝试执行,再次得到同样的错误......
    猜你喜欢
    • 2016-08-28
    • 1970-01-01
    • 2013-03-28
    • 2016-06-05
    • 2011-04-16
    • 2016-10-04
    • 1970-01-01
    • 2019-02-18
    • 2013-01-25
    相关资源
    最近更新 更多