I am trying to query database from two Different Tables i.e.
query = "select rbt.rbtCode, rbt.maskedName, cmas.catId, cmas.maskedName " +
"from CrbtRbt rbt, CrbtCategoryMaster cmas " +
"where rbt.playable='Y' and rbt.showOnWeb='Y' and rbt.rbtCode!=0 " +
"and rbt.catId=cmas.catId";
but when I pass this query through session.createQuery(query);
It appends package name to the next in coming Entity Name i.e.
select rbt.rbtCode, rbt.maskedName, cmas.catId, cmas.maskedName
from CrbtRbt rbt, com.telemune.toolGeneratedPojos.CrbtCategoryMaster cmas
where rbt.playable='Y' and rbt.showOnWeb='Y' and rbt.rbtCode!=0 and rbt.catId=cmas.catId
and gives the following Exception:
org.hibernate.hql.internal.ast.QuerySyntaxException: CrbtRbt is not mapped [select rbt.rbtCode, rbt.maskedName, cmas.catId, cmas.maskedName from CrbtRbt rbt, com.telemune.toolGeneratedPojos.CrbtCategoryMaster cmas where rbt.playable='Y' and rbt.showOnWeb='Y' and rbt.rbtCode!=0 and rbt.catId=cmas.catId]
at org.hibernate.hql.internal.ast.util.SessionFactoryHelper.requireClassPersister(SessionFactoryHelper.java:180)
at org.hibernate.hql.internal.ast.tree.FromElementFactory.addFromElement(FromElementFactory.java:110)
at org.hibernate.hql.internal.ast.tree.FromClause.addFromElement(FromClause.java:93)
at org.hibernate.hql.internal.ast.HqlSqlWalker.createFromElement(HqlSqlWalker.java:325)
at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.fromElement(HqlSqlBaseWalker.java:3252)
at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.fromElementList(HqlSqlBaseWalker.java:3141)
at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.fromClause(HqlSqlBaseWalker.java:694)
at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.query(HqlSqlBaseWalker.java:550)
at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.selectStatement(HqlSqlBaseWalker.java:287)
at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.statement(HqlSqlBaseWalker.java:235)
at org.hibernate.hql.internal.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:248)
at org.hibernate.hql.internal.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:183)
at org.hibernate.hql.internal.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:136)
at org.hibernate.engine.query.spi.HQLQueryPlan.<init>(HQLQueryPlan.java:101)
at org.hibernate.engine.query.spi.HQLQueryPlan.<init>(HQLQueryPlan.java:80)
at org.hibernate.engine.query.spi.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:119)
at org.hibernate.internal.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:214)
at org.hibernate.internal.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:192)
at org.hibernate.internal.SessionImpl.createQuery(SessionImpl.java:1537)
at com.telemune.generator.TestQuery.select(TestQuery.java:114)
at com.telemune.generator.PojoGenerator.main(PojoGenerator.java:191)
But if I query the Entities One By One it shows the desired result successfully.
i.e.
select rbt.rbtCode, rbt.maskedName
from CrbtRbt rbt
where rbt.playable='Y' and rbt.showOnWeb='Y' and rbt.rbtCode!=0;
gives desired result.
Can anyone Explain what I can do?
here is some example code:
Query Code
hql = session.createQuery(query);
hql.setMaxResults( querySchema.getMaxRes() );
list=hql.list();
For information I have done All the Mappings and included all the libraries very carefully no chance of any mistake.
UPDATE
As I said I have done the mappings carefully but someone may have doubts so here is the mapping:
<hibernate-mapping>
<class name="com.telemune.toolGeneratedPojos.CrbtCategoryMaster" schema="SDP" table="CRBT_CATEGORY_MASTER">
<id name="catId" type="java.lang.Integer">
<column name="CAT_ID" precision="4" scale="0" />
<generator class="assigned" />
</id>
<property column="SHOW_IN_SMS" name="showInSms" type="java.lang.String" />
<property column="SHOW_ON_WEB" name="showOnWeb" type="java.lang.String" />
<property column="PLAYABLE" name="playable" type="java.lang.String" />
<property column="STATUS" name="status" type="java.lang.String" />
<property column="IMAGE_PATH" name="imagePath" type="java.lang.String" />
<property column="DESCRIPTION" name="description" type="java.lang.String" />
<property column="MASKED_NAME" name="maskedName" type="java.lang.String" />
<property column="IVR_FILEPATH_1" name="ivrFilepath1" type="java.lang.String" />
<property column="IVR_FILEPATH" name="ivrFilepath" type="java.lang.String" />
<property column="MASKED_NAME_1" name="maskedName1" type="java.lang.String" />
</class></hibernate-mapping>
and for CRBT_RBT:
<hibernate-mapping>
<class name="com.telemune.toolGeneratedPojos.CrbtRbt" schema="SDP" table="CRBT_RBT">
<id name="rbtCode" type="java.lang.Integer">
<column name="RBT_CODE" precision="10" scale="0" />
<generator class="assigned" />
</id>
<property column="PLAYABLE" name="playable" type="java.lang.String" />
<property column="OTHER" name="other" type="java.lang.Integer" />
<property column="IMAGE_PATH" name="imagePath" type="java.lang.String" />
<property column="RBT_ORDER" name="rbtOrder" type="java.lang.Integer" />
<property column="VALIDITY_PERIOD" name="validityPeriod" type="java.lang.Integer" />
<property column="LYRICIST" name="lyricist" type="java.lang.String" />
<property column="APPROVED_BY" name="approvedBy" type="java.lang.String" />
<property column="PREV_CAT_ID" name="prevCatId" type="java.lang.Integer" />
<property column="RELEASE_YEAR" name="releaseYear" type="java.lang.Integer" />
<property column="COMPOSER" name="composer" type="java.lang.String" />
<property column="SHOW_ON_WEB" name="showOnWeb" type="java.lang.String" />
<property column="MASKED_NAME" name="maskedName" type="java.lang.String" />
<property column="CONTENT_PROVIDER_CODE" name="contentProviderCode" type="java.lang.Integer" />
<property column="CREATE_DATE" name="createDate" type="java.sql.Date" />
<property column="IVR_FILEPATH" name="ivrFilepath" type="java.lang.String" />
<property column="CORP_ID" name="corpId" type="java.lang.Integer" />
<property column="SHOW_IN_SMS" name="showInSms" type="java.lang.String" />
<property column="ALBUM_NAME" name="albumName" type="java.lang.String" />
<property column="NOKIA" name="nokia" type="java.lang.Integer" />
<property column="STATUS" name="status" type="java.lang.String" />
<property column="FILE_PATH" name="filePath" type="java.lang.String" />
<property column="REFERENCE_ID" name="referenceId" type="java.lang.Integer" />
<property column="CHARGING_CODE" name="chargingCode" type="java.lang.Integer" />
<property column="RBT_NICK" name="rbtNick" type="java.lang.String" />
<property column="APPROVAL_DATE" name="approvalDate" type="java.sql.Date" />
<property column="CAT_ID" name="catId" type="java.lang.Integer" />
<property column="RBT_SCORE" name="rbtScore" type="java.lang.Integer" />
<property column="ARTIST_NAME" name="artistName" type="java.lang.String" />
</class>
</hibernate-mapping>
I don't think there is any mistake in the mapping.
Hibernate.cfg.xml :
<hibernate-configuration>
<session-factory>
<property name="hibernate.connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
<property name="hibernate.connection.password">sdp</property>
<property name="hibernate.connection.url">jdbc:oracle:thin:#10.168.2.127:1521:mastera</property>
<property name="hibernate.connection.username">sdp</property>
<property name="hibernate.dialect">org.hibernate.dialect.OracleDialect</property>
<mapping resource="com/telemune/toolGeneratedPojos/CrbtRbt.hbm.xml"/>
<mapping resource="com/telemune/toolGeneratedPojos/CrbtCategoryMaster.hbm.xml"/>
</session-factory>
</hibernate-configuration>
Well, I got this.
SessionFactory getSessionFactory(className) {
try {
configuration.addResource( className + ".hbm.xml" );
}catch (Exception e) {
e.printStackTrace();
}
configuration.configure();
serviceRegistry = new ServiceRegistryBuilder().applySettings(configuration.getProperties()).buildServiceRegistry();
return configuration.buildSessionFactory(serviceRegistry);
here is the code to add .hbm.xml file,programatically, for each class while creating session factory.
try {
sessionFactory = ...getSessionFactory(className);
session = sessionFactory.openSession();
}
catch (Exception e) {
e.printStackTrace();
}
the problem with this code was that:
1. It was building a new session factory for each call(of getSessionFactory(classname)).
2. a new session was opened every time.
So, only the mapping of last class added to configuration was added as a resource and that's why its was searching the other classes by appending the packageName to it's name.
What I did is:
I just counted the no of mapping files in the package and added them with the help of a loop in the same session factory.
And it worked.
Here is the way:
File file = new File(packageName.replace(".", "/"));
for(File file1 : file.listFiles()){
if(file1.getName().trim().substring(file1.getName().trim().lastIndexOf("."),
file1.getName().trim().length()).equalsIgnoreCase(".xml")){
configuration.addResource( packageName.replaceAll("\\.", "/") + "/" + file1.getName() );
}
}
It was just a silly mistake.
Related
from EmployerCharges r1 where r1.routingCode.routingCode = ? and employer.employerId=?
where the following are the pojo classes
<class name="com.greytip.wps.model.EmployerCharges" table="emp_RoutingCode_Charges" lazy="false">
<id name="id" type="int" unsaved-value="0" >
<generator class="native">
<param name="sequence">emp_RoutingCode_id_seq</param>
</generator>
</id>
<many-to-one name ="employer" class = "com.greytip.wps.model.Employer"/>
<many-to-one name ="routingCode" class = "com.greytip.wps.model.RoutingCode"/>
<property name="charges"/>
</class>
//----------------------------------------
hibernate-mapping package="com.greytip.wps.model">
<class name="com.greytip.wps.model.Employer" table="wps_employer" lazy="false">
<id name="id" type="int" unsaved-value="0" >
<generator class="native">
<param name="sequence">wps_employer_id_seq</param>
</generator>
</id>
<property name="employerId"/>
<property name="name"/>
<property name="contactPerson"/>
<property name="address"/>
<property name="bankAcNo"/>
<property name="email"/>
<property name="licenseNo"/>
<property name="licenseExpiryDate"/>
<property name="active"/>
<many-to-one name ="emirateCode"/>
<many-to-one name ="economicActivity"/>
<many-to-one name ="wpsQueue"/>
<property name="schemaCreated"/>
<property name="code"/>
<many-to-one name ="branch"/>
<property name="bankCharges"/>
<property name="contactNo"/>
<many-to-one name="relationshipManager"/>
<many-to-one name ="employerGroup"/>
<property name="hpsEmployerReference"></property>
<property name="chargeReprocessing"></property>
<property name="restrictAccess"></property>
<property name="bankChargesPerFile"></property>
<property name="enableSalaryCardRequest"></property>
<property name="salaryCardCharges"/>
<property name="ftsBankChargesPerFile"/>
<property name="ftsIntBankChargesPerRecord"/>
<property name="ftsExtBankChargesPerRecord"/>
<property name="ftsExtBankChargesPerBank"/>
<property name="ftsIntBankChargesPerBank"/>
<property name="signature"/>
<property name="scReissueCharges"></property>
<property name="scActivateCharges"></property>
<property name="scCancelCharges"></property>
<property name="scReIssuePinCharges"></property>
<many-to-one name ="employerWorkflow"/>
<many-to-one name ="employerCategory"/>
<property name="poBox"></property>
<property name="bankChargesPerBank"></property>
<property name="bankChargesPerMonth"></property>
<property name="defaultCharges"></property>
<property name="isDeleted"></property>
<property name="monthlyCharges"></property>
<property name="appliedCharge"></property>
</class>
//-----------------------------------------------
<hibernate-mapping package="com.greytip.wps.model">
<class name="com.greytip.wps.model.RoutingCode" table="wps_routingCode" lazy="false">
<id name="id" type="int" unsaved-value="0" >
<generator class="native">
<param name="sequence">wps_routingCode_id_seq</param>
</generator>
</id>
<property name="bankCode"/>
<property name="bankName"/>
<property name="routingCode"/>
<property name="branchName"/>
</class>
Please tell me how to convert the hql to sql... Thank you..
Enable show sql and format sql parameters in hibernate configuration and you can see the queries being fired in the log file.
<property name="show_sql">true</property>
<property name="format_sql">true</property>
<property name="use_sql_comments">true</property>
For more information see this question
I'm new to hibernate and I'm trying to solve some problems i cannot understand too well...
For example, I have this query
Query query = session.createQuery("from Client where clientId = "+clientId+")");
List result = query.list();
My Client.hbm.xml is
<class name="it.besmart.models.Client" table="client" catalog="SMARTPARK">
<id name="idClient" type="int">
<column name="id_client" />
<generator class="identity" />
</id>
<property name="nomeClient" type="string">
<column name="nome_client" length="65535" not-null="true" />
</property>
<property name="numPosti" type="int">
<column name="num_posti" not-null="true" />
</property>
<property name="numLuci" type="int">
<column name="num_luci" not-null="true" />
</property>
<property name="inizioPosti" type="int">
<column name="inizio_posti" not-null="true" />
</property>
<property name="inizioLuci" type="int">
<column name="inizio_luci" not-null="true" />
</property>
</class>
</hibernate-mapping>
The table on the DB is called client and the column is client_id
The mapping in hibernate.cfg.xml is
<hibernate-configuration>
<session-factory name="parkserver">
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.password">passwprd</property>
<property name="hibernate.connection.url">jdbc:mysql://192.168.3.67:3306/SMARTPARK</property>
<property name="hibernate.connection.username">parkuser</property>
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="show_sql">true</property>
<property name="format_sql">true</property>
<mapping class="it.besmart.models.Client" resource="Client.hbm.xml"/>
<mapping class="it.besmart.models.Illuminazione" resource="Illuminazione.hbm.xml"/>
<mapping class="it.besmart.models.MappaPosti" resource="MappaPosti.hbm.xml"/>
<mapping class="it.besmart.models.Occupazione" resource="Occupazione.hbm.xml"/>
</session-factory>
</hibernate-configuration>
I'm having no problems in another query in the application, but when i try to executer the SELECT query i got this exception
org.hibernate.hql.internal.ast.QuerySyntaxException: Client is not mapped [from Client where clientId = 1)]
at org.hibernate.hql.internal.ast.QuerySyntaxException.generateQueryException(QuerySyntaxException.java:79)
at org.hibernate.QueryException.wrapWithQueryString(QueryException.java:103)
at org.hibernate.hql.internal.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:218)
at org.hibernate.hql.internal.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:142)
at org.hibernate.engine.query.spi.HQLQueryPlan.<init>(HQLQueryPlan.java:115)
at org.hibernate.engine.query.spi.HQLQueryPlan.<init>(HQLQueryPlan.java:76)
at org.hibernate.engine.query.spi.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:150)
at org.hibernate.internal.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:298)
at org.hibernate.internal.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:236)
at org.hibernate.internal.SessionImpl.createQuery(SessionImpl.java:1836)
at it.besmart.parkserver.SocketClientHandler.run(SocketClientHandler.java:83)
at java.lang.Thread.run(Thread.java:744)
Caused by: org.hibernate.hql.internal.ast.QuerySyntaxException: Client is not mapped
at org.hibernate.hql.internal.ast.util.SessionFactoryHelper.requireClassPersister(SessionFactoryHelper.java:171)
at org.hibernate.hql.internal.ast.tree.FromElementFactory.addFromElement(FromElementFactory.java:91)
at org.hibernate.hql.internal.ast.tree.FromClause.addFromElement(FromClause.java:76)
at org.hibernate.hql.internal.ast.HqlSqlWalker.createFromElement(HqlSqlWalker.java:321)
at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.fromElement(HqlSqlBaseWalker.java:3678)
at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.fromElementList(HqlSqlBaseWalker.java:3567)
at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.fromClause(HqlSqlBaseWalker.java:708)
at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.query(HqlSqlBaseWalker.java:564)
at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.selectStatement(HqlSqlBaseWalker.java:301)
at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.statement(HqlSqlBaseWalker.java:249)
at org.hibernate.hql.internal.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:262)
at org.hibernate.hql.internal.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:190)
I don't know why Client is not mapped, it's correctly in the cfg file...
Thanks in advance
Try to add the full name of the class in the query:
Query query = session.createQuery("from it.besmart.models.Client where clientId = :c");
query.setString("c", clientId)
List result = query.list();
I also changed to late binding here which is preferable but has nothing to do with your problem.
As Maurice Perry pointed out in comment below:
- You can also specify the default package in the mapping file: <hibernate-mapping package="it.besmart.models">
I want find all records in table 'users' using hibernate but its allways return empty collection (im sure that some users are in db). My searching function looks like this:
public List<Users> findAll() {
DetachedCriteria criteria = DetachedCriteria.forClass(Users.class);
return getHibernateTemplate().findByCriteria(criteria);
}
Why is not working?
hibernate.cfg.xml:
<hibernate-configuration>
<session-factory>
<property name="show_sql">true</property>
<property name="format_sql">true</property>
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="connection.url">jdbc:mysql://localhost:3306/intellidom</property>
<property name="connection.username">root</property>
<property name="connection.password"></property>
<mapping file="mapping/Users.hbm.xml"/>
</session-factory>
</hibernate-configuration>
Users.hbm.xml:
<hibernate-mapping>
<class name="intellidom.entity.Users" table="users" schema="intellidom">
<id column="id" name="id" type="int" >
<generator class="increment"/>
</id>
<property name="login" column="login" type="java.lang.String"/>
<property name="password" column="password" type="java.lang.String"/>
<property name="firstName" column="firstName" type="java.lang.String"/>
<property name="lastName" column="lastName" type="java.lang.String"/>
</class>
</hibernate-mapping>
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.