This is a different problem with different mappings and tables, than my previous post.
I have a 3 level cascade mapping and the select works fine.
However at the insert i am not able to insert the child does not get the id of the parent.
Regards
Suchak Jani
Here is my mapping file
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd" >
<hibernate-mapping>
<class name="com.esm.payroll.enterprise.company.vo.CompanyListVO" table="T_M_COMPANY">
<id name="companyId" type="int" column="COMPANY_ID">
<generator class="assigned" />
</id>
<property name="companyCode" type="java.lang.String" column="COMPANY_CODE" not-null="true" length="4" />
<property name="status" type="java.lang.String" column="STATUS" not-null="true" length="1" />
<property name="companyName" type="java.lang.String" column="COMPANY_NAME" not-null="true" length="30" />
</class>
<class name="com.esm.payroll.enterprise.company.vo.CompanyVO" table="T_M_COMPANY">
<id name="companyId" type="int" column="COMPANY_ID">
<generator class="com.esm.common.dbwrappers.ESMSequenceGen"/>
</id>
<property name="companyCode" type="java.lang.String" column="COMPANY_CODE" not-null="true" length="30" />
<property name="status" type="java.lang.String" column="STATUS" not-null="true" length="1" />
<property name="acrdprAcrlGLAcct" type="java.lang.Integer" column="ACRDPR_ACRL_GLACCT" not-null="true" length="10" />
<property name="pymntCalcGlDate" type="java.lang.String" column="PYMT_CALC_GL_DATE" not-null="true" length="10" />
<property name="erngCurrPostTo" type="java.lang.String" column="ERNG_CURR_POST_TO" not-null="true" length="10" />
<property name="companyName" type="java.lang.String" column="COMPANY_NAME" not-null="true" length="30" />
<property name="erngAllwPostTo" type="java.lang.String" column="ERNG_ALLW_POST_TO" not-null="true" length="10" />
<property name="erngAcrlPostTo" type="java.lang.String" column="ERNG_ACRL_POST_TO" not-null="true" length="10" />
<property name="created" type="java.sql.Timestamp" column="CREATED" not-null="false" length="10" />
<property name="lastModified" type="java.sql.Timestamp" column="LAST_MODIFIED" not-null="false" length="10" />
<property name="erngAdvPostTo" type="java.lang.String" column="ERNG_ADV_POST_TO" not-null="true" length="10" />
<property name="dednStatusPostTo" type="java.lang.String" column="DEDN_STATU_POST_TO" not-null="true" length="10" />
<property name="dednInvlnPostTo" type="java.lang.String" column="DEDN_INVLN_POST_TO" not-null="true" length="10" />
<property name="acrdprCurrGLAcct" type="java.lang.Integer" column="ACRDPR_CURR_GLACCT" not-null="true" length="4" />
<property name="dednOTHPostTo" type="java.lang.String" column="DEDN_OTH_POST_TO" not-null="true" length="10" />
<property name="dednVolnPostTo" type="java.lang.String" column="DEDN_VOLN_POST_TO" not-null="true" length="10" />
<property name="acrdprAdvGLAcct" type="int" column="ACRDPR_ADV_GLACCT" not-null="false" length="10" />
<property name="erngREIMPostTo" type="java.lang.String" column="ERNG_REIM_POST_TO" not-null="true" length="10" />
<property name="acrdprReimGLAcct" type="java.lang.Integer" column="ACRDPR_REIM_GLACCT" not-null="false" length="10" />
<property name="acrdprAdvGLAcct" type="java.lang.Integer" column="ACRDPR_ALLW_GLACCT" not-null="false" length="10" />
<property name="intrcorpAsstGlacct" type="int" column="INTRCORP_ASST_GLACCT" not-null="false" length="10" />
<property name="intrcorpLiabGlacct" type="int" column="INTRCORP_LIAB_GLACCT" not-null="false" length="10" />
<property name="serviceId" type="int" column="SERVICE_ID " not-null="false" length="4" />
<bag name="address" inverse="true" lazy="true" cascade="all">
<key column="OWNER_ID"/>
<one-to-many class="com.esm.payroll.enterprise.vo.AddressVO" />
</bag>
<bag name="contacts" inverse="true" lazy="true" cascade="all">
<key column="OWNER_ID" />
<one-to-many class="com.esm.payroll.enterprise.vo.ContactsVO" />
</bag>
</class>
<class name="com.esm.payroll.enterprise.vo.AddressVO" table="T_M_ADDRESS">
<id name="addressId" type="int" column="ADDRESS_ID">
<generator class="com.esm.common.dbwrappers.ESMSequenceGen"/>
</id>
<property name="addressLine1" type="java.lang.String" column="ADDRESS_LINE1" not-null="true" length="30" />
<property name="ownerType" type="java.lang.String" column="OWNER_TYPE" not-null="false" length="10" />
<property name="addressLine2" type="java.lang.String" column="ADDRESS_LINE2" not-null="false" length="30" />
<property name="zipCodeExtn" type="java.lang.String" column="ZIP_CODE_EXTN" not-null="false" length="4" />
<property name="created" type="java.sql.Timestamp" column="CREATED" not-null="false" length="10" />
<property name="lastModified" type="java.sql.Timestamp" column="LAST_MODIFIED" not-null="true" length="10" />
<property name="defaultAddress" type="java.lang.String" column="DEFAULT" not-null="false" length="1" />
<property name="city" type="java.lang.String" column="CITY" not-null="false" length="20" />
<property name="state" type="java.lang.String" column="STATE" not-null="false" length="2" />
<property name="country" type="java.lang.String" column="COUNTRY" not-null="false" length="20" />
<property name="ownerId" type="java.lang.String" column="OWNER_ID" not-null="false" length="20" />
<property name="status" type="java.lang.String" column="STATUS" not-null="true" length="1" />
<property name="zip" type="java.lang.String" column="ZIP" not-null="false" length="5" />
<property name="lastModifiedBy" type="java.lang.Integer" column="LAST_MODIFIED_BY" not-null="false" length="4" />
</class>
<class name="com.esm.payroll.enterprise.vo.ContactsVO" table="T_M_CONTACT">
<id name="contactId" type="java.lang.Integer" column="CONTACT_ID" unsaved-value="null">
<generator class="com.esm.common.dbwrappers.ESMSequenceGen"/>
</id>
<property name="contactType" type="java.lang.String" column="CONTACT_TYPE" not-null="false" length="15" />
<property name="contactFname" type="java.lang.String" column="CONTACT_FNAME" not-null="true" length="20" />
<property name="emailAddress1" type="java.lang.String" column="EMAIL_ADDRESS1" not-null="true" length="30" />
<property name="contactMName" type="java.lang.String" column="CONTACT_MNAME" not-null="true" length="20" />
<property name="contactLName" type="java.lang.String" column="CONTACT_LNAME" not-null="true" length="20" />
<property name="ownerId" type="java.lang.String" column="OWNER_ID" not-null="true" length="20" />
<property name="contactTitleId" type="java.lang.String" column="CONTACT_TITLE_ID" not-null="false" length="20" />
<property name="emailAddress2" type="java.lang.String" column="EMAIL_ADDRESS2" not-null="false" length="30" />
<property name="status" type="java.lang.String" column="STATUS" not-null="true" length="1" />
<property name="createdBy" type="java.lang.Integer" column="CREATED_BY" not-null="false" length="4" />
<property name="lastModifiedBy" type="java.lang.Integer" column="LAST_MODIFIED_BY" not-null="false" length="4" />
<property name="created" type="java.sql.Timestamp" column="CREATED" not-null="false" length="10" />
<property name="lastModified" type="java.sql.Timestamp" column="LAST_MODIFIED" not-null="true" length="10" />
<property name="defaultContact" type="java.lang.String" column="DEFAULT" not-null="false" length="1" />
<bag name="telephone" inverse="true" lazy="false" where="OWNER_TYPE='T_M_CONTACT' and DEFAULT='Y'" cascade="all">
<key column="OWNER_ID"/>
<one-to-many class="com.esm.payroll.enterprise.vo.TelephoneVO" />
</bag>
</class>
<class name="com.esm.payroll.enterprise.vo.TelephoneVO" table="T_M_TELEPHONE">
<id name="telephoneId" type="int" column="TELEPHONE_ID" unsaved-value="null">
<generator class="com.esm.common.dbwrappers.ESMSequenceGen"/>
</id>
<property name="telephoneType" type="java.lang.String" column="TELEPHONE_TYPE" not-null="false" length="10" />
<property name="telephoneNumber" type="java.lang.String" column="TELEPHONE_NUMBER" not-null="true" length="20" />
<property name="ownerType" type="java.lang.String" column="OWNER_TYPE" length="10"
/>
<property name="status" type="java.lang.String" column="STATUS" not-null="true" length="1" />
<property name="createdBy" type="java.lang.Integer" column="CREATED_BY" length="4" />
<property name="lastModifiedBy" type="java.lang.Integer" column="LAST_MODIFIED_BY" not-null="false" length="4" />
<property name="created" type="java.sql.Timestamp" column="CREATED" length="10"
not-null="false"/>
<property name="lastModified" type="java.sql.Timestamp" column="LAST_MODIFIED" not-null="false" length="10" />
<property name="defaultTelephone" type="java.lang.String" column="DEFAULT" length="1" />
<property name="areaCode" type="int" column="TELEPHONE_AREACODE" not-null="false" length="4" />
<property name="ownerId" type="int" column="OWNER_ID" not-null="true" length="15" />
</class>
</hibernate-mapping>
Here is my code
Code:
package com.esm.payroll.enterprise.vo;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.ToStringBuilder;
import com.esm.common.vo.ESMDataInterface;
public class ContactsVO implements Serializable,ESMDataInterface {
/** identifier field */
private Integer contactId;
/** nullable persistent field */
private String contactType;
/** persistent field */
private String contactFname;
/** persistent field */
private String emailAddress1;
/** persistent field */
private String contactMName;
/** persistent field */
private String contactLName;
/** persistent field */
private String ownerId;
/** nullable persistent field */
private String contactTitleId;
/** nullable persistent field */
private String emailAddress2;
/** persistent field */
private String status;
/** persistent field */
private Integer createdBy;
/** nullable persistent field */
private Integer lastModifiedBy;
/** persistent field */
private java.util.Date created;
/** persistent field */
private java.util.Date lastModified;
/** nullable persistent field */
private String defaultContact;
/** nullable persistent field */
private String ownerType;
/** persistent field */
private Collection telephone ;
/** full constructor */
public ContactsVO(java.lang.Integer contactId, java.lang.String contactType, java.lang.String contactFname, java.lang.String emailAddress1, java.lang.String contactMName, java.lang.String contactLName, java.lang.String ownerId, java.lang.String contactTitleId, java.lang.String emailAddress2, java.lang.String status, Integer createdBy, Integer lastModifiedBy, java.util.Date created, java.util.Date lastModified, java.lang.String defaultContact, java.lang.String ownerType, Collection telephone) {
this.contactId = contactId;
this.contactType = contactType;
this.contactFname = contactFname;
this.emailAddress1 = emailAddress1;
this.contactMName = contactMName;
this.contactLName = contactLName;
this.ownerId = ownerId;
this.contactTitleId = contactTitleId;
this.emailAddress2 = emailAddress2;
this.status = status;
this.createdBy = createdBy;
this.lastModifiedBy = lastModifiedBy;
this.created = created;
this.lastModified = lastModified;
this.defaultContact = defaultContact;
this.ownerType = ownerType;
this.telephone = telephone;
}
/** default constructor */
public ContactsVO() {
}
/** minimal constructor */
public ContactsVO(java.lang.Integer contactId, java.lang.String contactFname, java.lang.String emailAddress1, java.lang.String contactMName, java.lang.String contactLName, java.lang.String ownerId, java.lang.String status, Integer createdBy, java.util.Date created, java.util.Date lastModified, Collection telephone) {
this.contactId = contactId;
this.contactFname = contactFname;
this.emailAddress1 = emailAddress1;
this.contactMName = contactMName;
this.contactLName = contactLName;
this.ownerId = ownerId;
this.status = status;
this.createdBy = createdBy;
this.created = created;
this.lastModified = lastModified;
this.telephone = telephone;
}
public java.lang.Integer getContactId() {
return this.contactId;
}
public void setContactId(java.lang.Integer contactId) {
this.contactId = contactId;
}
public java.lang.String getContactType() {
return this.contactType;
}
public void setContactType(java.lang.String contactType) {
this.contactType = contactType;
}
public java.lang.String getContactFname() {
return this.contactFname;
}
public void setContactFname(java.lang.String contactFname) {
this.contactFname = contactFname;
}
public java.lang.String getEmailAddress1() {
return this.emailAddress1;
}
public void setEmailAddress1(java.lang.String emailAddress1) {
this.emailAddress1 = emailAddress1;
}
public java.lang.String getContactMName() {
return this.contactMName;
}
public void setContactMName(java.lang.String contactMName) {
this.contactMName = contactMName;
}
public java.lang.String getContactLName() {
return this.contactLName;
}
public void setContactLName(java.lang.String contactLName) {
this.contactLName = contactLName;
}
public java.lang.String getOwnerId() {
return this.ownerId;
}
public void setOwnerId(java.lang.String ownerId) {
this.ownerId = ownerId;
}
public java.lang.String getContactTitleId() {
return this.contactTitleId;
}
public void setContactTitleId(java.lang.String contactTitleId) {
this.contactTitleId = contactTitleId;
}
public java.lang.String getEmailAddress2() {
return this.emailAddress2;
}
public void setEmailAddress2(java.lang.String emailAddress2) {
this.emailAddress2 = emailAddress2;
}
public java.lang.String getStatus() {
return this.status;
}
public void setStatus(java.lang.String status) {
this.status = status;
}
public java.util.Date getCreated() {
return this.created;
}
public void setCreated(java.util.Date created) {
this.created = created;
}
public java.util.Date getLastModified() {
return this.lastModified;
}
public void setLastModified(java.util.Date lastModified) {
this.lastModified = lastModified;
}
public java.lang.String getDefaultContact() {
return this.defaultContact;
}
public void setDefaultContact(java.lang.String defaultContact) {
this.defaultContact = defaultContact;
}
public java.lang.String getOwnerType() {
return this.ownerType;
}
public void setOwnerType(java.lang.String ownerType) {
this.ownerType = ownerType;
}
public java.util.Collection getTelephone() {
return this.telephone;
}
public void setTelephone(java.util.Collection telephone) {
System.out.println("Set Telephone without Index called");
int telephoneSize = ((List)telephone).size();
if(telephoneSize < 4){
int extraAddition = 4-telephoneSize;
System.out.println("Telephone entries in database"+telephoneSize);
for(int addCounter=0;addCounter<extraAddition;addCounter++){
((List)telephone).add(new TelephoneVO());
}
this.telephone = telephone;
}
System.out.println("Telephone Collection after adding "+((List)telephone).size());
}
public String toString() {
return new ToStringBuilder(this)
.append("contactId", getContactId())
.toString();
}
public boolean equals(Object other) {
if ( !(other instanceof ContactsVO) ) return false;
ContactsVO castOther = (ContactsVO) other;
return new EqualsBuilder()
.append(this.getContactId(), castOther.getContactId())
.isEquals();
}
public int hashCode() {
return new HashCodeBuilder()
.append(getContactId())
.toHashCode();
}
/**
* Returns the lastModifiedBy.
* @return Integer
*/
public Integer getLastModifiedBy() {
return lastModifiedBy;
}
/**
* Sets the lastModifiedBy.
* @param lastModifiedBy The lastModifiedBy to set
*/
public void setLastModifiedBy(Integer lastModifiedBy) {
this.lastModifiedBy = lastModifiedBy;
}
/**
* Returns the createdBy.
* @return Integer
*/
public Integer getCreatedBy() {
return createdBy;
}
/**
* Sets the createdBy.
* @param createdBy The createdBy to set
*/
public void setCreatedBy(Integer createdBy) {
this.createdBy = createdBy;
}
public void setTelephone(int index,TelephoneVO telephoneVO) {
System.out.println("Set telephone with indexc called");
/*
if(null == telephone){
System.out.println("Telephone Liust is null");
telephone = new ArrayList();
}
*/
((List)telephone).set(index, telephoneVO);
}
public Object getPrimaryKey() {
return contactId;
}
}
package com.esm.payroll.enterprise.company.vo;
import com.esm.common.vo.ESMDataInterface;
import com.esm.payroll.enterprise.vo.AddressVO;
import com.esm.payroll.enterprise.vo.ContactsVO;
import com.esm.payroll.enterprise.vo.TelephoneVO;
import java.io.Serializable;
import java.util.Collection;
import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.ToStringBuilder;
public class CompanyVO implements Serializable ,ESMDataInterface{
/** identifier field */
private Integer companyId;
private String serviceBureau = "N";
private boolean serviceBureauTrue = false;
/** persistent field */
private String companyCode;
/** persistent field */
private String status;
private Integer acrdprCurrGLAcct;
private Integer acrdprAllowGLAcct;
private Integer acrdprAdvGLAcct;
private Integer acrdprReimGLAcct;
private Integer acrdprAcrlGLAcct ;
/** persistent field */
private String pymntCalcGlDate;
/** persistent field */
private String erngCurrPostTo;
/** persistent field */
private String companyName;
/** persistent field */
private String erngAllwPostTo;
/** persistent field */
private String erngAcrlPostTo;
/** persistent field */
private java.util.Date created;
/** persistent field */
private java.util.Date lastModified;
/** persistent field */
private String erngAdvPostTo;
/** persistent field */
private String dednStatusPostTo;
/** persistent field */
private String dednInvlnPostTo;
/** persistent field */
private int acrdprCurrGlAcct;
/** persistent field */
private String dednOTHPostTo;
/** persistent field */
private String dednVolnPostTo;
/** nullable persistent field */
private int acrdprAdvGlAcct;
/** persistent field */
private String erngREIMPostTo;
/** nullable persistent field */
private String acrdprREIMGlAcct;
/** nullable persistent field */
private Integer intrcorpAsstGlacct;
/** nullable persistent field */
private Integer intrcorpLiabGlacct;
/** nullable persistent field */
private Integer serviceId;
/** persistent field */
private Collection address;
/** persistent field */
private Collection contacts;
/** full constructor */
public CompanyVO(java.lang.Integer companyId, java.lang.String companyCode, java.lang.String status, java.lang.String pymntCalcGlDate, java.lang.String erngCurrPostTo, java.lang.String companyName, java.lang.String erngAllwPostTo, java.lang.String erngAcrlPostTo, java.util.Date created, java.util.Date lastModified, java.lang.String erngAdvPostTo, java.lang.String dednStatusPostTo, java.lang.String dednInvlnPostTo, int acrdprCurrGlAcct, java.lang.String dednOTHPostTo, java.lang.String dednVolnPostTo, int acrdprAdvGlAcct, java.lang.String erngREIMPostTo, java.lang.String acrdprREIMGlAcct, java.lang.Integer intrcorpAsstGlacct, java.lang.Integer intrcorpLiabGlacct, Integer serviceId, Collection address, Collection contacts, Collection telephone) {
this.companyId = companyId;
this.companyCode = companyCode;
this.status = status;
this.pymntCalcGlDate = pymntCalcGlDate;
this.erngCurrPostTo = erngCurrPostTo;
this.companyName = companyName;
this.erngAllwPostTo = erngAllwPostTo;
this.erngAcrlPostTo = erngAcrlPostTo;
this.created = created;
this.lastModified = lastModified;
this.erngAdvPostTo = erngAdvPostTo;
this.dednStatusPostTo = dednStatusPostTo;
this.dednInvlnPostTo = dednInvlnPostTo;
this.acrdprCurrGlAcct = acrdprCurrGlAcct;
this.dednOTHPostTo = dednOTHPostTo;
this.dednVolnPostTo = dednVolnPostTo;
this.acrdprAdvGlAcct = acrdprAdvGlAcct;
this.erngREIMPostTo = erngREIMPostTo;
this.acrdprREIMGlAcct = acrdprREIMGlAcct;
this.intrcorpAsstGlacct = intrcorpAsstGlacct;
this.intrcorpLiabGlacct = intrcorpLiabGlacct;
this.serviceId = serviceId;
this.address = address;
this.contacts = contacts;
}
/** default constructor */
public CompanyVO() {
}
/** minimal constructor */
public CompanyVO(java.lang.Integer companyId, java.lang.String companyCode, java.lang.String status, java.lang.String pymntCalcGlDate, java.lang.String erngCurrPostTo, java.lang.String companyName, java.lang.String erngAllwPostTo, java.lang.String erngAcrlPostTo, java.util.Date created, java.util.Date lastModified, java.lang.String erngAdvPostTo, java.lang.String dednStatusPostTo, java.lang.String dednInvlnPostTo, int acrdprCurrGlAcct, java.lang.String dednOTHPostTo, java.lang.String dednVolnPostTo, java.lang.String erngREIMPostTo, Collection address, Collection contacts, Collection telephone) {
this.companyId = companyId;
this.companyCode = companyCode;
this.status = status;
this.pymntCalcGlDate = pymntCalcGlDate;
this.erngCurrPostTo = erngCurrPostTo;
this.companyName = companyName;
this.erngAllwPostTo = erngAllwPostTo;
this.erngAcrlPostTo = erngAcrlPostTo;
this.created = created;
this.lastModified = lastModified;
this.erngAdvPostTo = erngAdvPostTo;
this.dednStatusPostTo = dednStatusPostTo;
this.dednInvlnPostTo = dednInvlnPostTo;
this.acrdprCurrGlAcct = acrdprCurrGlAcct;
this.dednOTHPostTo = dednOTHPostTo;
this.dednVolnPostTo = dednVolnPostTo;
this.erngREIMPostTo = erngREIMPostTo;
this.address = address;
this.contacts = contacts;
}
public java.lang.Integer getCompanyId() {
return this.companyId;
}
public void setCompanyId(java.lang.Integer companyId) {
this.companyId = companyId;
}
public java.lang.String getCompanyCode() {
return this.companyCode;
}
public void setCompanyCode(java.lang.String companyCode) {
this.companyCode = companyCode;
}
public java.lang.String getStatus() {
return this.status;
}
public void setStatus(java.lang.String status) {
this.status = status;
}
public java.lang.String getPymntCalcGlDate() {
return this.pymntCalcGlDate;
}
public void setPymntCalcGlDate(java.lang.String pymntCalcGlDate) {
this.pymntCalcGlDate = pymntCalcGlDate;
}
public java.lang.String getErngCurrPostTo() {
System.out.println("???????????Get erngCurrPostTo called????????"+erngCurrPostTo);
return this.erngCurrPostTo;
}
public void setErngCurrPostTo(java.lang.String erngCurrPostTo) {
System.out.println("////////////////Set erngCurrPostTo called///////////"+erngCurrPostTo);
this.erngCurrPostTo = erngCurrPostTo;
}
public java.lang.String getCompanyName() {
return this.companyName;
}
public void setCompanyName(java.lang.String companyName) {
this.companyName = companyName;
}
public java.lang.String getErngAllwPostTo() {
return this.erngAllwPostTo;
}
public void setErngAllwPostTo(java.lang.String erngAllwPostTo) {
this.erngAllwPostTo = erngAllwPostTo;
}
public java.lang.String getErngAcrlPostTo() {
return this.erngAcrlPostTo;
}
public void setErngAcrlPostTo(java.lang.String erngAcrlPostTo) {
this.erngAcrlPostTo = erngAcrlPostTo;
}
public java.util.Date getCreated() {
return this.created;
}
public void setCreated(java.util.Date created) {
this.created = created;
}
public java.util.Date getLastModified() {
return this.lastModified;
}
public void setLastModified(java.util.Date lastModified) {
this.lastModified = lastModified;
}
public java.lang.String getErngAdvPostTo() {
return this.erngAdvPostTo;
}
public void setErngAdvPostTo(java.lang.String erngAdvPostTo) {
this.erngAdvPostTo = erngAdvPostTo;
}
public java.lang.String getDednStatusPostTo() {
return this.dednStatusPostTo;
}
public void setDednStatusPostTo(java.lang.String dednStatusPostTo) {
this.dednStatusPostTo = dednStatusPostTo;
}
public java.lang.String getDednInvlnPostTo() {
return this.dednInvlnPostTo;
}
public void setDednInvlnPostTo(java.lang.String dednInvlnPostTo) {
this.dednInvlnPostTo = dednInvlnPostTo;
}
public int getAcrdprCurrGlAcct() {
return this.acrdprCurrGlAcct;
}
public void setAcrdprCurrGlAcct(int acrdprCurrGlAcct) {
this.acrdprCurrGlAcct = acrdprCurrGlAcct;
}
public java.lang.String getDednOTHPostTo() {
return this.dednOTHPostTo;
}
public void setDednOTHPostTo(java.lang.String dednOTHPostTo) {
this.dednOTHPostTo = dednOTHPostTo;
}
public java.lang.String getDednVolnPostTo() {
return this.dednVolnPostTo;
}
public void setDednVolnPostTo(java.lang.String dednVolnPostTo) {
this.dednVolnPostTo = dednVolnPostTo;
}
public int getAcrdprAdvGlAcct() {
return this.acrdprAdvGlAcct;
}
public void setAcrdprAdvGlAcct(int acrdprAdvGlAcct) {
this.acrdprAdvGlAcct = acrdprAdvGlAcct;
}
public java.lang.String getErngREIMPostTo() {
return this.erngREIMPostTo;
}
public void setErngREIMPostTo(java.lang.String erngREIMPostTo) {
this.erngREIMPostTo = erngREIMPostTo;
}
public java.lang.String getAcrdprREIMGlAcct() {
return this.acrdprREIMGlAcct;
}
public void setAcrdprREIMGlAcct(java.lang.String acrdprREIMGlAcct) {
this.acrdprREIMGlAcct = acrdprREIMGlAcct;
}
public java.util.Collection getAddress() {
return this.address;
}
public void setAddress(java.util.Collection address) {
this.address = address;
}
public java.util.Collection getContacts() {
return this.contacts;
}
public void setContacts(java.util.Collection contacts) {
this.contacts = contacts;
}
public String toString() {
return new ToStringBuilder(this)
.append("companyId", getCompanyId())
.toString();
}
public boolean equals(Object other) {
if ( !(other instanceof CompanyVO) ) return false;
CompanyVO castOther = (CompanyVO) other;
return new EqualsBuilder()
.append(this.getCompanyId(), castOther.getCompanyId())
.isEquals();
}
public int hashCode() {
return new HashCodeBuilder()
.append(getCompanyId())
.toHashCode();
}
public Object getPrimaryKey() {
return companyId;
}
/**
* Returns the serviceBureau.
* @return String
*/
public String getServiceBureau() {
return serviceBureau;
}
/**
* Returns the serviceBureauTrue.
* @return boolean
*/
public boolean isServiceBureauTrue() {
return serviceBureauTrue;
}
/**
* Sets the serviceBureau.
* @param serviceBureau The serviceBureau to set
*/
public void setServiceBureau(String serviceBureau) {
if(serviceBureau.equals("Y")){
this.serviceBureauTrue = true;
}
this.serviceBureau = serviceBureau;
}
/**
* Sets the serviceBureauTrue.
* @param serviceBureauTrue The serviceBureauTrue to set
*/
public void setServiceBureauTrue(boolean serviceBureauTrue) {
if (serviceBureauTrue == true){
this.serviceBureau = "Y";
}
else{
this.serviceBureau = "N";
}
this.serviceBureauTrue = serviceBureauTrue;
this.serviceBureauTrue = serviceBureauTrue;
}
/**
* Returns the intrcorpAsstGlacct.
* @return Integer
*/
public Integer getIntrcorpAsstGlacct() {
return intrcorpAsstGlacct;
}
/**
* Returns the intrcorpLiabGlacct.
* @return Integer
*/
public Integer getIntrcorpLiabGlacct() {
return intrcorpLiabGlacct;
}
/**
* Returns the serviceId.
* @return Integer
*/
public Integer getServiceId() {
return serviceId;
}
/**
* Sets the intrcorpAsstGlacct.
* @param intrcorpAsstGlacct The intrcorpAsstGlacct to set
*/
public void setIntrcorpAsstGlacct(Integer intrcorpAsstGlacct) {
this.intrcorpAsstGlacct = intrcorpAsstGlacct;
}
/**
* Sets the intrcorpLiabGlacct.
* @param intrcorpLiabGlacct The intrcorpLiabGlacct to set
*/
public void setIntrcorpLiabGlacct(Integer intrcorpLiabGlacct) {
this.intrcorpLiabGlacct = intrcorpLiabGlacct;
}
/**
* Sets the serviceId.
* @param serviceId The serviceId to set
*/
public void setServiceId(Integer serviceId) {
this.serviceId = serviceId;
}
/**
* Returns the acrdprAcrlGLAcct.
* @return Integer
*/
public Integer getAcrdprAcrlGLAcct() {
return acrdprAcrlGLAcct;
}
/**
* Returns the acrdprAdvGLAcct.
* @return Integer
*/
public Integer getAcrdprAdvGLAcct() {
return acrdprAdvGLAcct;
}
/**
* Returns the acrdprAllowGLAcct.
* @return Integer
*/
public Integer getAcrdprAllowGLAcct() {
return acrdprAllowGLAcct;
}
/**
* Returns the acrdprReimGLAcct.
* @return Integer
*/
public Integer getAcrdprReimGLAcct() {
return acrdprReimGLAcct;
}
/**
* Sets the acrdprAcrlGLAcct.
* @param acrdprAcrlGLAcct The acrdprAcrlGLAcct to set
*/
public void setAcrdprAcrlGLAcct(Integer acrdprAcrlGLAcct) {
this.acrdprAcrlGLAcct = acrdprAcrlGLAcct;
}
/**
* Sets the acrdprAdvGLAcct.
* @param acrdprAdvGLAcct The acrdprAdvGLAcct to set
*/
public void setAcrdprAdvGLAcct(Integer acrdprAdvGLAcct) {
this.acrdprAdvGLAcct = acrdprAdvGLAcct;
}
/**
* Sets the acrdprAllowGLAcct.
* @param acrdprAllowGLAcct The acrdprAllowGLAcct to set
*/
public void setAcrdprAllowGLAcct(Integer acrdprAllowGLAcct) {
this.acrdprAllowGLAcct = acrdprAllowGLAcct;
}
/**
* Sets the acrdprReimGLAcct.
* @param acrdprReimGLAcct The acrdprReimGLAcct to set
*/
public void setAcrdprReimGLAcct(Integer acrdprReimGLAcct) {
this.acrdprReimGLAcct = acrdprReimGLAcct;
}
/**
* Returns the acrdprCurrGLAcct.
* @return Integer
*/
public Integer getAcrdprCurrGLAcct() {
return acrdprCurrGLAcct;
}
/**
* Sets the acrdprCurrGLAcct.
* @param acrdprCurrGLAcct The acrdprCurrGLAcct to set
*/
public void setAcrdprCurrGLAcct(Integer acrdprCurrGLAcct) {
this.acrdprCurrGLAcct = acrdprCurrGLAcct;
}
}
package com.esm.payroll.enterprise.company.dao;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import net.sf.hibernate.HibernateException;
import com.esm.common.dao.ESMGlobalDAO;
import com.esm.common.dbwrappers.ESMQuery;
import com.esm.common.dbwrappers.ESMTransaction;
import com.esm.common.exception.ESMDataException;
import com.esm.common.utils.ESMConstants;
import com.esm.payroll.enterprise.company.vo.CompanyListVO;
import com.esm.payroll.enterprise.company.vo.CompanyVO;
import com.esm.payroll.enterprise.vo.AddressVO;
import com.esm.payroll.enterprise.vo.ContactsVO;
import com.esm.payroll.enterprise.vo.TelephoneVO;
public class CompanyDAO extends ESMGlobalDAO{
public List getCompanyList() throws ESMDataException{
List companyList = null;
try{
//String selStmt = "select * from T_M_COMPANY as clist";
ESMQuery query = session.createQuery(ESMConstants.COMPANY_LIST_QUERY);
System.out.println("Got the query in DAO class");
companyList= query.list();
return companyList;
//ESMQuery companyQuery = super.sess.getNamedQuery(ESMConstants.COMPANY_LIST_QUERY);
//companyList = companyQuery.list();
}
catch(HibernateException he){
System.out.println("Hibernate Exception in getCompanyList"+he);
ESMDataException dataExcep = new ESMDataException(he.getMessage());
dataExcep.setRootCause(he);
throw dataExcep;
}
catch(Exception e){
System.out.println("generic Exception in getCompanyList"+e);
ESMDataException dataExcep = new ESMDataException(e.getMessage());
dataExcep.setRootCause(e);
throw dataExcep;
}
//return companyList;
}
public CompanyVO getCompanyDetails(String companyId) throws ESMDataException{
List companyDetailList = null;
CompanyVO compDetailVO = null;
try{
companyDetailList = new ArrayList();
int compId = Integer.parseInt(companyId);
compDetailVO = (CompanyVO)(session.find("from CompanyVO as compVO where compVO.companyId = "+compId )).get(0);
System.out.println("Copnay Detail VO loaded in DAO");
List address = (List)compDetailVO.getAddress();
Iterator iter = address.iterator();
while(iter.hasNext()){
System.out.println("Adress object in DAO"+(AddressVO)iter.next());
}
return compDetailVO;
}
catch(HibernateException he){
System.out.println("Hibernate Exception in getCompanyDetails"+he);
ESMDataException dataExcep = new ESMDataException(he.getMessage());
dataExcep.setRootCause(he);
//session.close();
throw dataExcep;
}
catch(Exception e){
System.out.println("generic Exception in getDetails"+e);
e.printStackTrace();
ESMDataException dataExcep = new ESMDataException(e.getMessage());
dataExcep.setRootCause(e);
//session.close();
throw dataExcep;
}
finally{
//session.close();
}
//return companyList;
}
public AddressVO getAddressDetail(String companyId) throws ESMDataException{
AddressVO addressVO = null;
CompanyVO compDetailVO = null; try{
int compId = Integer.parseInt(companyId);
addressVO = (AddressVO)(session.find("from AddressVO as addressVO where addressVO.addressId = "+compId)).get(0);
//System.out.println("Adress VO loaded in DAO"+addressVO.getAddressLine1());
return addressVO;
}
catch(HibernateException he){
System.out.println("Hibernate Exception in getAddressDetail"+he);
ESMDataException dataExcep = new ESMDataException(he.getMessage());
dataExcep.setRootCause(he);
//session.close();
throw dataExcep;
}
catch(Exception e){
System.out.println("generic Exception in getAddressDetail"+e);
e.printStackTrace();
ESMDataException dataExcep = new ESMDataException(e.getMessage());
dataExcep.setRootCause(e);
//session.close();
throw dataExcep;
}
finally{
//session.close();
}
//return companyList;
}
public ContactsVO getContactDetail(String companyId) throws ESMDataException{
ContactsVO contactVO = null;
try{
int compId = Integer.parseInt(companyId);
contactVO = (ContactsVO)(session.find("from ContactsVO as contactVO where contactVO.contactId = "+compId)).get(0);
System.out.println("Adress VO loaded in DAO");
session.close();
return contactVO;
}
catch(HibernateException he){
System.out.println("Hibernate Exception in getContactDetail"+he);
ESMDataException dataExcep = new ESMDataException(he.getMessage());
dataExcep.setRootCause(he);
//session.close();
throw dataExcep;
}
catch(Exception e){
System.out.println("generic Exception in getContactDetail"+e);
e.printStackTrace();
ESMDataException dataExcep = new ESMDataException(e.getMessage());
dataExcep.setRootCause(e);
//session.close();
throw dataExcep;
}
finally{
//session.close();
}
//return companyList;
}
public ContactsVO saveContacts(ContactsVO contactVO) throws ESMDataException{
try{
session.evict(contactVO);
/*
THIS METHOD CANNOT BE USED BECAUSE WE NEED TO SEPERATE INSERTS AND UPDATES
HAD THIS BEEN NOT THE CASE WE COULD HAVE USED THIS METHOD
ESMTransaction transaction = null;
transaction = session.beginTransaction();
session.saveOrUpdate(contactVO);
session.flush();
transaction.commit();
session.refresh(contactVO);
System.out.println("Transaction commited in saveContacts DAO");
*/
List telephoneList = (List)contactVO.getTelephone();
System.out.println("Telephone list b4 removing inserts"+telephoneList.size());
List telephoneSaveList = new ArrayList();
ESMTransaction transaction = null;
String telType = null;
int sizeOfListToIterate = telephoneList.size();
for(int count=0;count<sizeOfListToIterate;count++){
telType = ((TelephoneVO)telephoneList.get(count)).getTelephoneType();
System.out.println("The Type is"+telType);
System.out.println("The Type equals 0"+(!(telType.equals("0"))));
if(((TelephoneVO)telephoneList.get(count)).getTelephoneId() == null){
//System.out.println("Null Telephone id so insert"+((TelephoneVO)telephoneList.get(count)).getTelephoneNumber());
System.out.println("((TelephoneVO)telephoneList.get(count)).toString())" + ((TelephoneVO)telephoneList.get(count)).toString());
if(!(telType.equals("0"))){
System.out.println("Null Telephone id so insert"+((TelephoneVO)telephoneList.get(count)).getTelephoneNumber());
telephoneSaveList.add((TelephoneVO)telephoneList.get(count));
}
telephoneList.remove(count);
sizeOfListToIterate = sizeOfListToIterate-1;
count = count-1;
}
else{
System.out.println("ID Not ZNULL so dont remove"+((TelephoneVO)telephoneList.get(count)).getTelephoneId());
System.out.println("((TelephoneVO)telephoneList.get(count)).toString())" + ((TelephoneVO)telephoneList.get(count)).toString());
}
}// end for
System.out.println("Size of Telephone List after Removing inserts"+telephoneSaveList.size());
transaction = session.beginTransaction();
for(int insertTel=0;insertTel<telephoneSaveList.size();insertTel++){
session.save((TelephoneVO)telephoneSaveList.get(insertTel));
}
session.update(contactVO);
session.flush();
transaction.commit();
session.refresh(contactVO);
System.out.println("Transaction commited in saveContacts DAO");
}
catch(HibernateException he){
System.out.println("Hibernate Exception in saveContacts"+he);
ESMDataException dataExcep = new ESMDataException(he.getMessage());
dataExcep.setRootCause(he);
//session.close();
throw dataExcep;
}
catch(Exception e){
System.out.println("generic Exception in saveContacts"+e);
e.printStackTrace();
ESMDataException dataExcep = new ESMDataException(e.getMessage());
dataExcep.setRootCause(e);
//session.close();
throw dataExcep;
}
finally{
//session.close();
}
return contactVO;
}
public AddressVO saveAddress(AddressVO addressVO) throws ESMDataException{
try{
session.evict(addressVO);
ESMTransaction transaction = null;
transaction = session.beginTransaction();
session.update(addressVO);
session.flush();
transaction.commit();
session.refresh(addressVO);
System.out.println("Transaction commited in saveContacts DAO");
}
catch(HibernateException he){
System.out.println("Hibernate Exception in saveAddress"+he);
ESMDataException dataExcep = new ESMDataException(he.getMessage());
dataExcep.setRootCause(he);
//session.close();
throw dataExcep;
}
catch(Exception e){
System.out.println("generic Exception in saveAddress"+e);
e.printStackTrace();
ESMDataException dataExcep = new ESMDataException(e.getMessage());
dataExcep.setRootCause(e);
//session.close();
throw dataExcep;
}
finally{
//session.close();
}
return addressVO;
}
public CompanyVO saveCompany(CompanyVO compVO) throws ESMDataException{
try{
session.evict((ContactsVO)((List)(compVO.getContacts())).get(0));
session.evict(compVO);
System.out.println("Evicted Company VO");
ESMTransaction transaction = null;
transaction = session.beginTransaction();
session.update(compVO);
session.flush();
transaction.commit();
System.out.println("Transaction commited in saveCompany DAO");
session.refresh(compVO);
}
catch(HibernateException he){
System.out.println("Hibernate Exception in saveCompany"+he);
ESMDataException dataExcep = new ESMDataException(he.getMessage());
dataExcep.setRootCause(he);
//session.close();
throw dataExcep;
}
catch(Exception e){
System.out.println("generic Exception in saveCompany"+e);
e.printStackTrace();
ESMDataException dataExcep = new ESMDataException(e.getMessage());
dataExcep.setRootCause(e);
//session.close();
throw dataExcep;
}
finally{
//session.close();
}
return compVO;
}
public CompanyVO createCompany(CompanyVO compVO) throws ESMDataException{
try{
//session.evict((ContactsVO)((List)(compVO.getContacts())).get(0));
session.evict(compVO);
System.out.println("Evicted Company VO while creating");
ESMTransaction transaction = null;
transaction = session.beginTransaction();
session.save(compVO);
session.flush();
transaction.commit();
System.out.println("Transaction commited in saveCompany DAO");
session.refresh(compVO);
}
catch(HibernateException he){
System.out.println("Hibernate Exception in saveCompany"+he);
ESMDataException dataExcep = new ESMDataException(he.getMessage());
dataExcep.setRootCause(he);
//session.close();
throw dataExcep;
}
catch(Exception e){
System.out.println("generic Exception in saveCompany"+e);
e.printStackTrace();
ESMDataException dataExcep = new ESMDataException(e.getMessage());
dataExcep.setRootCause(e);
//session.close();
throw dataExcep;
}
finally{
//session.close();
}
return compVO;
}
}