无法确定类型:TIMESTAMP,表:BATCH_JOB_CONFIG_DTLS,列:[org.hibernate.mapping.Column(ADD_USER_DTM)]

Posted

技术标签:

【中文标题】无法确定类型:TIMESTAMP,表:BATCH_JOB_CONFIG_DTLS,列:[org.hibernate.mapping.Column(ADD_USER_DTM)]【英文标题】:Could not determine type for: TIMESTAMP, at table: BATCH_JOB_CONFIG_DTLS, for columns: [org.hibernate.mapping.Column(ADD_USER_DTM)] 【发布时间】:2019-08-19 17:41:01 【问题描述】:
Exception in thread "main" org.hibernate.MappingException: Could not determine type for: TIMESTAMP, at table: BATCH_JOB_CONFIG_DTLS, for columns: [org.hibernate.mapping.Column(ADD_USER_DTM)]
    at org.hibernate.mapping.SimpleValue.getType(SimpleValue.java:486)
    at org.hibernate.mapping.SimpleValue.isValid(SimpleValue.java:453)
    at org.hibernate.mapping.Property.isValid(Property.java:226)
    at org.hibernate.mapping.PersistentClass.validate(PersistentClass.java:624)
    at org.hibernate.mapping.RootClass.validate(RootClass.java:267)
    at org.hibernate.boot.internal.MetadataImpl.validate(MetadataImpl.java:347)
    at org.hibernate.boot.internal.SessionFactoryBuilderImpl.build(SessionFactoryBuilderImpl.java:466)
    at com.hms.api.batch.job.config.StartBatchJobConfigApplication.createSession(StartBatchJobConfigApplication.java:71)
    at com.hms.api.batch.job.config.StartBatchJobConfigApplication.main(StartBatchJobConfigApplication.java:38)

以下是我的代码。在 Main 中调用 createSession() 方法。 我有两个实体类。

我的 hibernate.cfg.xml 中提供了数据库连接

private static void createSession() 

        StandardServiceRegistry s-s-r = new StandardServiceRegistryBuilder().configure("hibernate.cfg.xml").build();
        Metadata meta = new MetadataSources(s-s-r).getMetadataBuilder().build();

        SessionFactory factory = meta.getSessionFactoryBuilder().build();
        Session session = factory.openSession();
        Transaction t = session.beginTransaction();

        SessionFactory fact = meta.getSessionFactoryBuilder().build();
        Session ss = factory.openSession();
        Transaction tt = session.beginTransaction();

        BatchJobConfig config = new BatchJobConfig();

        BatchJobConfigDetails details = new BatchJobConfigDetails();

        Timestamp timestamp = new Timestamp(System.currentTimeMillis());
        System.out.println("timestamp  ->  "+timestamp);

        BatchJobConfigDetails batchJobConfigDtl = new BatchJobConfigDetails(300, 3, "JAVA", date, "JAVA", date, "N",
                "Some Key", "Some value", "FT", "KEY DESCRIPTION", "Y");
        try 
            config.setBatchJobConfigDtl(batchJobConfigDtl);
            config.setAddUserCd("gdfdgdfgdgd");
            config.setBatchJobConfigId(505);
            config.setActiveInd("YYYY");
            config.setAddUserDtm(timestamp);
            config.setDeleteInd("N");
            config.setEndDtm(timestamp);
            config.setJobDesc("DESCRIPTION");
            config.setJobNm("JOB NAME");
            config.setJobType("Job Type");
            config.setLastUpdtDtm(timestamp);
            config.setLastUpdtUserCd("someone");
            config.setStatus("COMPLETED");
            config.setStartDtm(timestamp);
            ss.save(config);
            tt.commit();
            System.out.println("config session saved");

         catch (HibernateException exception) 
            System.out.println("Problem creating session factory!!!!!!!!!!");
            exception.printStackTrace();
         finally 
            fact.close();
            ss.close();
        

        try 
            details.setAddUserCd("fffffffffffffffffffff");
            details.setAddUserDtm(timestamp);           
            details.setBusinessUpdtInd("dssssssss");
            details.setDeleteInd("NNNNNNNNN");
            details.setKeyDataType("ggggggggggggg");
            details.setKeyDesc("Description.......");
            details.setKeyNm("some key name");
            details.setKeyVal("someval");
            details.setLastUpdtDtm(timestamp);
            details.setLastUpdtUserCd("last user");
            BatchJobConfig batchJobConfig = new BatchJobConfig(1L, "JAVA", date, "C#", date, "N", "MissingCK",
                    "JOB DESCRIPTION", "FT", date, date, "COMPLETED", "Y");
            List<BatchJobConfig> b = null;
            b.add(batchJobConfig);
            details.setBatchJobConfigs(b);
            session.save(details);
            t.commit();
            System.out.println("details session saved");

         catch (HibernateException exception) 
            System.out.println("Problem creating session factory....");
            exception.printStackTrace();
         finally 
            factory.close();
            session.close();
        

    

