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.
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
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>
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
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.
I have a legacy web app that I am maintaining. It started out as Java 1.4, but I've compiled it to Java5. We're using Spring+Hibernate. I'm not using annotations yet. I'm sticking with XDoclet for now. In it, I have an object graph that looks like this:
Job 1:m Operations 1:m Activities 1:m Transactions
Those Transactions are NOT J2EE transactions. We're just documenting the workflow from one Activity to another.
In HttpRequest#1, I update a couple of Activities and create a new Transaction. Then in HttpRequest#2, I redisplay the entire Job. What I am seeing at this point is the usual SELECT statements for the Job, Operations and Activities, but then I'm seeing some UPDATE statements for the Transactions. It turns out those updates are reverting the Transactions back to their previous states, discarding the latest updates.
Why in the world is Hibernate doing this?
As requested, here's the .hbm.xml file:
<hibernate-mapping>
<class name="ActivityTransaction" table="imed_if_move_transactions"
lazy="false" mutable="true">
<cache usage="nonstrict-read-write" />
<id name="id" column="IF_MOVE_TRANSACTION_ID" type="java.lang.Long">
<generator class="sequence">
<param name="sequence">IMED_IF_MOVE_TRANSACTIONS_S</param>
</generator>
</id>
<property name="activityActionKey" type="java.lang.String"
update="true" insert="true" column="ACTIVITY_ACTION_KEY" />
<property name="approvalStatus" type="int" update="true"
insert="true" column="APPROVAL_STATUS" />
<property name="authorizedBy" type="java.lang.Long" update="true"
insert="true" column="AUTHORIZATION_ID" />
<many-to-one name="authorizedByUser"
class="UserModel" cascade="none"
outer-join="false" update="false" insert="false" not-found="ignore"
fetch="select" column="AUTHORIZATION_ID" />
<property name="date" type="java.util.Date" update="true"
insert="true" column="JOA_TRANSACTION_DATE" />
<many-to-one name="from"
class="JobOpActivity" cascade="none"
outer-join="false" update="true" insert="true" fetch="select"
column="FM_JOB_OP_ACTIVITY_ID" />
<property name="fromIntraActivityStepType" type="java.lang.Integer"
update="true" insert="true" column="FM_INTRAACTIVITY_STEP_TYPE" />
<property name="fromIntraOperationStepType" type="java.lang.Integer"
update="true" insert="true" column="FM_INTRAOPERATION_STEP_TYPE" />
<property name="fromOperationSeqNum" type="java.lang.Integer"
update="true" insert="true" column="FM_OPERATION_SEQ_NUM" />
<many-to-one name="job" class="Job"
cascade="none" outer-join="false" update="true" insert="true" fetch="select"
column="WIP_ENTITY_ID" />
<property name="operationEndDate" type="java.util.Date"
update="true" insert="true" column="OP_END_DATE" />
<property name="operationStartDate" type="java.util.Date"
update="true" insert="true" column="OP_START_DATE" />
<many-to-one name="organization" class="Organization"
cascade="none" outer-join="false" update="true" insert="true" fetch="select"
column="ORGANIZATION_ID" />
<property name="processingStatus" type="java.lang.String"
update="true" insert="true" column="PROCESS_FLAG" />
<property name="quantity" type="int" update="true" insert="true"
column="TRANSACTION_QUANTITY" />
<property name="reasonId" type="java.lang.Long" update="true"
insert="true" column="REASON_ID" />
<property name="reference" type="java.lang.String" update="true"
insert="true" column="REFERENCE" />
<property name="scrapAccountId" type="java.lang.Long" update="true"
insert="true" column="SCRAP_ACCOUNT_ID" />
<property name="spsaId" type="java.lang.Long" update="true"
insert="true" column="SPSA_ID" />
<many-to-one name="to"
class="JobOpActivity" cascade="none"
outer-join="false" update="true" insert="true" fetch="select"
column="TO_JOB_OP_ACTIVITY_ID" />
<property name="toIntraActivityStepType" type="java.lang.Integer"
update="true" insert="true" column="TO_INTRAACTIVITY_STEP_TYPE" />
<property name="toIntraOperationStepType" type="java.lang.Integer"
update="true" insert="true" column="TO_INTRAOPERATION_STEP_TYPE" />
<property name="toOperationSeqNum" type="java.lang.Integer"
update="true" insert="true" column="TO_OPERATION_SEQ_NUM" />
<property name="typeId" type="java.lang.Long" update="true"
insert="true" column="TRANSACTION_TYPE_ID" />
<property name="webKeyEntryId" type="java.lang.String"
update="true" insert="true" column="WEB_KEY_ENTRY_ID" />
<property name="issueMaterial" type="true_false" update="true"
insert="true" column="MATERIAL_ISSUE" />
<property name="createDate" type="java.util.Date" update="true"
insert="true" column="CREATION_DATE" />
<property name="createdBy" type="java.lang.Integer" update="true"
insert="true" column="CREATED_BY" />
<property name="lastUpdateDate" type="java.util.Date" update="true"
insert="true" column="LAST_UPDATE_DATE" />
<property name="lastUpdatedBy" type="java.lang.Integer"
update="true" insert="true" column="LAST_UPDATED_BY" />
</class>
</hibernate-mapping>
And here's an example transaction setup:
<bean id="moldingActivitiesService" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
<property name="transactionManager" ref="etrack2ProviderTransactionManager"/>
<property name="target" ref="moldingActivitiesServiceTarget"/>
<property name="transactionAttributes">
<props>
<prop key="*">PROPAGATION_REQUIRED</prop>
</props>
</property>
</bean>
From some Hibernate Javadoc document on Google http://ajava.org/online/hibernate3api/org/hibernate/FlushMode.html:
AUTO
public static final FlushMode AUTO
The Session is sometimes flushed before query execution in order to ensure that queries never return stale state. This is the default flush mode.
Every modification you are doing on a JPA-managed entity is done in a persistent context. That means Hibernate is assuming that the things that you modify in your entity are safe to be committed. So when you select data from the same entity or related entities, in this mode Hibernate puts consistency of your changes over everything else. So it flushes and then does the read to reflect your changes correctly. If you do not want to have this behavior you can do two things:
disable auto-commit (which I prefer, but it is some kind of a JPA convention, so make up your mind). The downside of this approach is that you have to do more by hand depending on your configuration. The upside is, that everything is much more explicit and less magic
change your code that you collect the data you need first. Also this would make your code much cleaner. Because it would work like the basic computer science pattern everybody understands: Input, Computation, Output. Your mixing those things up, which is the reason why the default mode does not work.
Edit: On how to use Spring's PlatformTransactionManager best without using annotations I would recommend the TransactionTemplate: http://static.springsource.org/spring/docs/3.1.x/spring-framework-reference/html/transaction.html#tx-prog-template
Just inject your PlatformTransactionManager (Hibernate) there and use it to abstract from the transaction handling.
Depending on your FLUSHMODE you will see this, because whenever you do a query, hibernate will normally guess as to whether it should FLUSH to get a clean and consistent read.
Ok, finally found the problem. Here's a more complete flow:
I have Controller C1, Manager M1, Manager M2 and Persister P1. M1 and M2 have managed transactions as I stated above, using TransactionProxyFactoryBean.
C1.methodA() calls M1.methodB() which calls P1.methodC()
C1.methodA() then calls M2.methodD(), which then calls M1.methodE() which calls P1.methodF().
See the problem yet?
It happens when M1.methodD calls M1.methodE(). What I think happens is that since both M1 and M2 are transaction managed, two transactions are created, one for each call. Those two transactions battle it out for which one has the true state of the system, with neither one truly winning.