I am posting this question because all the other questions with the same title was not able to resolve my issue.
I have the following table:
CREATE TABLE CONTRACT_DB_AGREEMENT (
AGREEMENT_CODE VARCHAR2(50),
COM_CONTRACT_CODE VARCHAR2(15),
AGREEMENT_TYPE VARCHAR2(20),
EXPIRE_DATE TIMESTAMP(6),
SIGNATORY_USER_NAME NVARCHAR2(150),
SIGNATORY_NAME NVARCHAR2(50),
ORIGINATOR_USER_NAME NVARCHAR2(150),
ORIGINATOR_NAME NVARCHAR2(50),
DATE_CREATED TIMESTAMP(6),
CREATED_BY NVARCHAR2(150),
LAST_UPDATE_DATE TIMESTAMP(6),
LAST_UPDATED_BY NVARCHAR2(150),
CONSTRAINT CONTRACT_DB_AGREEMENT_PK PRIMARY KEY (AGREEMENT_CODE),
CONSTRAINT CONTRACT_DB_AGREEMENT_FK1 FOREIGN KEY(COM_CONTRACT_CODE) REFERENCES CONTRACTS (CONTRACT_CODE)
);
In the HBM file, I have this:
<id name="agreementCode" type="string">
<column name="AGREEMENT_CODE" length="50" />
<generator class="assigned" />
</id>
<property name="agreementType" type="string">
<meta attribute="scope-field">#Length(min = 0, max = 20) private</meta>
<column name="AGREEMENT_TYPE" length="20" />
</property>
<property name="expireDate" type="timestamp">
<column name="EXPIRE_DATE" sql-type="timestamp" />
</property>
<property name="signatoryUserName" type="string">
<meta attribute="scope-field">#Length(min=0, max=150) private</meta>
<column name="SIGNATORY_USER_NAME" length="150" />
</property>
<property name="signatoryName" type="string">
<meta attribute="scope-field">#Length(min=0, max=50) private</meta>
<column name="SIGNATORY_NAME" length="50" />
</property>
<property name="originatorUserName" type="string">
<meta attribute="scope-field">#Length(min=0, max=150) private</meta>
<column name="ORIGINATOR_USER_NAME" length="150" />
</property>
<property name="originatorName" type="string">
<meta attribute="scope-field">#Length(min=0, max=50) private</meta>
<column name="ORIGINATOR_NAME" length="50" />
</property>
<property name="dateCreated" type="timestamp">
<column name="DATE_CREATED" sql-type="timestamp" />
</property>
<property name="createdBy" type="string">
<meta attribute="scope-field">#Length(min=0, max=150) private</meta>
<column name="CREATED_BY" length="150" />
</property>
<property name="lastUpdateDate" type="timestamp">
<column name="LAST_UPDATE_DATE" sql-type="timestamp" />
</property>
<property name="lastUpdatedBy" type="string">
<meta attribute="scope-field">#Length(min=0, max=150) private</meta>
<column name="LAST_UPDATED_BY" length="150" />
</property>
<set name="contractDBAttachments" inverse="true" cascade="save-update">
<key>
<column name="AGREEMENT_CODE" />
</key>
<one-to-many class="ContractDBAttachment" />
</set>
<set name="contractDBNotes" inverse="true" cascade="save-update">
<key>
<column name="AGREEMENT_CODE" />
</key>
<one-to-many class="ContractDBNote" />
</set>
<many-to-one name="contract" class="Contract">
<meta attribute="scope-field">#Length(min = 0, max = 15) private</meta>
<column name="COM_CONTRACT_CODE" length="15"/>
</many-to-one>
I try to run this HQL:
String sql = "SELECT a FROM ContractDBAgreement a WHERE a.comContractCode = ?";
params.add(contractCode);
List<ContractDBAgreement> resultList = DaoManager.getDao(ContractDBAgreement.class).searchBySql(sql, params.toArray());
But I get the following error:
org.hibernate.QueryException: could not resolve property: comContractCode of: com.company.entity.ContractDBAgreement [SELECT a FROM com.company.entity.ContractDBAgreement a WHERE a.comContractCode = ?]
I appreciate any help on this please. Thank you!
UPDATE/EDIT
I updated the field names. I tried hiding the company name I work for and think I altered the code too much. I put it closer to what it actually is. Pretty much, the column is called "COM_CONTRACT_CODE", not just "CONTRACT_CODE"
I got this to work. I had to change the <many-to-one> section to the following:
<property name="comContractCode" type="string">
<meta attribute="scope-field">#Length(min = 0, max = 15) private</meta>
<column name="COM_CONTRACT_CODE" length="15"/>
</property>
<many-to-one name="contract" column="COM_CONTRACT_CODE" class="Contract" insert="false" update="false" />
Related
I want to get id and name of user, who have mhId = "AAA" (mhId is a column in table User_MonHoc. In User_MonHoc, mhid + user_id are primary key).
Table User:
<hibernate-mapping>
<class name="entites.User" table="user" catalog="bthibernate" optimistic-lock="version">
<id name="username" type="string">
<column name="username" length="100" />
<generator class="assigned" />
</id>
<property name="password" type="string">
<column name="password" length="100" not-null="true" />
</property>
<property name="note" type="byte">
<column name="note" not-null="true" />
</property>
<property name="name" type="string">
<column name="name" length="100" not-null="true" />
</property>
<set name="userMonhocs" table="user_monhoc" inverse="true" lazy="true" fetch="select">
<key>
<column name="user_id" length="100" not-null="true" />
</key>
<one-to-many class="entites.UserMonhoc" />
</set>
</class>
Table User_MonHoc
<hibernate-mapping>
<class name="entites.UserMonhoc" table="user_monhoc" catalog="bthibernate" optimistic-lock="version">
<composite-id name="id" class="entites.UserMonhocId">
<key-property name="userId" type="string">
<column name="user_id" length="100" />
</key-property>
<key-property name="mhId" type="string">
<column name="mh_id" length="100" />
</key-property>
</composite-id>
<many-to-one name="monhoc" class="entites.Monhoc" update="false" insert="false" fetch="select">
<column name="mh_id" length="100" not-null="true" />
</many-to-one>
<many-to-one name="user" class="entites.User" update="false" insert="false" fetch="select">
<column name="user_id" length="100" not-null="true" />
</many-to-one>
<property name="thoigianDk" type="timestamp">
<column name="thoigian_dk" length="19" not-null="true" />
</property>
</class>
I want to get id and name of user, who have mhId = "AAA" (mhId is a column in table User_MH).
Thank you!
You should join User and User_MH table in a SQL or HQL query. set alias to User_MH in your query o access User_MH table in where clause:
SQL :
SELECT tbl_user.useranme,tbl_user_mh.user_id FROM User AS tbl_user
INNER JOIN User_MH AS tbl_user_mh ON tbl_user.id=tbl_user_mh.user_id
WHERE tbl_user_mh.mhdl = 'AAA
In my PostgreSQL ERP database, I have a table "Custtable", which has a composite primary key, made from the following fields:
accountnum (String)
partition (Long)
dataareaid (String)
As I understand, because of this composite key, I have to implement a separat POJO, which will serve as the ID field for my "Custtable" hibernate class:
public class CusttableId {
private String accountnum;
private Long partition;
private String dataareaid;
public CusttableId(){
}
public String getAccountnum(){
return accountnum;
}
public void setAccountnum( String an ) {
accountnum = an;
}
public Long getPartition(){
return partition;
}
public void setPartition(Long part){
partition = part;
}
Then, I can use this ID class in my main class:
#Entity
public class Custtable implements java.io.Serializable {
#Id
private CusttableId custTableId;
Having done that, when I use Eclipse Hibernate Tools menu to generate the .hbn.xml mapping file for my main class, I get the following mapping:
<?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 Sep 7, 2016 10:15:45 AM by Hibernate Tools 3.5.0.Final -->
<hibernate-mapping>
<class name="com.myproject.Custtable" table="CUSTTABLE">
<id name="orgid" type="java.lang.String">
<column name="ORGID" />
<generator class="assigned" />
</id>
<many-to-one name="custTableId" class="com.uptake.symphony.data.CusttableId" access="field" fetch="join">
<column name="CUSTTABLEID" />
</many-to-one>
<property name="invoiceaccount" type="java.lang.String">
<column name="INVOICEACCOUNT" />
</property>
<property name="custgroup" type="java.lang.String">
<column name="CUSTGROUP" />
</property>
<property name="linedisc" type="java.lang.String">
<column name="LINEDISC" />
</property>
<property name="paymtermid" type="java.lang.String">
<column name="PAYMTERMID" />
</property>
<property name="cashdisc" type="java.lang.String">
<column name="CASHDISC" />
</property>
<property name="currency" type="java.lang.String">
<column name="CURRENCY" />
</property>
<property name="intercompanyautocreateorders" type="int">
<column name="INTERCOMPANYAUTOCREATEORDERS" />
</property>
<property name="salesgroup" type="java.lang.String">
<column name="SALESGROUP" />
</property>
<property name="blocked" type="int">
<column name="BLOCKED" />
</property>
<property name="onetimecustomer" type="int">
<column name="ONETIMECUSTOMER" />
</property>
<property name="accountstatement" type="int">
<column name="ACCOUNTSTATEMENT" />
</property>
<property name="creditmax" type="java.math.BigDecimal">
<column name="CREDITMAX" />
</property>
<property name="mandatorycreditlimit" type="int">
<column name="MANDATORYCREDITLIMIT" />
</property>
<property name="vendaccount" type="java.lang.String">
<column name="VENDACCOUNT" />
</property>
<property name="pricegroup" type="java.lang.String">
<column name="PRICEGROUP" />
</property>
<property name="multilinedisc" type="java.lang.String">
<column name="MULTILINEDISC" />
</property>
<property name="enddisc" type="java.lang.String">
<column name="ENDDISC" />
</property>
<property name="vatnum" type="java.lang.String">
<column name="VATNUM" />
</property>
<property name="inventlocation" type="java.lang.String">
<column name="INVENTLOCATION" />
</property>
<property name="dlvterm" type="java.lang.String">
<column name="DLVTERM" />
</property>
<property name="dlvmode" type="java.lang.String">
<column name="DLVMODE" />
</property>
<property name="markupgroup" type="java.lang.String">
<column name="MARKUPGROUP" />
</property>
<property name="clearingperiod" type="java.lang.String">
<column name="CLEARINGPERIOD" />
</property>
<property name="freightzone" type="java.lang.String">
<column name="FREIGHTZONE" />
</property>
<property name="creditrating" type="java.lang.String">
<column name="CREDITRATING" />
</property>
<property name="taxgroup" type="java.lang.String">
<column name="TAXGROUP" />
</property>
<property name="statisticsgroup" type="java.lang.String">
<column name="STATISTICSGROUP" />
</property>
<property name="paymmode" type="java.lang.String">
<column name="PAYMMODE" />
</property>
<property name="commissiongroup" type="java.lang.String">
<column name="COMMISSIONGROUP" />
</property>
<property name="bankaccount" type="java.lang.String">
<column name="BANKACCOUNT" />
</property>
<property name="paymsched" type="java.lang.String">
<column name="PAYMSCHED" />
</property>
<property name="contactpersonid" type="java.lang.String">
<column name="CONTACTPERSONID" />
</property>
<property name="invoiceaddress" type="int">
<column name="INVOICEADDRESS" />
</property>
<property name="ouraccountnum" type="java.lang.String">
<column name="OURACCOUNTNUM" />
</property>
<property name="salespoolid" type="java.lang.String">
<column name="SALESPOOLID" />
</property>
<property name="incltax" type="int">
<column name="INCLTAX" />
</property>
<property name="custitemgroupid" type="java.lang.String">
<column name="CUSTITEMGROUPID" />
</property>
<property name="numbersequencegroup" type="java.lang.String">
<column name="NUMBERSEQUENCEGROUP" />
</property>
<property name="paymdayid" type="java.lang.String">
<column name="PAYMDAYID" />
</property>
<property name="lineofbusinessid" type="java.lang.String">
<column name="LINEOFBUSINESSID" />
</property>
<property name="destinationcodeid" type="java.lang.String">
<column name="DESTINATIONCODEID" />
</property>
<property name="girotype" type="int">
<column name="GIROTYPE" />
</property>
<property name="suppitemgroupid" type="java.lang.String">
<column name="SUPPITEMGROUPID" />
</property>
<property name="girotypeinterestnote" type="int">
<column name="GIROTYPEINTERESTNOTE" />
</property>
<property name="taxlicensenum" type="java.lang.String">
<column name="TAXLICENSENUM" />
</property>
<property name="websalesorderdisplay" type="int">
<column name="WEBSALESORDERDISPLAY" />
</property>
<property name="paymspec" type="java.lang.String">
<column name="PAYMSPEC" />
</property>
<property name="bankcentralbankpurposetext" type="java.lang.String">
<column name="BANKCENTRALBANKPURPOSETEXT" />
</property>
<property name="bankcentralbankpurposecode" type="java.lang.String">
<column name="BANKCENTRALBANKPURPOSECODE" />
</property>
<property name="intercompanyallowindirectcreation" type="int">
<column name="INTERCOMPANYALLOWINDIRECTCREATION" />
</property>
<property name="packmaterialfeelicensenum" type="java.lang.String">
<column name="PACKMATERIALFEELICENSENUM" />
</property>
<property name="taxbordernumberFi" type="java.lang.String">
<column name="TAXBORDERNUMBERFI" />
</property>
<property name="einvoiceeannum" type="java.lang.String">
<column name="EINVOICEEANNUM" />
</property>
<property name="fiscalcode" type="java.lang.String">
<column name="FISCALCODE" />
</property>
<property name="dlvreason" type="java.lang.String">
<column name="DLVREASON" />
</property>
<property name="forecastdmpinclude" type="int">
<column name="FORECASTDMPINCLUDE" />
</property>
<property name="girotypecollectionletter" type="int">
<column name="GIROTYPECOLLECTIONLETTER" />
</property>
<property name="salescalendarid" type="java.lang.String">
<column name="SALESCALENDARID" />
</property>
<property name="custclassificationid" type="java.lang.String">
<column name="CUSTCLASSIFICATIONID" />
</property>
<property name="intercompanydirectdelivery" type="int">
<column name="INTERCOMPANYDIRECTDELIVERY" />
</property>
<property name="enterprisenumber" type="java.lang.String">
<column name="ENTERPRISENUMBER" />
</property>
<property name="shipcarrieraccount" type="java.lang.String">
<column name="SHIPCARRIERACCOUNT" />
</property>
<property name="girotypeprojinvoice" type="int">
<column name="GIROTYPEPROJINVOICE" />
</property>
<property name="inventsiteid" type="java.lang.String">
<column name="INVENTSITEID" />
</property>
<property name="orderentrydeadlinegroupid" type="java.lang.String">
<column name="ORDERENTRYDEADLINEGROUPID" />
</property>
<property name="shipcarrierid" type="java.lang.String">
<column name="SHIPCARRIERID" />
</property>
<property name="shipcarrierfuelsurcharge" type="int">
<column name="SHIPCARRIERFUELSURCHARGE" />
</property>
<property name="shipcarrierblindshipment" type="int">
<column name="SHIPCARRIERBLINDSHIPMENT" />
</property>
<property name="shipcarrieraccountcode" type="java.lang.String">
<column name="SHIPCARRIERACCOUNTCODE" />
</property>
<property name="girotypefreetextinvoice" type="int">
<column name="GIROTYPEFREETEXTINVOICE" />
</property>
<property name="syncentityid" type="java.lang.String">
<column name="SYNCENTITYID" />
</property>
<property name="syncversion" type="long">
<column name="SYNCVERSION" />
</property>
<property name="memo" type="java.lang.String">
<column name="MEMO" />
</property>
<property name="salesdistrictid" type="java.lang.String">
<column name="SALESDISTRICTID" />
</property>
<property name="segmentid" type="java.lang.String">
<column name="SEGMENTID" />
</property>
<property name="subsegmentid" type="java.lang.String">
<column name="SUBSEGMENTID" />
</property>
<property name="rfiditemtagging" type="int">
<column name="RFIDITEMTAGGING" />
</property>
<property name="rfidcasetagging" type="int">
<column name="RFIDCASETAGGING" />
</property>
<property name="rfidpallettagging" type="int">
<column name="RFIDPALLETTAGGING" />
</property>
<property name="companychainid" type="java.lang.String">
<column name="COMPANYCHAINID" />
</property>
<property name="companyidsiret" type="java.lang.String">
<column name="COMPANYIDSIRET" />
</property>
<property name="party" type="long">
<column name="PARTY" />
</property>
<property name="identificationnumber" type="java.lang.String">
<column name="IDENTIFICATIONNUMBER" />
</property>
<property name="partycountry" type="java.lang.String">
<column name="PARTYCOUNTRY" />
</property>
<property name="partystate" type="java.lang.String">
<column name="PARTYSTATE" />
</property>
<property name="paymidtype" type="java.lang.String">
<column name="PAYMIDTYPE" />
</property>
<property name="factoringaccount" type="java.lang.String">
<column name="FACTORINGACCOUNT" />
</property>
<property name="defaultdimension" type="long">
<column name="DEFAULTDIMENSION" />
</property>
<property name="custexcludecollectionfee" type="int">
<column name="CUSTEXCLUDECOLLECTIONFEE" />
</property>
<property name="custexcludeinterestcharges" type="int">
<column name="CUSTEXCLUDEINTERESTCHARGES" />
</property>
<property name="companynafcode" type="long">
<column name="COMPANYNAFCODE" />
</property>
<property name="bankcustpaymidtable" type="long">
<column name="BANKCUSTPAYMIDTABLE" />
</property>
<property name="girotypeaccountstatement" type="int">
<column name="GIROTYPEACCOUNTSTATEMENT" />
</property>
<property name="maincontactworker" type="long">
<column name="MAINCONTACTWORKER" />
</property>
<property name="creditcardaddressverification" type="int">
<column name="CREDITCARDADDRESSVERIFICATION" />
</property>
<property name="creditcardcvc" type="int">
<column name="CREDITCARDCVC" />
</property>
<property name="creditcardaddressverificationvoid" type="int">
<column name="CREDITCARDADDRESSVERIFICATIONVOID" />
</property>
<property name="creditcardaddressverificationlevel" type="int">
<column name="CREDITCARDADDRESSVERIFICATIONLEVEL" />
</property>
<property name="companytypeMx" type="int">
<column name="COMPANYTYPEMX" />
</property>
<property name="rfcMx" type="java.lang.String">
<column name="RFCMX" />
</property>
<property name="curpMx" type="java.lang.String">
<column name="CURPMX" />
</property>
<property name="stateinscriptionMx" type="java.lang.String">
<column name="STATEINSCRIPTIONMX" />
</property>
<property name="residenceforeigncountryregionidIt" type="java.lang.String">
<column name="RESIDENCEFOREIGNCOUNTRYREGIONIDIT" />
</property>
<property name="birthcountycodeIt" type="java.lang.String">
<column name="BIRTHCOUNTYCODEIT" />
</property>
<property name="birthdateIt" type="java.util.Date">
<column name="BIRTHDATEIT" />
</property>
<property name="birthplaceIt" type="java.lang.String">
<column name="BIRTHPLACEIT" />
</property>
<property name="einvoice" type="int">
<column name="EINVOICE" />
</property>
<property name="ccmnumBr" type="java.lang.String">
<column name="CCMNUMBR" />
</property>
<property name="cnpjcpfnumBr" type="java.lang.String">
<column name="CNPJCPFNUMBR" />
</property>
<property name="pbacustgroupid" type="java.lang.String">
<column name="PBACUSTGROUPID" />
</property>
<property name="ienumBr" type="java.lang.String">
<column name="IENUMBR" />
</property>
<property name="suframanumberBr" type="java.lang.String">
<column name="SUFRAMANUMBERBR" />
</property>
<property name="suframaBr" type="int">
<column name="SUFRAMABR" />
</property>
<property name="custfinaluserBr" type="int">
<column name="CUSTFINALUSERBR" />
</property>
<property name="interestcodeBr" type="java.lang.String">
<column name="INTERESTCODEBR" />
</property>
<property name="finecodeBr" type="java.lang.String">
<column name="FINECODEBR" />
</property>
<property name="suframapiscofinsBr" type="int">
<column name="SUFRAMAPISCOFINSBR" />
</property>
<property name="taxwithholdcalculateTh" type="int">
<column name="TAXWITHHOLDCALCULATETH" />
</property>
<property name="taxwithholdgroupTh" type="java.lang.String">
<column name="TAXWITHHOLDGROUPTH" />
</property>
<property name="consdayJp" type="int">
<column name="CONSDAYJP" />
</property>
<property name="nitBr" type="java.lang.String">
<column name="NITBR" />
</property>
<property name="inssceiBr" type="java.lang.String">
<column name="INSSCEIBR" />
</property>
<property name="cnaeBr" type="java.lang.String">
<column name="CNAEBR" />
</property>
<property name="icmscontributorBr" type="int">
<column name="ICMSCONTRIBUTORBR" />
</property>
<property name="servicecodeondlvaddressBr" type="int">
<column name="SERVICECODEONDLVADDRESSBR" />
</property>
<property name="inventprofiletypeRu" type="int">
<column name="INVENTPROFILETYPERU" />
</property>
<property name="inventprofileidRu" type="java.lang.String">
<column name="INVENTPROFILEIDRU" />
</property>
<property name="taxwithholdcalculateIn" type="int">
<column name="TAXWITHHOLDCALCULATEIN" />
</property>
<property name="unitedvatinvoiceLt" type="int">
<column name="UNITEDVATINVOICELT" />
</property>
<property name="enterprisecode" type="java.lang.String">
<column name="ENTERPRISECODE" />
</property>
<property name="commercialregistersection" type="java.lang.String">
<column name="COMMERCIALREGISTERSECTION" />
</property>
<property name="commercialregisterinsetnumber" type="java.lang.String">
<column name="COMMERCIALREGISTERINSETNUMBER" />
</property>
<property name="commercialregister" type="java.lang.String">
<column name="COMMERCIALREGISTER" />
</property>
<property name="regnumW" type="java.lang.String">
<column name="REGNUMW" />
</property>
<property name="isresidentLv" type="int">
<column name="ISRESIDENTLV" />
</property>
<property name="intbankLv" type="java.lang.String">
<column name="INTBANKLV" />
</property>
<property name="paymentreferenceEe" type="java.lang.String">
<column name="PAYMENTREFERENCEEE" />
</property>
<property name="packagedepositexcemptPl" type="int">
<column name="PACKAGEDEPOSITEXCEMPTPL" />
</property>
<property name="fednonfedindicator" type="int">
<column name="FEDNONFEDINDICATOR" />
</property>
<property name="irs1099cindicator" type="int">
<column name="IRS1099CINDICATOR" />
</property>
<property name="agencylocationcode" type="java.lang.String">
<column name="AGENCYLOCATIONCODE" />
</property>
<property name="federalcomments" type="java.lang.String">
<column name="FEDERALCOMMENTS" />
</property>
<property name="usepurchrequest" type="int">
<column name="USEPURCHREQUEST" />
</property>
<property name="mcrmergedparent" type="java.lang.String">
<column name="MCRMERGEDPARENT" />
</property>
<property name="mcrmergedroot" type="java.lang.String">
<column name="MCRMERGEDROOT" />
</property>
<property name="affiliatedRu" type="int">
<column name="AFFILIATEDRU" />
</property>
<property name="cashdiscbasedays" type="int">
<column name="CASHDISCBASEDAYS" />
</property>
<property name="custtradingpartnercode" type="long">
<column name="CUSTTRADINGPARTNERCODE" />
</property>
<property name="custwhtcontributiontypeBr" type="int">
<column name="CUSTWHTCONTRIBUTIONTYPEBR" />
</property>
<property name="daxintegrationid" type="java.lang.String">
<column name="DAXINTEGRATIONID" />
</property>
<property name="defaultdirectdebitmandate" type="long">
<column name="DEFAULTDIRECTDEBITMANDATE" />
</property>
<property name="defaultinventstatusid" type="java.lang.String">
<column name="DEFAULTINVENTSTATUSID" />
</property>
<property name="entrycertificaterequiredW" type="int">
<column name="ENTRYCERTIFICATEREQUIREDW" />
</property>
<property name="exportsalesPl" type="int">
<column name="EXPORTSALESPL" />
</property>
<property name="expressbilloflading" type="int">
<column name="EXPRESSBILLOFLADING" />
</property>
<property name="fiscaldoctypePl" type="int">
<column name="FISCALDOCTYPEPL" />
</property>
<property name="foreignresidentRu" type="int">
<column name="FOREIGNRESIDENTRU" />
</property>
<property name="generateincomingfiscaldocumentBr" type="int">
<column name="GENERATEINCOMINGFISCALDOCUMENTBR" />
</property>
<property name="invoicepostingtypeRu" type="int">
<column name="INVOICEPOSTINGTYPERU" />
</property>
<property name="issueownentrycertificateW" type="int">
<column name="ISSUEOWNENTRYCERTIFICATEW" />
</property>
<property name="issuercountryHu" type="java.lang.String">
<column name="ISSUERCOUNTRYHU" />
</property>
<property name="lvpaymtranscodes" type="long">
<column name="LVPAYMTRANSCODES" />
</property>
<property name="mandatoryvatdatePl" type="int">
<column name="MANDATORYVATDATEPL" />
</property>
<property name="passportnoHu" type="java.lang.String">
<column name="PASSPORTNOHU" />
</property>
<property name="pdscustrebategroupid" type="java.lang.String">
<column name="PDSCUSTREBATEGROUPID" />
</property>
<property name="pdsfreightaccrued" type="int">
<column name="PDSFREIGHTACCRUED" />
</property>
<property name="pdsrebatetmagroup" type="java.lang.String">
<column name="PDSREBATETMAGROUP" />
</property>
<property name="taxperiodpaymentcodePl" type="java.lang.String">
<column name="TAXPERIODPAYMENTCODEPL" />
</property>
<property name="usecashdisc" type="int">
<column name="USECASHDISC" />
</property>
<property name="modifieddatetime" type="java.util.Date">
<column name="MODIFIEDDATETIME" />
</property>
<property name="delModifiedtime" type="int">
<column name="DELMODIFIEDTIME" />
</property>
<property name="modifiedby" type="java.lang.String">
<column name="MODIFIEDBY" />
</property>
<property name="createddatetime" type="java.util.Date">
<column name="CREATEDDATETIME" />
</property>
<property name="delCreatedtime" type="int">
<column name="DELCREATEDTIME" />
</property>
<property name="dataareaid" type="java.lang.String">
<column name="DATAAREAID" />
</property>
<property name="recversion" type="int">
<column name="RECVERSION" />
</property>
<property name="partition" type="long">
<column name="PARTITION" />
</property>
<property name="recid" type="long">
<column name="RECID" />
</property>
<property name="einvoiceregisterIt" type="int">
<column name="EINVOICEREGISTERIT" />
</property>
<property name="foreigneridBr" type="java.lang.String">
<column name="FOREIGNERIDBR" />
</property>
<property name="authorityofficeIt" type="java.lang.String">
<column name="AUTHORITYOFFICEIT" />
</property>
<property name="presencetypeBr" type="int">
<column name="PRESENCETYPEBR" />
</property>
<property name="taxgstreliefgroupheadingMy" type="long">
<column name="TAXGSTRELIEFGROUPHEADINGMY" />
</property>
</class>
</hibernate-mapping>
As you can see, the mapping generator gets two things wrong: 1) it identifies an incorrect id; 2) it interprets the CusttableId class as a one-to-many relationship, rather then using it as the id for the Custtable class.
What is the proper way to handle this mapping, to have the CusttableId class mapped as the id for the Custtable class?
You're looking for EmbeddedId or IdClass:
https://docs.jboss.org/hibernate/orm/5.0/mappingGuide/en-US/html/ch06.html#identifiers-composite-nonaggregated
Since judging by provided XML you're using Hibernate 3, you should look into that example:
https://docs.jboss.org/hibernate/orm/3.3/reference/en/html/mapping.html#mapping-declaration-id
In your case you can remove the class and replace incorrect association with:
<composite-id>
<key-property name="accountnum"/>
<key-property name="partition"/>
<key-property name="dataareaid"/>
</composite-id>
I have the following Hibernate Mappings:
<class name="Database.Content" table="..." schema="" catalog="...">
<id name="id">
<column name="id" sql-type="int" not-null="true"/>
</id>
<property name="week">
<column name="week" sql-type="int"/>
</property>
<property name="day">
<column name="day" sql-type="int"/>
</property>
<property name="hour">
<column name="hour" sql-type="int"/>
</property>
<property name="type">
<column name="type" sql-type="int" not-null="true"/>
</property>
<many-to-one name="group" class="Database.Group">
<column name="group"/>
</many-to-one>
<many-to-one name="table" class="Database.Table">
<column name="table" not-null="true"/>
</many-to-one>
<list name="entries" inverse="true" table="...">
<key>
<column name="content" not-null="true"/>
</key>
<list-index column="id"/>
<one-to-many not-found="ignore" class="Database.Entry"/>
</list>
</class>
<class name="Database.Entry" table="..." schema="" catalog="...">
<id name="id">
<column name="id" sql-type="int" not-null="true"/>
</id>
<property name="teacher">
<column name="teacher" sql-type="int" not-null="true"/>
</property>
<property name="course">
<column name="course" sql-type="int" not-null="true"/>
</property>
<property name="room">
<column name="room" sql-type="int" not-null="true"/>
</property>
<property name="p">
<column name="p" sql-type="int" not-null="true"/>
</property>
<many-to-one name="content" class="Database.Content" fetch="join" lazy="false">
<column name="content" not-null="true"/>
</many-to-one>
</class>
Now I am trying to query all contents with the corresponding entries:
List<Content> contents = session.createQuery("from Content c WHERE c.day IN :days ").setParameterList("days", days).list();
The query returns the correct response. However, when I do the following:
contents.get(0).getEntries()
there is a bunch of null values. What is the correct way to eager load all corresponding entries for each content?
I have about 20,000 content records, and most of the records have only one entry.
If I set lazy="false" for the list of entries, I get Java heap space error.
I ended up fetching entries and joining contents:
List<Entry> entries = session.createQuery("select e from Entry e Join e.content c WHERE c.day IN :days ").setParameterList("days", days).list();
I also changed lazy to proxy in:
<many-to-one name="content" class="Database.Content" fetch="join" lazy="proxy">
<column name="content" not-null="true"/>
</many-to-one>
Add lazy=false attribute:
<list name="entries" inverse="true" table="up_timetable_entries" lazy="false">
Hope helped you!
Try calling:
contents.get(0).getEntries().size();
To force hibernate to load the children.
I have to tables Usuario_tbl and RolUsuario_tbl. I generate java model with hibernate reverse engineering having this .hbm.xml
<hibernate-mapping>
<class name="co.ejemplo.modelo.UsuarioTbl" table="usuario_tbl" catalog="structse_db">
<id name="idUsuario" type="java.lang.Integer">
<column name="id_usuario" />
<generator class="identity" />
</id>
<property name="login" type="string">
<column name="login" length="50" not-null="true" unique="true" />
</property>
<property name="clave" type="string">
<column name="clave" not-null="true" />
</property>
<property name="habilitado" type="byte">
<column name="habilitado" not-null="true" />
</property>
<property name="fechaAlta" type="timestamp">
<column name="fecha_alta" length="19" />
</property>
<property name="fechaBaja" type="timestamp">
<column name="fecha_baja" length="19" />
</property>
<set name="rolUsuarioTbls" table="rol_usuario_tbl" inverse="true" lazy="true" fetch="select">
<key>
<column name="login" not-null="true" />
</key>
<one-to-many class="co.ejemplo.modelo.RolUsuarioTbl" />
</set>
</class>
</hibernate-mapping>
and
<hibernate-mapping>
<class name="co.ejemplo.modelo.RolUsuarioTbl" table="rol_usuario_tbl" catalog="structse_db">
<id name="idUsuarioRol" type="java.lang.Integer">
<column name="id_usuario_rol" />
<generator class="identity" />
</id>
<many-to-one name="usuarioTbl" class="co.ejemplo.modelo.UsuarioTbl" fetch="select">
<column name="login" not-null="true" />
</many-to-one>
<property name="rol" type="string">
<column name="rol" length="50" not-null="true" />
</property>
</class>
</hibernate-mapping>
When I try to save one RolUsuarioTbl using getHibernateTemplate().save(rolUsuarioTbl) hibernate tells me that needs all the UsuarioTbl properties but I only has setting the login in UsuarioTbl.
How can I save RolUsuarioTbl having only login property in UsuarioTbl?
Many to one relations must be by the code of both tables, otherwise hibernate will not recognize the children of the parent table.
I am presently trying to do a bulk upload operation where in i need to parse an excel and update the details into the database. The problem is the data needs to be stored into multiple tables and the relationship is maintained. The problem is not when i have about 50-100 records to updated, but hugely affected when i have around 50000 records to be updated. It takes ages to upload and sometimes the browser gives up waiting for the response to arrive. Please find below the code and the mapping files. Please let me know what i can do to increase the performance and complete the processing quicker.
Note: The cascades are all required.
***.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 Mar 19, 2012 9:24:47 AM by Hibernate Tools 3.3.0.GA -->
<hibernate-mapping>
<class name="com.****.****.hibernate.****" table="V_ACCOUNT_DIM">
<id name="acctDimIdN" type="long">
<column name="ACCT_DIM_ID_N" precision="10" scale="0" />
<generator class="sequence">
<param name="sequence">ACCOUNT_DIM_SEQ</param>
</generator>
</id>
<property name="gdwIdN" type="long">
<column name="GDW_ID_N" precision="38" scale="0" not-null="true" />
</property>
<property name="pycisInstnIdN" type="java.lang.Long">
<column name="PYCIS_INSTN_ID_N" precision="10" scale="0" />
</property>
<property name="acctNotesC" type="string">
<column name="ACCT_NOTES_C" length="4000" />
</property>
<property name="trdSysShrtNmC" type="string">
<column name="TRD_SYS_SHRT_NM_C" length="100" />
</property>
<property name="reimbAuthorizeD" type="date">
<column name="REIMB_AUTHORIZE_D" length="7" />
</property>
<property name="reimbInitD" type="date">
<column name="REIMB_INIT_D" length="7" />
</property>
<property name="reimbEffD" type="date">
<column name="REIMB_EFF_D" length="7" />
</property>
<property name="acctGainLossAmtN" type="java.lang.Double">
<column name="ACCT_GAIN_LOSS_AMT_N" precision="15" />
</property>
<property name="buySellIndC" type="string">
<column name="BUY_SELL_IND_C" length="10" />
</property>
<property name="navImpcN" type="java.lang.Double">
<column name="NAV_IMPC_N" precision="15" />
</property>
<property name="delIndC" type="string">
<column name="DEL_IND_C" length="1" not-null="true" />
</property>
<property name="updUsrC" type="string">
<column name="UPD_USR_C" length="12" />
</property>
<property name="updTsD" type="date">
<column name="UPD_TS_D" length="7" />
</property>
<property name="insUsrC" type="string">
<column name="INS_USR_C" length="12" not-null="true" />
</property>
<property name="insTsD" type="date">
<column name="INS_TS_D" length="7" not-null="true" />
</property>
<set name="incidentAcctSecFacts" table="V_INCIDENT_ACCT_SEC_FACT" inverse="true" lazy="true" fetch="select" cascade="all-delete-orphan" >
<key>
<column name="ACCT_DIM_ID_N" precision="22" scale="0" not-null="true" />
</key>
<one-to-many class="com.****.***.***.I***Fact" />
</set>
<set name="incidentAcctFacts" table="V_INCIDENT_ACCT_FACT" inverse="true" lazy="true" fetch="select" cascade="all-delete-orphan" >
<key>
<column name="ACCT_DIM_ID_N" precision="22" scale="0" not-null="true" />
</key>
<one-to-many class="com.****.***.***.I***Fact" />
</set>
<set name="accountAttachmentFacts" table="V_ACCOUNT_ATTACHMENT_FACT" inverse="true" lazy="true" fetch="select" cascade="all-delete-orphan" >
<key>
<column name="ACCT_DIM_ID_N" precision="22" scale="0" not-null="true" />
</key>
<one-to-many class="com.****.***.***.A****Fact" />
</set>
</class>
</hibernate-mapping>
I****Dim.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 Mar 19, 2012 9:24:47 AM by Hibernate Tools 3.3.0.GA -->
<hibernate-mapping>
<class name="com.****.***.***.I****Dim" table="V_****_DIM">
<id name="incidentDimIdN" type="long">
<column name="INCIDENT_DIM_ID_N" precision="10" scale="0" />
<generator class="sequence">
<param name="sequence">INCIDENT_DIM_SEQ</param>
</generator>
</id>
<property name="errMemoIdC" type="string">
<column name="ERR_MEMO_ID_C" length="60" not-null="true" unique="true" />
</property>
<property name="errMemoD" type="date">
<column name="ERR_MEMO_D" length="7" />
</property>
<property name="idD" type="date">
<column name="ID_D" length="7" not-null="true" />
</property>
<property name="incidentD" type="date">
<column name="INCIDENT_D" length="7" not-null="true" />
</property>
<property name="ntfcD" type="date">
<column name="NTFC_D" length="7" not-null="true" />
</property>
<property name="totGainLossN" type="java.lang.Double">
<column name="TOT_GAIN_LOSS_N" precision="18" scale="2"/>
</property>
<property name="ovrdAttachedAcctC" type="string">
<column name="OVRD_ATTACHED_ACCT_C" length="1" />
</property>
<property name="gainLossCalcMthdC" type="string">
<column name="GAIN_LOSS_CALC_MTHD_C" length="4000" />
</property>
<property name="deemedAnErrC" type="string">
<column name="DEEMED_AN_ERR_C" length="1" not-null="true" />
</property>
<property name="errRatifiedC" type="string">
<column name="ERR_RATIFIED_C" length="1" not-null="true" />
</property>
<property name="errAcctUsedC" type="string">
<column name="ERR_ACCT_USED_C" length="1" not-null="true" />
</property>
<property name="aprvPrcsC" type="string">
<column name="APRV_PRCS_C" length="4000" />
</property>
<property name="incidentShrtDescC" type="string">
<column name="INCIDENT_SHRT_DESC_C" length="4000" />
</property>
<property name="incidentSumC" type="string">
<column name="INCIDENT_SUM_C" length="4000" />
</property>
<property name="incidentNotesC" type="string">
<column name="INCIDENT_NOTES_C" length="4000" />
</property>
<property name="delIndC" type="string">
<column name="DEL_IND_C" length="1" not-null="true" />
</property>
<property name="updUsrC" type="string">
<column name="UPD_USR_C" length="12" />
</property>
<property name="updTsD" type="date">
<column name="UPD_TS_D" length="7" />
</property>
<property name="insUsrC" type="string">
<column name="INS_USR_C" length="12" not-null="true" />
</property>
<property name="insTsD" type="date">
<column name="INS_TS_D" length="7" />
</property>
<set name="incidentAttachmentFacts" table="V_****FACT" inverse="true" lazy="true" fetch="select" cascade="all-delete-orphan" >
<key>
<column name="INCIDENT_DIM_ID_N" precision="10" scale="0" not-null="true" />
</key>
<one-to-many class="com.****.***.***.I***Fact" />
</set>
<set name="incidentActionItemFacts" table="V_****_FACT" inverse="true" lazy="true" fetch="select" cascade="all-delete-orphan" >
<key>
<column name="INCIDENT_DIM_ID_N" precision="22" scale="0" />
</key>
<one-to-many class="com.****.***.***.I****Fact" />
</set>
<set name="incidentAcctSecFacts" table="V_****FACT" inverse="true" lazy="true" fetch="select" cascade="all-delete-orphan" >
<key>
<column name="INCIDENT_DIM_ID_N" precision="22" scale="0" not-null="true" />
</key>
<one-to-many class="com.***.***.****.IncidentAcctSecFact" />
</set>
<set name="irgMemberAssignmentFacts" table="V_IRG_MEMBER_ASSIGNMENT_FACT" inverse="true" lazy="true" fetch="select" cascade="all-delete-orphan" >
<key>
<column name="INCIDENT_DIM_ID_N" precision="22" scale="0" />
</key>
<one-to-many class="com.***.***.****.IrgMemberAssignmentFact" />
</set>
<set name="incidentAcctFacts" table="V_INCIDENT_ACCT_FACT" inverse="true" lazy="true" fetch="select" cascade="all-delete-orphan" >
<key>
<column name="INCIDENT_DIM_ID_N" precision="22" scale="0" not-null="true" />
</key>
<one-to-many class="com.***.***.****.IncidentAcctFact" />
</set>
<set name="acctAttachmentFacts" table="V_ACCOUNT_ATTACHMENT_FACT" inverse="true" lazy="true" fetch="select" cascade="all-delete-orphan" >
<key>
<column name="INCIDENT_DIM_ID_N" precision="22" scale="0" not-null="true" />
</key>
<one-to-many class="com.***.***.****.AccountAttachmentFact" />
</set>
</class>
</hibernate-mapping>
CerSecurityDim.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 Mar 19, 2012 9:24:47 AM by Hibernate Tools 3.3.0.GA -->
<hibernate-mapping>
<class name="com.***.***.****.CerSecurityDim" table="V_CER_SECURITY_DIM">
<id name="cerSecuDimIdN" type="long">
<column name="CER_SECU_DIM_ID_N" precision="22" scale="0" />
<generator class="sequence">
<param name="sequence">CER_SECURITY_DIM_SEQ</param>
</generator>
</id>
<property name="fmrCusipC" type="string">
<column name="FMR_CUSIP_C" length="30" not-null="true" />
</property>
<property name="tckrC" type="string">
<column name="TCKR_C" length="30" />
</property>
<property name="secuNmC" type="string">
<column name="SECU_NM_C" not-null="true" />
</property>
<property name="numOfShrTrdN" type="java.lang.Long">
<column name="NUM_OF_SHR_TRD_N" precision="10" scale="0" />
</property>
<property name="secuGainLossN" type="java.lang.Double">
<column name="SECU_GAIN_LOSS_N" precision="15" />
</property>
<property name="buySellIndC" type="string">
<column name="BUY_SELL_IND_C" length="10" />
</property>
<property name="delIndC" type="string">
<column name="DEL_IND_C" length="1" not-null="true" />
</property>
<property name="updUsrC" type="string">
<column name="UPD_USR_C" length="12" />
</property>
<property name="updTsD" type="date">
<column name="UPD_TS_D" length="7" />
</property>
<property name="insUsrC" type="string">
<column name="INS_USR_C" length="12" not-null="true" />
</property>
<property name="insTsD" type="date">
<column name="INS_TS_D" length="7" not-null="true" />
</property>
<set name="incidentAcctSecFacts" table="V_INCIDENT_ACCT_SEC_FACT" inverse="true" lazy="true" fetch="select" cascade="all-delete-orphan" >
<key>
<column name="SECU_DIM_ID_N" precision="22" scale="0" not-null="true" />
</key>
<one-to-many class="com.***.***.****.IncidentAcctSecFact" />
</set>
</class>
</hibernate-mapping>
IncidentAcctFact.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 Mar 19, 2012 9:24:47 AM by Hibernate Tools 3.3.0.GA -->
<hibernate-mapping>
<class name="com.***.***.****.IncidentAcctFact" table="V_INCIDENT_ACCT_FACT">
<id name="incidentAcctFactIdN" type="long">
<column name="INCIDENT_ACCT_FACT_ID_N" precision="22" scale="0" />
<generator class="sequence">
<param name="sequence">INCIDENT_ACCT_FACT_SEQ</param>
</generator>
</id>
<many-to-one name="accountDim" class="com.***.***.****.AccountDim" fetch="select">
<column name="ACCT_DIM_ID_N" precision="22" scale="0" not-null="true" />
</many-to-one>
<many-to-one name="incidentDim" class="com.***.***.****.IncidentDim" fetch="select">
<column name="INCIDENT_DIM_ID_N" precision="22" scale="0" not-null="true" />
</many-to-one>
<!-- <many-to-one name="attachmentTypeDim" class="com.***.***.****.AttachmentTypeDim" fetch="select">
<column name="ATTACHMENT_TYPE_DIM_ID_N" precision="22" scale="0" not-null="false" />
</many-to-one> -->
<property name="relEffFromD" type="date">
<column name="REL_EFF_FROM_D" length="7" />
</property>
<property name="relEffThruD" type="date">
<column name="REL_EFF_THRU_D" length="7" />
</property>
<property name="ltstRelIndC" type="string">
<column name="LTST_REL_IND_C" length="1" />
</property>
<property name="delIndC" type="string">
<column name="DEL_IND_C" length="1" not-null="true" />
</property>
<property name="updUsrC" type="string">
<column name="UPD_USR_C" length="12" />
</property>
<property name="updTsD" type="date">
<column name="UPD_TS_D" length="7" />
</property>
<property name="insUsrC" type="string">
<column name="INS_USR_C" length="12" />
</property>
<property name="insTsD" type="date">
<column name="INS_TS_D" length="7" />
</property>
</class>
</hibernate-mapping>
IncidentAcctSecFact.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 Mar 19, 2012 9:24:47 AM by Hibernate Tools 3.3.0.GA -->
<hibernate-mapping>
<class name="com.***.***.****.IncidentAcctSecFact" table="V_INCIDENT_ACCT_SEC_FACT">
<id name="incidentAcctSecIdN" type="long">
<column name="INCIDENT_ACCT_SEC_ID_N" precision="22" scale="0" />
<generator class="sequence">
<param name="sequence">INCIDENT_ACCT_SEC_FACT_SEQ</param>
</generator>
</id>
<many-to-one name="accountDim" class="com.***.***.****.AccountDim" fetch="select">
<column name="ACCT_DIM_ID_N" precision="22" scale="0" not-null="true" />
</many-to-one>
<many-to-one name="cerSecurityDim" class="com.***.***.****.CerSecurityDim" fetch="select">
<column name="SECU_DIM_ID_N" precision="22" scale="0" not-null="true" />
</many-to-one>
<many-to-one name="incidentDim" class="com.***.***.****.IncidentDim" fetch="select">
<column name="INCIDENT_DIM_ID_N" precision="22" scale="0" not-null="true" />
</many-to-one>
<property name="relEffFromD" type="date">
<column name="REL_EFF_FROM_D" length="7" />
</property>
<property name="relEffThruD" type="date">
<column name="REL_EFF_THRU_D" length="7" />
</property>
<property name="ltstRelIndC" type="string">
<column name="LTST_REL_IND_C" length="1" />
</property>
<property name="delIndC" type="string">
<column name="DEL_IND_C" length="1" />
</property>
<property name="updUsrC" type="string">
<column name="UPD_USR_C" length="12" />
</property>
<property name="updTsD" type="date">
<column name="UPD_TS_D" length="7" />
</property>
<property name="insUsrC" type="string">
<column name="INS_USR_C" length="12" />
</property>
<property name="insTsD" type="date">
<column name="INS_TS_D" length="7" />
</property>
</class>
</hibernate-mapping>
The method where the actual processing is as follows.
public boolean retrieveDataAndParseFile(IncidentDetailsForm incidentDetailsForm, BaseViewBean baseViewBean$Session,
ActionMessages errors) throws Exception {
boolean savedStatus = false;
boolean deletedstatus = false;
/*List<AccountDim> accountsList = new ArrayList<AccountDim>();
List<CerSecurityDim> cerSecuList = new ArrayList<CerSecurityDim>();
List<IncidentAcctSecFact> inciAcctSecFactList = new ArrayList<IncidentAcctSecFact>();
List<IncidentAcctFact> inciAcctFactList = new ArrayList<IncidentAcctFact>();
List<IncidentDim> incidentList = new ArrayList<IncidentDim>();*/
try {
double totalSecGL= 0.00;
double secTrdNetTotal= 0.00;
DecimalFormat twoDForm = new DecimalFormat("#.##");
String loginUser = baseViewBean$Session.getLoggedInUser().getUserId();
List<Long> addedElementList = new ArrayList<Long>();
CerSecurityDim cerSecDim = null;
AccountDim account = null;
IncidentAcctSecFact iasFact = null;
IncidentAcctFact iaFact = null;
long incidentId = baseViewBean$Session.getIncidentDim$Session().getIncidentDimIdN();
IncidentDim incident = (IncidentDim)incidentDimDao.findById(IncidentDim.class, incidentId);
ExcelListenerBean beanDetails;
List<AccountDim> acctList = new ArrayList<AccountDim>();
List <CerSecurityDim> cerSecList = new ArrayList<CerSecurityDim>();
List <IncidentAcctSecFact> iasFactList = new ArrayList<IncidentAcctSecFact>();
for (Map.Entry<Integer, ExcelListenerBean> entry : baseViewBean$Session.getExcelRecords().entrySet())
{
beanDetails = entry.getValue();
//Initialize the net amounts for incorrect trade and correction trade.
secTrdNetTotal= 0;
cerSecDim = new CerSecurityDim();
account = new AccountDim();
iasFact = new IncidentAcctSecFact();
iaFact = new IncidentAcctFact();
//
Object[] pycisDet = investmentDimDao.getPyCISIdByShrtName(beanDetails.getShortName());
if(pycisDet != null && pycisDet.length > 0){
account.setPycisInstnIdN((Long)pycisDet[0]);
account.setGdwIdN((Long)pycisDet[1]);
account.setTrdSysShrtNmC(beanDetails.getShortName());
if(!addedElementList.contains((Long)pycisDet[0])){
addedElementList.add((Long)pycisDet[0]);
}
}
//
cerSecDim.setFmrCusipC(beanDetails.getFmrCusip());
SecurityDim sec = getSecDetailsByCusip(beanDetails.getFmrCusip());
if(sec != null){
cerSecDim.setSecuNmC(sec.getSecuNmC());
cerSecDim.setTckrC(sec.getTckrC());
}else {
cerSecDim.setSecuNmC("UNKNOWN");
cerSecDim.setTckrC("UNKNOWN");
}
//
cerSecDim.setNumOfShrTrdN(beanDetails.getIncorrectTrdShares().longValue());
//
cerSecDim.setBuySellIndC(beanDetails.getIncorrectTrdBuySell().toUpperCase());
account.setBuySellIndC(beanDetails.getIncorrectTrdBuySell().toUpperCase());
//
secTrdNetTotal = Double.valueOf(twoDForm.format(beanDetails.getIncorrectTrdNet())) +
Double.valueOf(twoDForm.format(beanDetails.getCorrectionTrdNet()));
//
totalSecGL = totalSecGL + secTrdNetTotal;
boolean updatedStatus = false;
// create the relationship and then add to the respective lists.
cerSecDim.setInsUsrC(loginUser);
cerSecDim.setInsTsD(AppGlobalUtil.getCurrentTimeStamp());
cerSecDim.setDelIndC(AppGlobalConstants.HardCodedValues.No);
if(!acctList.isEmpty()){
for( AccountDim olderAccount :acctList){
if(olderAccount.getPycisInstnIdN().compareTo(account.getPycisInstnIdN()) == 0) {
double newAcctGainLossAmt=0;
double oldAcctGainLossAmt=0;
if(account.getAcctGainLossAmtN() != null){
newAcctGainLossAmt = account.getAcctGainLossAmtN();
}
if(olderAccount.getAcctGainLossAmtN() != null){
oldAcctGainLossAmt = olderAccount.getAcctGainLossAmtN();
}
double newGLAmt = newAcctGainLossAmt + oldAcctGainLossAmt;
account = olderAccount;
account.setAcctGainLossAmtN(newGLAmt);
updatedStatus = true;
}
}
}
if(!cerSecList.isEmpty()){
for(CerSecurityDim olderCerSecDim : cerSecList){
if(olderCerSecDim.getFmrCusipC().equals(cerSecDim.getFmrCusipC())) {
cerSecDim = olderCerSecDim;
double newSecuGainLoss = 0;
double oldSecuGainLoss = 0;
if(cerSecDim.getSecuGainLossN() != null){
newSecuGainLoss = cerSecDim.getSecuGainLossN();
}
if(olderCerSecDim.getSecuGainLossN() != null){
oldSecuGainLoss = olderCerSecDim.getSecuGainLossN();
}
cerSecDim.setSecuGainLossN(newSecuGainLoss + oldSecuGainLoss);
for(IncidentAcctSecFact olderIASFact : iasFactList){
if(olderIASFact != null && olderIASFact.getCerSecurityDim() != null
&& olderIASFact.getCerSecurityDim().getFmrCusipC().equals(cerSecDim.getFmrCusipC())){
iasFact = olderIASFact;
}
}
}
}
}
if(!deletedstatus){
deleteAllImpactedAccounts(baseViewBean$Session);
deletedstatus = true;
}
totalSecGL = Double.valueOf(twoDForm.format(totalSecGL));
account.setInsUsrC(loginUser);
account.setInsTsD(AppGlobalUtil.getCurrentTimeStamp());
account.setDelIndC(AppGlobalConstants.HardCodedValues.No);
accountDimDao.saveOrUpdate(account);
iasFact.setAccountDim(account);
iasFact.setIncidentDim(incident);
iasFact.setCerSecurityDim(cerSecDim);
iasFact.setInsUsrC(loginUser);
iasFact.setInsTsD(AppGlobalUtil.getCurrentTimeStamp());
iasFact.setDelIndC(AppGlobalConstants.HardCodedValues.No);
cerSecDim.getIncidentAcctSecFacts().add(iasFact);
account.getIncidentAcctSecFacts().add(iasFact);
incident.getIncidentAcctSecFacts().add(iasFact);
if(!updatedStatus){
iaFact.setAccountDim(account);
iaFact.setIncidentDim(incident);
iaFact.setInsUsrC(loginUser);
iaFact.setInsTsD(AppGlobalUtil.getCurrentTimeStamp());
iaFact.setDelIndC(AppGlobalConstants.HardCodedValues.No);
incident.getIncidentAcctFacts().add(iaFact);
account.getIncidentAcctFacts().add(iaFact);
}
incident.setTotGainLossN(totalSecGL);
cerSecurityDimDao.saveOrUpdate(cerSecDim);
incidentAcctSecFactDao.saveOrUpdate(iasFact);
if(!updatedStatus){
accountDimDao.saveOrUpdate(account);
}
if(!acctList.contains(account)){
acctList.add(account);
}
if(!cerSecList.contains(cerSecDim)){
cerSecList.add(cerSecDim);
}
if(!iasFactList.contains(iasFact)){
iasFactList.add(iasFact);
}
if(!updatedStatus){
incidentAcctFactDao.saveOrUpdate(iaFact);
}
incidentDimDao.saveOrUpdate(incident);
NumberFormat formatter = new DecimalFormat("#0.00");
incidentDetailsForm.setTotalGainLoss(formatter.format(totalSecGL));
savedStatus = true;
/*accountsList.add(account);
cerSecuList.add(cerSecDim);
inciAcctSecFactList.add(iasFact);
inciAcctFactList.add(iaFact);
incidentList.add(incident);*/
}
} catch (Exception e) {
logger.error(e.getMessage());
e.printStackTrace();
throw e;
}
finally{
baseViewBean$Session.getExcelRecords().clear();
baseViewBean$Session.setExcelRecords(null);
}
/*accountDimDao.saveOrUpdateAll(accountsList);
cerSecurityDimDao.saveOrUpdateAll(cerSecuList);
incidentAcctSecFactDao.saveOrUpdateAll(inciAcctSecFactList);
incidentAcctFactDao.saveOrUpdateAll(inciAcctFactList);
incidentDimDao.saveOrUpdateAll(incidentList);*/
return savedStatus;
}
The dao functions are accessed from another file.
Please let me know how i can increase my performance.
The problem is that you are trying to do this from a browser, where the default timeout for a page is 30 seconds. You should be doing this from an application so that you can control the amount of time you wait to upload the records.
I am having lookalike problems.
Make sure that you have all keys for join and search fields.
May be you can store your file in temporary location and then handle it by paralell thread.
Another option is to use Stateless Sessions (there is almost no info on the net, see hibernate manual) I am not sure if there is an option to fill ManyToMany collections.
Caching getOrCreate queries by saving copy of table in memory may help you (but you may run into OutOfMemory exception, so pass -Xmx param to your app).
All these may not solve your problem. I've decided to implement these inserts using native sql queries.
There are multiple issues that should be looked at:
Long-running operations should be run asynchronously. If you are using Spring, you can annotate #Async, for instance. Then your transaction is not beholden to network connectivity or browser/HTTP timeouts.
Batch operations in Hibernate can be very slow. Even if you set up JDBC batching, and even if you follow the instructions in the Hibernate documentation, you are still beholden to the fact that you are using an ORM. ORMS are best used for maintaining state for object-oriented operations, not for batch operations, where any individual object's state is less relevant.
Batch operations in Hibernate can be very finicky. For instance, the Hibernate batching documentation fails to note that you need to set additional flags in the configuration to make sure that it batches correctly. See this post for details.
At the end of the day, ORMs will always be slower than base SQL. Consider swtiching over to base SQL, maybe concatenating SQL statements so that you have fewer database trips, or using a stored proc, passing bactches of data to the proc and have it run the inserts.
when you open session use openStatelessSession and call session.update at the end. this way persistentcontext cannot have 10000 object in cache and all the updates happens in db.