简体   繁体   English

将Hibernate 3.2.5迁移到3.6

[英]Migrating Hibernate 3.2.5 to 3.6

Currently We are facing a lot of problem in migrating our Application from Hibernate 3.2.5 to 3.6.1. 目前,我们在将应用程序从Hibernate 3.2.5迁移到3.6.1时遇到了很多问题。

The first error that We are facing is : 我们面临的第一个错误是:

SEVERE: Invalid column name 'btn_name'. 严重:列名'btn_name'无效。 Although btn_name is mapped no where. 虽然btn_name没有映射到哪里。 The actual mapping is btnName. 实际的映射是btnName。

Here is my mapping file 这是我的映射文件

<hibernate-mapping>
    <class abstract="true" name="com.sampleproject.client.beansdm.metadata.Component"
        table="component_master">
        <id column="metadata_id" name="id" type="long">
            <generator class="native" />
        </id>
        <property column="metadata_type" name="type" type="string" />
        <property name="createdDateTime" column="created_date" type="date"
            update="false"></property>
        <property name="version" type="string" column="version_id"></property>
        <property name="currentDate" type="date" column="curr_date"></property>
        <property name="currentIP" type="string" column="current_ip"></property>
        <many-to-one name="currentUser"
            class="com.sampleproject.client.beansdm.domain.common.User" cascade="refresh"
            column="current_user_id"></many-to-one>
        <property name="latestDate" type="date" column="latest_date"></property>
        <property name="latestIP" type="string" column="latest_ip"></property>
        <many-to-one name="latestUser"
            class="com.sampleproject.client.beansdm.domain.common.User" cascade="refresh"
            column="latest_user"></many-to-one>
        <property name="recordStatus" type="boolean" column="record_status"></property>
        <property name="portal" type="string" column="portal"></property>
        <many-to-one cascade="refresh,save-update,delete"
            class="com.sampleproject.client.beansdm.metadata.Component" column="md_id"
            name="metadata" not-null="false" />

        <joined-subclass
            name="com.sampleproject.client.beansdm.metadata.uicontrols.UIControl"
            table="ui_control_master">
            <key column="ui_control_id" />
            <property column="display_name" name="displayText" />
            <property column="help_text" name="helpText" />
            <property column="info_text" name="informativeText" />
            <property column="rows" name="rows" type="integer" />
            <property column="cols" name="cols" type="integer" />
            <property column="btnName" name="btnName" type="string" />
            <property name="version" type="string" column="version_id"></property>
            <property name="currentDate" type="date" column="curr_date"></property>
            <property name="currentIP" type="string" column="current_ip"></property>
            <many-to-one name="currentUser"
                class="com.sampleproject.client.beansdm.domain.common.User" cascade="refresh"
                column="current_user_id"></many-to-one>
            <property name="latestDate" type="date" column="latest_date"></property>
            <property name="latestIP" type="string" column="latest_ip"></property>
            <many-to-one name="latestUser"
                class="com.sampleproject.client.beansdm.domain.common.User" cascade="refresh"
                column="latest_user"></many-to-one>
            <property name="recordStatus" type="boolean" column="record_status"></property>
            <property name="portal" type="string" column="portal"></property>
            <property name="readOnly" type="boolean" column="read_only"/>

            <joined-subclass
                name="com.sampleproject.client.beansdm.metadata.uicontrols.InputControl"
                table="input_control_master" lazy="true">
                <key column="input_control_id" />
                <property column="default_value" name="defaultValue"
                    not-null="false" />
                <property column="is_fk" name="fk" />
                <property column="validatable" name="validatable" />
                <property column="violatable" name="violatable" />
                <property name="isRequired" column="is_required"></property>
                <property name="ruleType"
                    type="com.sampleproject.facadeimplementation.util1.UserEnumRuleType"
                    column="rule_type"></property>
                <property name="fileType" column="file_type"></property>
                <property name="maxFileSize" column="max_file_size" type="integer"></property>
                <property name="precision" column="input_precision" type="integer"></property>
                <property name="maxLength" column="maxlength" type="integer"></property>
                <property name="minLength" column="minlength" type="integer"></property>
                <property name="dateFormatType" column="dateformat"
                    type="com.sampleproject.facadeimplementation.util1.UserEnumDateFormatType"></property>
                <property name="specialCharAllow" column="isspecialcharallow"></property>
                <property name="specialChars" column="specialchars" type="string"></property>
                <property name="dateType"
                    type="com.sampleproject.facadeimplementation.util1.UserEnumDateType"
                    column="date_type"></property>
                <property name="minDate" column="mindate" type="string"></property>
                <property name="maxDate" column="maxdate" type="string"></property>
                <property name="inspection" column="inspection" type="boolean"></property>
                <property name="values" column="default_values" type="string"></property>
                <property name="targetNames" column="target_names" type="string"></property>
                <!--
                    <many-to-one cascade="save-update, delete"
                    class="com.sampleproject.client.beansdm.metadata.Column"
                    column="target_column_id" name="targetColumn" />
                -->
                <property name="targetColumn" column="target_column" type="string"></property>
                <property name="templateName" column="template_name" type="string"></property>
                <!--
                    <bag name="targetColumnNames" cascade="save-update"
                    table="input_possible_columns_map"> <key
                    column="input_control_id"></key> <element column="column_name"
                    not-null="true" type="string" /> </bag>
                -->
                <!--<bag name="possibleValues" cascade="save-update" table="input_possible_values_map">
                    <key column="input_control_id" />
                    <many-to-many
                        class="com.sampleproject.client.beansdm.metadata.uicontrols.PossibleValue"
                        column="value" />
                </bag>
                --><property name="seperator" column="seperator" type="string" />
                <many-to-one name="refTable" cascade="refresh"
                    class="com.sampleproject.client.beansdm.metadata.Table" column="ref_table_id" lazy="false">
                </many-to-one>
                <many-to-one name="targetTable" cascade="refresh"
                    class="com.sampleproject.client.beansdm.metadata.Table" column="target_table_id" />
                <property name="version" type="string" column="version_id"></property>
                <property name="currentDate" type="date" column="curr_date"></property>
                <property name="currentIP" type="string" column="current_ip"></property>
                <many-to-one name="currentUser"
                    class="com.sampleproject.client.beansdm.domain.common.User" cascade="refresh"
                    column="current_user_id"></many-to-one>
                <property name="latestDate" type="date" column="latest_date"></property>
                <property name="latestIP" type="string" column="latest_ip"></property>
                <many-to-one name="latestUser"
                    class="com.sampleproject.client.beansdm.domain.common.User" cascade="refresh"
                    column="latest_user"></many-to-one>
                <property name="recordStatus" type="boolean" column="record_status"></property>
                <property name="portal" type="string" column="portal"></property>
                <many-to-one name="linkedColumn" cascade="refresh"
                    class="com.sampleproject.client.beansdm.metadata.Column" column="linked_column_name">
                </many-to-one>
                <many-to-one name="linkedMasterColumn" cascade="refresh"
                    class="com.sampleproject.client.beansdm.metadata.Column" column="linked_master_column">
                </many-to-one>
                <many-to-one name="linkedTable" cascade="refresh"
                    class="com.sampleproject.client.beansdm.metadata.Table" column="linked_master_id">
                </many-to-one>
            </joined-subclass>
        </joined-subclass>
    </class>