batchJob.hbm.xml

<?xml version = "1.0" encoding = "utf-8"?>
<!DOCTYPE hibernate-mapping PUBLIC 
"-//Hibernate/Hibernate Mapping DTD//EN"
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">

<hibernate-mapping>
    <class name="BatchJobConfig" table="BATCH_JOB_CONFIG">

        <meta attribute="class-description">
            This class contains the BATCH_JOB_CONFIG.
        </meta>

        <id name="batchJobConfigId" type="int" column="BATCH_JOB_CONFIG_ID">
            <generator class="native" />
        </id>

        <property name="addUserCd" column="ADD_USER_CD" type="string" />
        <property name="addUserDtm" column="ADD_USER_DTM" type="TIMESTAMP" />
        <property name="lastUpdtUserCd" column="LAST_UPDT_USER_CD"
            type="string" />
        <property name="lastUpdtDtm" column="LAST_UPDT_DTM" type="TIMESTAMP" />
        <property name="deleteInd" column="DELETE_IND" type="string" />
        <property name="jobNm" column="JOB_NM" type="string" />
        <property name="jobDesc" column="JOB_DESC" type="string" />
        <property name="jobType" column="JOB_TYPE" type="string" />
        <property name="startDtm" column="START_DTM" type="TIMESTAMP" />
        <property name="status" column="STATUS" type="string" />
        <property name="endDtm" column="END_DTM" type="TIMESTAMP" />
        <property name="activeInd" column="ACTIVE_IND" type="string" />

        <many-to-one name="BatchJobConfigDetails" column="BATCH_JOB_CONFIG_ID"
            class="BatchJobConfigDetails" not-null="true" />

    </class>

    <class name="BatchJobConfigDetails" table="BATCH_JOB_CONFIG_DTLS">

        <meta attribute="class-description">
            This class contains the BATCH_JOB_CONFIG_DETAILS.
        </meta>

        <id name="batchJobConfigDtlsId" type="int" column="BATCH_JOB_CONFIG_DTLS_ID">
            <generator class="native" />
        </id>

        <property name="batchJobConfigId" column="BATCH_JOB_CONFIG_ID"
            type="int" />
        <property name="addUserCd" column="ADD_USER_CD" type="string" />
        <property name="addUserDtm" column="ADD_USER_DTM" type="TIMESTAMP" />
        <property name="businessUpdtInd" column="BUSINESS_UPDT_IND"
            type="int" />
        <property name="deleteInd" column="DELETE_IND" type="string" />
        <property name="keyDataType" column="KEY_DATA_TYPE" type="string" />
        <property name="keyDesc" column="KEY_DESC" type="string" />
        <property name="keyNm" column="KEY_NM" type="string" />
        <property name="keyVal" column="KEY_VAL" type="string" />
        <property name="lastUpdtDtm" column="LAST_UPDT_DTM" type="TIMESTAMP" />
        <property name="lastUpdtUserCd" column="LAST_UPDT_USER_CD" type="string" />

    </class>

</hibernate-mapping>

并在 DB2 数据库中创建了两个这样的表。

我的项目是 spring-boot REST API GET all、GET 1 和 PUT 操作。请看一下,让我知道我在哪里犯了错误。提前谢谢!!!!

【问题讨论】:

问题已解决。谢谢MS90!!通过将 TIMESTAMP(大写)更改为时间戳(小写) 很高兴它有帮助!我想写信给 cmets,但却写了一个答案。 @蒂蒂 我也是。它不允许我发表评论,所以我写了一个答案 知道了。完毕。谢谢 现在我的异常是线程“main” org.hibernate.MappingException 中的异常:实体映射中的重复列:BatchJobConfig 列:BATCH_JOB_CONFIG_ID(应该使用 insert="false" update="false" 进行映射) at org.hibernate.mapping.PersistentClass.checkColumnDuplication(PersistentClass.java:862) at org.hibernate.mapping.PersistentClass.checkPropertyColumnDuplication(PersistentClass.java:880) .. 你能看到问题吗? 【参考方案1】:

在您的 hbm.xml 文件中放置所有小写字母“时间戳”而不是大写字母。比如:

<property name="addUserDtm" column="ADD_USER_DTM" type="timestamp" />

【讨论】:

以上是关于无法确定类型:TIMESTAMP,表:BATCH_JOB_CONFIG_DTLS,列:[org.hibernate.mapping.Column(ADD_USER_DTM)]的主要内容,如果未能解决你的问题,请参考以下文章

无法在 Azure Databricks 中创建具有 TIMESTAMP 数据类型的 Hive 表

BigQuery:无法将 TIMESTAMP_MICROS 类型的字段“stamp”读取为 DATETIME

spring batch中MyBatisPagingItemReader分页使用介绍

无法比较 to_char(timestamp, 'day') = 'monday'

Spring Batch No serializer found for class java.io.ByteArrayInputStream for oracle.sql.TIMESTAMP

通过查看编码映射表确定编码类型