I am trying to upgrade the Hibernate version of our project from 4.3 to 5.2.I have gone through the steps required for upgrading by going through the following documents
https://github.com/hibernate/hibernate-orm/blob/5.0/migration-guide.adoc
and the upgrade documents for other releases as well.
However after making the required changes, i am facing some runtime errors.
I took a very simple example model, where in my EntityModel looks like this:
EntityMetamodel(cemployees_create:[Attribute(name=LastName, type=string [non-identifier]),Attribute(name=FirstName, type=string [non-identifier]),Attribute(name=BirthDate, type=timestamp [non-identifier]),Attribute(name=HireDate, type=timestamp [non-identifier]),Attribute(name=Photo, type=binary [non-identifier]),Attribute(name=ReportsTo, type=cemployees_create [non-identifier,association]),Attribute(name=ReporteesArr, type=java.util.Collection(cemployees_create.ReporteesArr) [non-identifier,association])])
However in version 5.2 when its trying to buildAttribute in AttributeFactory.java, its throwing the following exception:
java.lang.IllegalArgumentException: Expecting collection type [org.hibernate.type.BagType]
at org.hibernate.metamodel.internal.AttributeFactory.determineCollectionType(AttributeFactory.java:937)
at org.hibernate.metamodel.internal.AttributeFactory$PluralAttributeMetadataImpl.<init>(AttributeFactory.java:786)
at org.hibernate.metamodel.internal.AttributeFactory$PluralAttributeMetadataImpl.<init>(AttributeFactory.java:767)
at org.hibernate.metamodel.internal.AttributeFactory.determineAttributeMetadata(AttributeFactory.java:548)
at org.hibernate.metamodel.internal.AttributeFactory.buildAttribute(AttributeFactory.java:77)
at org.hibernate.metamodel.internal.MetadataContext.wrapUp(MetadataContext.java:213)
at org.hibernate.metamodel.internal.MetamodelImpl.initialize(MetamodelImpl.java:220)
at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:297)
at org.hibernate.boot.internal.SessionFactoryBuilderImpl.build(SessionFactoryBuilderImpl.java:452)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:710)
This is happening when its trying to build the Attribute for
Attribute(name=ReporteesArr, type=java.util.Collection(cemployees_create.ReporteesArr) [non-identifier,association])])
Just wanted to check if someone has faced this problem before or if there are any resolutions to it. The same thing works perfectly fine with Hibernate 4.3
Adding the hibernate Entity Mapping file as well:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="cfsuite.orm.manual.relationship.self_join">
<class entity-name="cemployees" table="Employees">
<tuplizer class="coldfusion.orm.hibernate.CFCTuplizer" entity-mode="dynamic-map"/>
<id column="EmployeeID" name="EmployeeID" type="integer">
<generator class="native"/>
</id>
<property column="LastName" name="LastName" type="string"/>
<property column="FirstName" name="FirstName" type="string"/>
<property column="Title" name="Title" type="string"/>
<property column="TitleOfCourtesy" name="TitleOfCourtesy" type="string"/>
<property column="BirthDate" name="BirthDate" type="date"/>
<property column="HireDate" name="HireDate" type="date"/>
<property column="Address" name="Address" type="string"/>
<property column="City" name="City" type="string"/>
<property column="Region" name="Region" type="string"/>
<property column="PostalCode" name="PostalCode" type="string"/>
<property column="Country" name="Country" type="string"/>
<property column="HomePhone" name="HomePhone" type="string"/>
<property column="Extension" name="Extension" type="string"/>
<property column="Photo" name="Photo" type="binary"/>
<property column="Notes" name="Notes" type="string"/>
<many-to-one column="ReportsTo" entity-name="cemployees" name="ReportsToObj"/>
<property column="PhotoPath" name="PhotoPath" type="string"/>
<bag cascade="all-delete-orphan" name="ReporteesArr">
<key column="ReportsTo"/>
<one-to-many entity-name="cemployees"/>
</bag>
</class>
</hibernate-mapping>
Related
I have three persistent classes named:shops.class,user.class,vehicle.class and three hibernate mapping file shops.hbm.xml,users.hbm.xml,vehicle.hbm.xml
But i am getting following error in my users and vehicle mappingg file:
The content of element type "class" must match
"(meta*,subselect?,cache?,synchronize*,comment?,tuplizer*,(id|composite-id),discriminator?,natural-id?,(version|timestamp)?,(property|many-to-one|one-to-one|component|dynamic-component|properties|any|map|set|list|bag|idbag|array|primitive-array)*,((join*,subclass*)|joined-subclass*|union-subclass*),loader?,sql-insert?,sql-update?,sql-delete?,filter*,fetch-profile*,resultset*,(query|sql-query)*)".
shops.hbm.xml:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated Jun 7, 2017 2:04:29 PM by Hibernate Tools 3.4.0.CR1 -->
<hibernate-mapping>
<class name="persistent_classes.shops" table="SHOPS">
<id name="id" type="int">
<column name="ID" />
<generator class="increment" />
</id>
<version name="version_id" type="int" unsaved-value="undefined">
<column name="VERSION_ID" />
</version>
<property name="name" type="java.lang.String">
<column name="NAME" />
</property>
<property name="address" type="java.lang.String">
<column name="ADDRESS" />
</property>
<property name="city" type="java.lang.String">
<column name="CITY" />
</property>
<property name="dealername" type="java.lang.String">
<column name="DEALERNAME" />
</property>
<property name="dealerno" type="java.lang.String">
<column name="DEALERNO" />
</property>
<property name="dealeremail" type="java.lang.String">
<column name="DEALEREMAIL" />
</property>
<property name="password" type="java.lang.String">
<column name="PASSWORD" />
</property>
<property name="shops_string" type="java.lang.String">
<column name="SHOPS_STRING" />
</property>
<property name="login" type="boolean">
<column name="LOGIN" />
</property>
<list name="vehicles" inverse="false" table="VEHICLE" lazy="true">
<key>
<column name="store_id" />
</key>
<list-index></list-index>
<one-to-many class="persistent_classes.vehicle" />
</list>
<map name="users" table="SHOPS_MAP" lazy="true">
<key>
<column name="ID" />
</key>
<map-key type="java.lang.Integer"></map-key>
<element type="java.lang.Integer">
<column name="USERS" />
</element>
</map>
</class>
</hibernate-mapping>
vehicle.hbm.xml:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated Jun 7, 2017 2:04:29 PM by Hibernate Tools 3.4.0.CR1 -->
<hibernate-mapping>
<class name="persistent_classes.vehicle" table="VEHICLE">
<id name="id" type="int">
<column name="ID" />
<generator class="increment" />
</id>
<property name="stock" type="int">
<column name="STOCK" />
</property>
<version name="version_id" type="int" unsaved-value="undefined">
<column name="VERSION_ID" />
</version>
<property name="name" type="java.lang.String">
<column name="NAME" />
</property>
<property name="company" type="java.lang.String">
<column name="COMPANY" />
</property>
<property name="milage" type="java.lang.String">
<column name="MILAGE" />
</property>
<property name="year" type="java.lang.String">
<column name="YEAR" />
</property>
<property name="priceoriginal" type="java.lang.String">
<column name="PRICEORIGINAL" />
</property>
<property name="priceoffer" type="java.lang.String">
<column name="PRICEOFFER" />
</property>
<property name="vehicle_string" type="java.lang.String">
<column name="VEHICLE_STRING" />
</property>
</class>
</hibernate-mapping>
users.hbm.xml:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated Jun 7, 2017 2:04:40 PM by Hibernate Tools 3.4.0.CR1 -->
<hibernate-mapping>
<class name="persistent_classes.users" table="USERS">
<id name="id" type="int">
<column name="ID" />
<generator class="increment" />
</id>
<map name="points" table="user_points" cascade="all">
<key column="user_id" />
<index column="shop_id" type="integer"></index>
<element column="points" type="string"></element>
</map>
<version name="version_id" type="int" unsaved-value="undefined">
<column name="VERSION_ID" />
</version>
<property name="login" type="boolean">
<column name="LOGIN" />
</property>
<property name="name" type="java.lang.String">
<column name="NAME" />
</property>
<property name="password" type="java.lang.String">
<column name="PASSWORD" />
</property>
<property name="email" type="java.lang.String">
<column name="EMAIL" />
</property>
<property name="mobno" type="java.lang.String">
<column name="MOBNO" />
</property>
<property name="address" type="java.lang.String">
<column name="ADDRESS" />
</property>
<property name="users_string" type="java.lang.String">
<column name="USERS_STRING" />
</property>
</class>
</hibernate-mapping>
I know this question is asked many times but all of that were related to not using tag. But i had used this tag in all files but still getting this error in users and vehicle file.
Please Help i am badly stuck with this.
Thanks in advance
version must be defined before property and map
Move it to be right after id definition in the users and vehicle hbm
<generator class="increment" />
<id name="id" />
<property name="movie" />
<property name="showtimes" />
<property name="seatno" />
</class>
Exception
ERROR: HHH000196: Error parsing XML (2) : The content of element type "class" must match "(meta*,subselect?,cache?,synchronize*,comment?,tuplizer*,(id|composite-id),discriminator?,natural-id?,(version|timestamp)?,(property|many-to-one|one-to-one|component|dynamic-component|properties|any|map|set|list|bag|idbag|array|primitive-array)*,((join*,subclass*)|joined-subclass*|union-subclass*),loader?,sql-insert?,sql-update?,sql-delete?,filter*,fetch-profile*,resultset*,(query|sql-query)*)".
Exception in thread "main" org.hibernate.InvalidMappingException: Unable to read XML
at org.hibernate.internal.util.xml.MappingReader.legacyReadMappingDocument(MappingReader.java:375)
at org.hibernate.internal.util.xml.MappingReader.readMappingDocument(MappingReader.java:304)
at org.hibernate.cfg.Configuration.add(Configuration.java:516)
at org.hibernate.cfg.Configuration.add(Configuration.java:512)
at org.hibernate.cfg.Configuration.add(Configuration.java:686)
at org.hibernate.cfg.Configuration.addResource(Configuration.java:769)
at org.hibernate.cfg.Configuration.parseMappingElement(Configuration.java:2255)
at org.hibernate.cfg.Configuration.parseSessionFactory(Configuration.java:2227)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:2207)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:2160)
at org.hibernate.cfg.Configuration.configure(Configuration.java:2075)
at test.ClientUsingAssigned.main(ClientUsingAssigned.java:16)
Use <generator> tag inside <Id>
<hibernate-mapping>
<class name="Employee" table="EMPLOYEE">
<meta attribute="class-description">
This class contains the employee detail.
</meta>
<id name="id" type="int" column="id">
<generator class="increment"/>
</id>
<property name="firstName" column="first_name" type="string"/>
<property name="lastName" column="last_name" type="string"/>
<property name="salary" column="salary" type="int"/>
</class>
</hibernate-mapping>
I am using hibernate 4.1.9. I have Users, and the Users have a list of Accounts, and Accounts have list of Transactions. Here is my hbm.xml
<?xml version="1.0"?>
<class name="User" table="users">
<id name="userId" column="userid">
<generator class="increment"/>
</id>
<property name="username" column="username" not-null="true"/>
<property name="password" column="password" not-null="true"/>
<property name="registerDate" type="timestamp" column="register_date"/>
<list name="accounts" table="accounts" inverse="true" cascade="all">
<key column="userid" not-null="true"/>
<index column="accountid"/>
<one-to-many class="com.joe.data.Account"/>
</list>
</class>
<class name="Account" table="accounts">
<id name="accountId" column="accountid">
<generator class="increment"/>
</id>
<property name="balance" type="big_decimal" column="balance"/>
<property name="lastModified" type="timestamp" column="last_modified"/>
<list name="txns" table="transactions" inverse="true" cascade="all">
<key column="accountId" not-null="true"/>
<index column="transactionId"/>
<one-to-many class="com.joe.data.Transaction"/>
</list>
<many-to-one name="userId" class="User" column="userid" not-null="true"
unique="true" cascade="all"/>
<many-to-one name="accountType" class="AccountType" column="account_type"
not-null="true" cascade="all" unique="true" />
</class>
<class name="Transaction" table="transactions">
<id name="transactionId" column="transactionid">
<generator class="increment"/>
</id>
<property name="description" column="description"/>
<property name="amount" type="big_decimal" column="amount"/>
<property name="dateAdded" column="date_added"/>
<property name="reoccuring" type="numeric_boolean" column="reoccuring"/>
<many-to-one name="category" class="Category" column="category"
not-null="true" cascade="all" unique="true" />
</class>
<class name="Category" table="categories">
<id name="categoryId" column="categoryid"/>
<property name="categoryName" column="categoryname" not-null="true"/>
</class>
<class name="AccountType" table="account_types">
<id name="accountType" column="account_type"/>
<property name="accountName" column="name"/>
</class>
If I leave inverse="true" on the list of accounts (in the User) I get the ConstraintViolationException because the userid is not getting put in the insert query. If I take inverse="true" off of the list of accounts, I get org.hibernate.MappingException: Repeated column in mapping for entity: com.joe.data.Account column: accountid (should be mapped with insert="false" update="false")
To clarify lowercase names are database columns names, camel case are class variable names. I know Transaction class isn't working quite right yet, but if I could get the Accounts to insert I could do the same thing to get the Transactions to insert.
Edit: I added the many-to-one on the Account class and now I am getting another exception where hibernate is complaining about missing a getter for userId in com.joe.data.Account
In order to get inverse="true" work, you need to define many-to-one for User in Account and for Account in Transaction class and mappings.
The configuration for Affiliate class is:
<class name="AffiliatesDO" table="AFFILIATES">
<id name="affiliateId" column="affiliate_id" type="java.lang.String">
<generator class="assigned" />
</id>
<property name="customerId" column="customer_id" type="int" />
<property name="affiliateType" column="affiliate_type" type="java.lang.String" />
<property name="site" column="site" type="java.lang.String" />
<property name="status" column="status" type="java.lang.String" />
<property name="createdBy" column="created_by" type="java.lang.String" />
<property name="creationDate" column="creation_date" type="java.util.Date" />
<property name="lastUpdatedBy" column="last_updated_by" type="java.lang.String" />
<property name="lastUpdated" column="last_updated" type="java.util.Date" />
<set name="address" lazy="true" inverse="true" order-by="address_id asc">
<key column="address_id"/>
<one-to-many class="AddressDO"/>
</set>
</class>
The Configuration for Address class is
<class name="Address"
table="Address">
<id name="addressId" column="address_id"
type="java.lang.String">
<generator class="assigned" />
</id>
<property name="name" column="name" type="java.lang.String" />
<property name="address1" column="address1" type="java.lang.String" />
<property name="phone" column="phone" type="java.lang.String" />
<property name="landLineNumber" column="land_line_number" type="java.lang.String" />
<property name="faxNumber" column="fax_number" type="java.lang.String" />
</class>
I am getting the below error
org.hibernate.MappingException: Association references unmapped class: com.infibeam.customerservice.dbObjects.AddressDO
at org.hibernate.cfg.HbmBinder.bindCollectionSecondPass(HbmBinder.java:2370)
at org.hibernate.cfg.HbmBinder$CollectionSecondPass.secondPass(HbmBinder.java:2652)
at org.hibernate.cfg.CollectionSecondPass.doSecondPass(CollectionSecondPass.java:43)
at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1054)
at org.hibernate.cfg.AnnotationConfiguration.secondPassCompile(AnnotationConfiguration.java:296)
at org.hibernate.cfg.Configuration.buildMappings(Configuration.java:1039)
at org.codehaus.mojo.hibernate3.configuration.AbstractComponentConfiguration.getConfiguration(AbstractComponentConfiguration.java:38)
at org.codehaus.mojo.hibernate3.HibernateExporterMojo.configureExporter(HibernateExporterMojo.java:186)
at org.codehaus.mojo.hibernate3.exporter.Hbm2JavaGeneratorMojo.configureExporter(Hbm2JavaGeneratorMojo.java:69)
Kindly show me the mistakes I have made.. I want to use one to many relation AffiliateDO->AddressDO
It looks like your mapping of the parent class is referring to AddressDO, but the subsequent child mapping is referring to Address (No "DO")... If I had to guess, you should change the second mapping to AddressDO (or visa versa). In any event, looks like a typo to me.
Considering Do as a typo error in Addrees xml, The Address mapping seems incorrect, there must address_id must be many-to-one currently it is generated new one.
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>
--><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.