</hibernate-mapping>

Focus on com.sampleproject.client.beansdm.metadata.uicontrols.InputControl joined-subclass mapping there is a field named btnName. 专注于com.sampleproject.client.beansdm.metadata.uicontrols.InputControl的join-subclass mapping有一个名为btnName的字段。 Its working fine with 3.2.5 version but when i changed it to newer hibernate version it stops responding. 它与3.2.5版本的工作正常,但当我把它改为更新的hibernate版本时它停止响应。

Is there any possible jar conflicts ? 有没有可能的jar冲突?

Please help. 请帮忙。

Thanking You, Regards, 感谢你,问候,

The Hibernate Version Comparison guide states when moving from 3.5 to 3.6 that: Hibernate版本比较指南指出从3.5移动到3.6时:

However, for users still using hbm.xml you should be aware that we chose to use the org.hibernate.cfg.EJB3NamingStrategy used in AnnotationConfigration instead of the older org.hibernate.cfg.DefaultNamingStrategy historically used on Configuration. 但是,对于仍在使用hbm.xml的用户,您应该知道我们选择使用AnnotationConfigration中使用的org.hibernate.cfg.EJB3NamingStrategy而不是历史上在Configuration上使用的旧的org.hibernate.cfg.DefaultNamingStrategy。 This may cause naming mismatches; 这可能会导致命名不匹配; one known place where this is an issue is if you rely on the naming strategy to default the name of a association (many-to-many and collections of elements) table. 这是一个问题的一个已知位置是,如果您依赖命名策略来默认关联的名称 (多对多和元素集合)表。 If you find yourself in this situation, you can tell Hibernate to use the the legacy org.hibernate.cfg.DefaultNamingStrategy by calling Configuration#setNamingStrategy and passing it org.hibernate.cfg.DefaultNamingStrategy#INSTANCE 如果您发现自己处于这种情况,可以通过调用Configuration#setNamingStrategy并将其传递给org.hibernate.cfg.DefaultNamingStrategy #INSTANCE来告诉Hibernate使用旧版org.hibernate.cfg.DefaultNamingStrategy。

The NamingStrategy interface defines several methods like String foreignKeyColumnName(String propertyName, String propertyEntityName, String propertyTableName, String referencedColumnName) used to determine the names of columns and associations which are implemented by the EJB3NamingStrategy . NamingStrategy接口定义了几个方法,如String foreignKeyColumnName(String propertyName, String propertyEntityName, String propertyTableName, String referencedColumnName)用于确定EJB3NamingStrategy实现的列和关联的名称。 I suggest you look at the implementation of these methods in the EJB3NamingStrategy class and see how it is transforming property names to column names. 我建议你看一下EJB3NamingStrategy类中这些方法的实现,看看它是如何将属性名转换为列名的。

It looks like hibernate is now adding the underscores to what it expects the column name to be in the DB via one these transformations, and is upset when it can't find the resultant column name 'btn_name' in your database. 看起来hibernate现在通过这些转换将下划线添加到它希望列名在DB中的内容,并且当它在数据库中找不到结果列名'btn_name'时会感到不安。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM