开发者

Migrating Hibernate 3.2.5 to 3.6

开发者 https://www.devze.com 2023-02-16 18:29 出处:网络
Currently We are facing a lot of problem in migrating our Application from Hibernate 3.2.5 to 3.6.1. The first error that We are facing is :

Currently We are facing a lot of problem in migrating our Application from Hibernate 3.2.5 to 3.6.1.

The first error that We are facing is :

SEVERE: Invalid column name 'btn_name'. Although btn_name is mapped no where. The actual mapping is 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>
         开发者_Go百科       --><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. Its working fine with 3.2.5 version but when i changed it to newer hibernate version it stops responding.

Is there any possible jar conflicts ?

Please help.

Thanking You, Regards,


The Hibernate Version Comparison guide states when moving from 3.5 to 3.6 that:

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. 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

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. 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.

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号