Hibernate version: 2.0
Mapping documents:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>
<class
name="com.db.caaa.domain.Company"
table="COMPANY"
dynamic-update="false"
dynamic-insert="false"
>
<cache usage="nonstrict-read-write" />
<id
name="id"
column="id"
type="long"
unsaved-value="-1"
>
<generator class="native">
</generator>
</id>
<version
name="version"
type="long"
column="version"
access="property"
unsaved-value="negative"
/>
<property
name="building"
type="java.lang.String"
update="true"
insert="true"
access="property"
column="building"
/>
<property
name="area"
type="java.lang.String"
update="true"
insert="true"
access="property"
column="area"
/>
<property
name="street"
type="java.lang.String"
update="true"
insert="true"
access="property"
column="street"
/>
<property
name="companyName"
type="java.lang.String"
update="true"
insert="true"
access="property"
>
<column
name="companyName"
length="35"
unique-key="CONAMESNAME"
not-null="true"
/>
</property>
<property
name="companyShortName"
type="java.lang.String"
update="true"
insert="true"
access="property"
>
<column
name="companyShortName"
length="20"
unique-key="CONAMESNAME"
not-null="true"
/>
</property>
<many-to-one
name="country"
class="com.db.caaa.domain.lookup.Country"
cascade="none"
outer-join="auto"
update="true"
insert="true"
access="property"
column="country_fk"
/>
<set
name="customers"
table="customer_company"
lazy="true"
inverse="false"
cascade="none"
sort="unsorted"
>
<cache
usage="nonstrict-read-write"
/>
<key
column="company_fk"
>
</key>
<many-to-many
class="com.db.caaa.domain.Customer"
column="customer_fk"
outer-join="auto"
/>
</set>
<set
name="accounts"
lazy="true"
inverse="true"
cascade="all-delete-orphan"
sort="unsorted"
>
<cache
usage="nonstrict-read-write"
/>
<key
column="company_fk"
>
</key>
<one-to-many
class="com.db.caaa.domain.Account"
/>
</set>
<set
name="contactPersons"
lazy="false"
inverse="false"
cascade="all-delete-orphan"
sort="unsorted"
>
<cache
usage="nonstrict-read-write"
/>
<key
column="company_fk"
>
</key>
<one-to-many
class="com.db.caaa.domain.ContactPerson"
/>
</set>
<property
name="state"
type="java.lang.String"
update="true"
insert="true"
access="property"
column="state"
/>
<property
name="zipCode"
type="java.lang.String"
update="true"
insert="true"
access="property"
column="zipCode"
length="15"
/>
<property
name="city"
type="java.lang.String"
update="true"
insert="true"
access="property"
column="city"
/>
<set
name="companyProducts"
lazy="true"
inverse="false"
cascade="all-delete-orphan"
sort="unsorted"
>
<cache
usage="nonstrict-read-write"
/>
<key
column="company_fk"
>
</key>
<one-to-many
class="com.db.caaa.domain.CompanyProduct"
/>
</set>
<many-to-one
name="branch"
class="com.db.caaa.domain.Branch"
cascade="none"
outer-join="auto"
update="true"
insert="true"
access="property"
>
<column
name="branch_fk"
/>
</many-to-one>
<set
name="companyAccounts"
lazy="false"
inverse="true"
cascade="none"
sort="unsorted"
>
<cache
usage="nonstrict-read-write"
/>
<key
column="MasterNumber_FK"
>
</key>
<one-to-many
class="com.db.caaa.domain.Account"
/>
</set>
<property
name="masterNumber"
type="java.lang.String"
update="true"
insert="true"
access="property"
>
<column
name="MasterNumber"
not-null="false"
/>
</property>
<set
name="masterNumberCompanies"
table="Company_MasterNumber"
lazy="true"
inverse="false"
cascade="none"
sort="unsorted"
>
<cache
usage="nonstrict-read-write"
/>
<key
column="company_fk"
>
</key>
<many-to-many
class="com.db.caaa.domain.Company"
column="MasterNumber_fk"
outer-join="auto"
/>
</set>
<set
name="regularCompanies"
table="Company_MasterNumber"
lazy="true"
inverse="true"
cascade="none"
sort="unsorted"
>
<cache
usage="nonstrict-read-write"
/>
<key
column="MasterNumber_fk"
>
</key>
<many-to-many
class="com.db.caaa.domain.Company"
column="company_fk"
outer-join="auto"
/>
</set>
<set
name="dbdcCDeliveryAddress"
table="DBDCDELIVERYADDRESS"
lazy="false"
inverse="false"
cascade="all-delete-orphan"
sort="unsorted"
>
<cache
usage="nonstrict-read-write"
/>
<key
column="company_fk"
>
</key>
<one-to-many
class="com.db.caaa.domain.DBDCDeliveryAddress"
/>
</set>
<property
name="status"
type="com.db.caaa.approval.domain.StatusEnumType"
update="true"
insert="true"
access="property"
column="status"
/>
<many-to-one
name="lastModifier"
class="com.db.caaa.domain.UserLastModifier"
cascade="none"
outer-join="auto"
update="true"
insert="true"
access="property"
column="modifier_fk"
/>
<property
name="lastAction"
type="com.db.caaa.approval.domain.ActionTypeEnumType"
update="true"
insert="true"
access="property"
column="lastAction"
/>
<property
name="lastModificationDate"
type="java.util.Date"
update="true"
insert="true"
access="property"
column="lastModificationDate"
/>
<property
name="lastComment"
type="java.lang.String"
update="true"
insert="true"
access="property"
column="lastComment"
/>
<set
name="pendingChanges"
lazy="false"
inverse="false"
cascade="all-delete-orphan"
sort="unsorted"
>
<cache
usage="nonstrict-read-write"
/>
<key
column="parent_fk"
>
</key>
<one-to-many
class="com.db.caaa.approval.domain.PendingChange"
/>
</set>
<set
name="externalPendingChanges"
lazy="true"
inverse="true"
cascade="all-delete-orphan"
sort="unsorted"
>
<key
column="propertyValue_fk"
>
</key>
<one-to-many
class="com.db.caaa.approval.domain.PendingChangeBO"
/>
</set>
<property
name="extid"
type="java.lang.String"
update="true"
insert="true"
access="property"
column="extid"
not-null="false"
/>
<property
name="businessKey"
type="java.lang.String"
update="true"
insert="true"
access="property"
column="businessKey"
/>
<map
name="mapExtensions"
table="Company_XTS"
lazy="false"
inverse="false"
cascade="none"
sort="unsorted">
<cache usage="nonstrict-read-write" />
<key>
<column name="PARENT_FK" unique-key="UNIQUEXTS"/>
</key>
<index type="string" column="PROPERTYNAME"/>
<!--
<composite-element class="com.db.caaa.domain.GenericProperty">
<property name="propertyValue" column="PROPERTYVALUE" not-null="false"/>
</composite-element>
-->
<element type="com.db.caaa.domain.GenericProperty">
<column name="PROPERTYVALUE" not-null="false" unique-key="UNIQUEXTS"/>
</element>
</map>
<!--
To add non XDoclet property mappings, create a file named
hibernate-properties-Company.xml
containing the additional properties and place it in your merge dir.
-->
</class>
</hibernate-mapping>
Mapping documents:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>
<class
name="com.db.caaa.domain.DBDCDeliveryAddress"
table="DBDCDELIVERYADDRESS"
dynamic-update="false"
dynamic-insert="false"
>
<cache usage="nonstrict-read-write" />
<id
name="id"
column="id"
type="long"
unsaved-value="-1"
>
<generator class="native">
</generator>
</id>
<version
name="version"
type="long"
column="version"
access="property"
unsaved-value="negative"
/>
<property
name="interchangeFileFormat"
type="java.lang.String"
update="true"
insert="true"
access="property"
>
<column
name="FileFormat"
not-null="false"
/>
</property>
<property
name="receiverID"
type="java.lang.String"
update="true"
insert="true"
access="property"
>
<column
name="ReceiverId"
not-null="false"
unique="false"
/>
</property>
<property
name="senderID"
type="java.lang.String"
update="true"
insert="true"
access="property"
>
<column
name="SenderId"
not-null="false"
unique="false"
/>
</property>
<many-to-one
name="company"
class="com.db.caaa.domain.Company"
cascade="save-update"
outer-join="auto"
update="true"
insert="true"
access="property"
column="company_fk"
/>
<property
name="status"
type="com.db.caaa.approval.domain.StatusEnumType"
update="true"
insert="true"
access="property"
column="status"
/>
<many-to-one
name="lastModifier"
class="com.db.caaa.domain.UserLastModifier"
cascade="none"
outer-join="auto"
update="true"
insert="true"
access="property"
column="modifier_fk"
/>
<property
name="lastAction"
type="com.db.caaa.approval.domain.ActionTypeEnumType"
update="true"
insert="true"
access="property"
column="lastAction"
/>
<property
name="lastModificationDate"
type="java.util.Date"
update="true"
insert="true"
access="property"
column="lastModificationDate"
/>
<property
name="lastComment"
type="java.lang.String"
update="true"
insert="true"
access="property"
column="lastComment"
/>
<set
name="pendingChanges"
lazy="false"
inverse="false"
cascade="all-delete-orphan"
sort="unsorted"
>
<cache
usage="nonstrict-read-write"
/>
<key
column="parent_fk"
>
</key>
<one-to-many
class="com.db.caaa.approval.domain.PendingChange"
/>
</set>
<set
name="externalPendingChanges"
lazy="true"
inverse="true"
cascade="all-delete-orphan"
sort="unsorted"
>
<key
column="propertyValue_fk"
>
</key>
<one-to-many
class="com.db.caaa.approval.domain.PendingChangeBO"
/>
</set>
<property
name="extid"
type="java.lang.String"
update="true"
insert="true"
access="property"
column="extid"
not-null="false"
/>
<property
name="businessKey"
type="java.lang.String"
update="true"
insert="true"
access="property"
column="businessKey"
/>
<!--
To add non XDoclet property mappings, create a file named
hibernate-properties-DBDCDeliveryAddress.xml
containing the additional properties and place it in your merge dir.
-->
</class>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close():
Full stack trace of any exception that occurs:
2008-03-08 15:40:32,125 ERROR net.sf.hibernate.impl.SessionImpl - Could not synchronize database state with session
net.sf.hibernate.TransientObjectException: object references an unsaved transient instance - save the transient instance
before flushing: com.db.caaa.domain.DBDCDeliveryAddress
at net.sf.hibernate.impl.SessionImpl.throwTransientObjectException(SessionImpl.java:2768)
at net.sf.hibernate.impl.SessionImpl.getEntityIdentifierIfNotUnsaved(SessionImpl.java:2760)
at net.sf.hibernate.type.ObjectType.disassemble(ObjectType.java:206)
at net.sf.hibernate.impl.CacheEntry.disassemble(CacheEntry.java:38)
at net.sf.hibernate.impl.CacheEntry.<init>(CacheEntry.java:29)
at net.sf.hibernate.impl.ScheduledInsertion.execute(ScheduledInsertion.java:33)
at net.sf.hibernate.impl.SessionImpl.executeAll(SessionImpl.java:2418)
at net.sf.hibernate.impl.SessionImpl.execute(SessionImpl.java:2371)
Name and version of the database you are using:2.0
The generated SQL (show_sql=true):
Debug level Hibernate log excerpt:
Problems with Session and transaction handling?
Read this:
http://hibernate.org/42.html
Code:
[color=red][/color]
Company.java
public class Company extends ApprovableExtendedBusinessObject implements ReplicableWithDependants, Lifecycle
{
private String companyName;
private String companyShortName;
private String building;
private String area;
private String street;
private String zipCode;
private String city;
private String state;
private Set customers = new HashSet();
private Set contactPersons = new HashSet();
private Set accounts = new HashSet();
private Set companyAccounts = new HashSet();
private Country country;
private Set companyProducts = new HashSet();
private Set users = new HashSet();
private Branch branch;
// i-flex solutions 27-Jun-06: Modifications for CAAA 3.0 Iteraion-1 Design Section : 2.3.1 Begin
private String masterNumber = "N";
private Set masterNumberCompanies = new HashSet();
private Set regularCompanies;
// i-flex solutions 27-Jun-06: Modifications for CAAA 3.0 Iteraion-1 Design Section : 2.3.1 End
private transient static org.apache.commons.logging.Log LOG = LogFactory.getLog(Company.class);
// Fx4cash Phase2 dbdc delivery address
private Set dbdcCDeliveryAddress = new HashSet();
/**
* Constructor for Company
*/
public Company()
{
super();
}
/**
* Constructor for Company
* @param companyShortName String
*/
public Company(String companyShortName)
{
this.companyShortName = companyShortName;
}
/* (non-Javadoc)
* @see com.db.caaa.domain.BaseBusinessObject#getDisplayValue()
*/
public String getDisplayValue()
{
return this.getCompanyName();
}
/**
* @hibernate.property
*
* @return Returns the building.
*/
public String getBuilding()
{
return building;
}
/**
* @param address1 The building to set.
*/
public void setBuilding(String address1)
{
this.building = address1;
}
/**
* @hibernate.property
*
* @return Returns the area.
*/
public String getArea()
{
return area;
}
/**
* @param address2 The area to set.
*/
public void setArea(String address2)
{
this.area = address2;
}
/**
* @hibernate.property
*
* @return Returns the street.
*/
public String getStreet()
{
return street;
}
/**
* @param address3 The street to set.
*/
public void setStreet(String address3)
{
this.street = address3;
}
/**
* @hibernate.property
*
* @hibernate.column
* name="companyName"
* unique-key="CONAMESNAME"
* length="35"
* not-null="true"
*
* @return Returns the companyName.
*/
public String getCompanyName()
{
return companyName;
}
/**
* @param companyName The companyName to set.
*/
public void setCompanyName(String companyName)
{
this.companyName = companyName;
}
/**
* @hibernate.property
*
* @hibernate.column
* name="companyShortName"
* unique-key="CONAMESNAME"
* length="20"
* not-null="true"
*
* @return Returns the companyShortName.
*/
public String getCompanyShortName()
{
return companyShortName;
}
/**
* @param companyShortName The companyShortName to set.
*/
public void setCompanyShortName(String companyShortName)
{
this.companyShortName = companyShortName;
}
/**
* @hibernate.many-to-one
* column="country_fk"
* cascade="none"
*
* @return Returns the countryReference.
*/
public Country getCountry()
{
return country;
}
/**
* @param country The countryReference to set.
*/
public void setCountry(Country country)
{
this.country = country;
}
/**
* @hibernate.set
* lazy="true"
* inverse="false"
* cascade="none"
* table="customer_company"
* @hibernate.collection-key
* column="company_fk"
* @hibernate.collection-many-to-many
* column="customer_fk"
* class="com.db.caaa.domain.Customer"
* @hibernate.collection-cache usage="nonstrict-read-write"
*
* @return Returns the customers.
*/
public Set getCustomers()
{
return customers;
}
/**
* @param customers The customers to set.
*/
private void setCustomers(Set customers)
{
this.customers = customers;
}
/**
* Method add
* @param customer Customer
*/
public void add(Customer customer)
{
//TODO: check whether the following if-statement can be removed in favour for
// an improved PendingChange behaviour
if (ThreadLocalSession.areObjectsInSession(new Object[]{this, customer}))
customer.getCompanies().add(this);
this.customers.add(customer);
}
/**
* Method remove
* @param customer Customer
*/
public void remove(Customer customer)
{
this.customers.remove(customer);
//TODO: check whether the following if-statement can be removed in favour for
// an improved PendingChange behaviour
if (ThreadLocalSession.areObjectsInSession(new Object[]{this, customer}))
customer.getCompanies().remove(this);
}
/**
* @hibernate.set
* lazy="true"
* inverse="true"
* cascade="all-delete-orphan"
* @hibernate.collection-key
* column="company_fk"
* @hibernate.collection-one-to-many
* class="com.db.caaa.domain.Account"
* @hibernate.collection-cache usage="nonstrict-read-write"
*
* @return Returns the accounts.
*/
public Set getAccounts()
{
return accounts;
}
/**
* @param accounts The accounts to set.
*/
private void setAccounts(Set accounts)
{
this.accounts = accounts;
}
/**
* Method add
* @param account Account
*/
public void add(Account account)
{
account.setCompany(this);
this.accounts.add(account);
}
/**
* Method remove
* @param account Account
*/
public void remove(Account account)
{
this.accounts.remove(account);
account.setCompany(null);
}
/**
* @hibernate.set
* inverse="false"
* cascade="all-delete-orphan"
* @hibernate.collection-key
* column="company_fk"
* @hibernate.collection-one-to-many
* class="com.db.caaa.domain.ContactPerson"
* @hibernate.collection-cache usage="nonstrict-read-write"
*
* @return Returns the contactPersons.
*/
public Set getContactPersons()
{
return contactPersons;
}
/**
* @param contactPersons The contactPersons to set.
*/
private void setContactPersons(Set contactPersons)
{
this.contactPersons = contactPersons;
}
/**
* Method add
* @param contactPerson ContactPerson
*/
public void add(ContactPerson contactPerson)
{
this.contactPersons.add(contactPerson);
}
/**
* Method remove
* @param contactPerson ContactPerson
*/
public void remove(ContactPerson contactPerson)
{
this.contactPersons.remove(contactPerson);
}
/**
* @hibernate.property
*
* @return Returns the state.
*/
public String getState()
{
return state;
}
/**
* @param state The state to set.
*/
public void setState(String state)
{
this.state = state;
}
/**
* @hibernate.property
* length="15"
*
* @return Returns the zipCode.
*/
public String getZipCode()
{
return zipCode;
}
/**
* @param zipCode The zipCode to set.
*/
public void setZipCode(String zipCode)
{
this.zipCode = zipCode;
}
/**
* @hibernate.property
*
* @return Returns the city.
*/
public String getCity()
{
return city;
}
/**
* @param city The city to set.
*/
public void setCity(String city)
{
this.city = city;
}
/**
* @see java.lang.Object#toString()
*/
public String toString()
{
return this.companyName;
}
/**
*
* @return the related customers
*/
public Collection retrieveRelatedCustomers()
{
return getCustomers();
}
/**
*
* @return the related companies
*/
public Collection retrieveRelatedCompanies()
{
HashSet theCompany = new HashSet();
theCompany.add(this);
return theCompany;
}
/**
* @hibernate.set
* inverse="false"
* lazy="true"
* cascade="all-delete-orphan"
* @hibernate.collection-key
* column="company_fk"
* @hibernate.collection-one-to-many
* class="com.db.caaa.domain.CompanyProduct"
* @hibernate.collection-cache usage="nonstrict-read-write"
*
* @return Returns the companyProduct.
*/
public Set getCompanyProducts()
{
return companyProducts;
}
/**
* @param companyProducts The companyProducts to set.
*/
public void setCompanyProducts(Set companyProducts)
{
this.companyProducts = companyProducts;
}
/**
* @param companyProduct
*/
public void add(CompanyProduct companyProduct)
{
companyProduct.set(this);
this.companyProducts.add(companyProduct);
}
/**
* @param companyProduct
*/
public void remove(CompanyProduct companyProduct)
{
this.companyProducts.remove(companyProduct);
//companyProduct.setProduct(null);
}
/**
* hibernate.set
* inverse="false"
* cascade="none"
* hibernate.collection-key
* column="company_fk"
* hibernate.collection-one-to-many
* class="com.db.caaa.domain.User"
* hibernate.collection-cache usage="nonstrict-read-write"
*
* @return Returns the companyProduct.
*/
public Set getUsers()
{
return users;
}
/**
* @param users The companyProducts to set.
*/
public void setUsers(Set users)
{
this.users = users;
}
/**
* @param user
*/
public void add(User user)
{
user.set(this);
this.users.add(user);
}
/**
* @param user
*/
public void remove(User user)
{
this.users.remove(user);
user.setCompany(null);
}
/**
* @hibernate.many-to-one
* column="branch_fk"
* cascade="none"
* @hibernate.column
*
* name="branch_fk"
* @return Returns the branch.
*/
public Branch getBranch()
{
return branch;
}
/**
* @param branch The branch to set.
*/
public void setBranch(Branch branch)
{
this.branch = branch;
}
/**
* @hibernate.set
* lazy="false"
* inverse="true"
* cascade="none"
* @hibernate.collection-key
* column="MasterNumber_FK"
* not-null="false"
* @hibernate.collection-one-to-many
* class="com.db.caaa.domain.Account"
* @hibernate.collection-cache usage="nonstrict-read-write"
* @return Returns the accounts related to master company.
*/
public Set getCompanyAccounts()
{
return companyAccounts;
}
/**
* @param companyAccounts
* Sets the accounts related to master company.
*/
public void setCompanyAccounts(Set companyAccounts)
{
this.companyAccounts = companyAccounts;
}
/**
* @param _productName
* @return
*/
public CompanyProduct findCompanyProductsByProductName(final String _productName)
{
return (CompanyProduct)CollectionUtils.find(this.companyProducts, new Predicate(){
public boolean evaluate(Object arg0)
{
CompanyProduct ap = (CompanyProduct)arg0;
return _productName.equals(ap.getProduct().getProductName());
}
}
);
}
/* (non-Javadoc)
* @see net.sf.hibernate.Lifecycle#onDelete(net.sf.hibernate.Session)
*/
public boolean onDelete(Session session) throws CallbackException
{
for (Iterator iter = companyAccounts.iterator(); iter.hasNext();)
{
Account acc = (Account)iter.next();
try
{
acc = (Account) session.load(Account.class, acc.getSerializableId());
acc.setMasterCompany(null);
} catch (net.sf.hibernate.ObjectDeletedException ode)
{
//nothing to do
} catch (HibernateException e)
{
throw new CallbackException(e);
}
}
for (Iterator iter = customers.iterator(); iter.hasNext();)
{
Customer customer = (Customer) iter.next();
try
{
customer = (Customer) session.load(Customer.class, customer.getSerializableId());
customer.getCompanies().remove(this);
} catch (net.sf.hibernate.ObjectDeletedException ode)
{
//nothing to do
} catch (HibernateException e)
{
throw new CallbackException(e);
}
}
if (LOG.isDebugEnabled())
LOG.debug("Setting user.company to 'null'.");
Criteria crit = session.createCriteria(User.class);
crit.add(Expression.eq("company", this));
try
{
List result = crit.list();
for(Iterator iter = result.iterator(); iter.hasNext();)
{
User user = (User)iter.next();
if (LOG.isDebugEnabled())
LOG.debug("Setting user.company to 'null' for user: "+user);
user.setCompany(null);
}
} catch (HibernateException e)
{
throw new CallbackException(e);
}
// Fix for TD Start
try
{
Criteria criteria = session.createCriteria(PendingChangeSetBO.class);
criteria.add(Expression.eq("propertyValue",this));
List pendingChanges = criteria.list();
for(Iterator itrRoles = pendingChanges.iterator();itrRoles.hasNext();) {
PendingChangeSetBO pendingChange = (PendingChangeSetBO) itrRoles.next();
BusinessObject bo = pendingChange.getParent();
if (bo != null)
bo.removePendingChange(pendingChange);
session.delete(pendingChange);
}
}
catch (net.sf.hibernate.ObjectDeletedException ode) {
}
catch (HibernateException e) {
throw new CallbackException(e);
}
// Fix for TD End
// try
// {
// Hibernate.initialize(this.getUsers());
// } catch (HibernateException e2)
// {
// throw new CallbackException(e2);
// }
// for (Iterator iter = users.iterator(); iter.hasNext();)
// {
// User user = (User) iter.next();
// try
// {
// user = (User) session.load(User.class, user.getSerializableId());
// user.setCompany(null);
// } catch (net.sf.hibernate.ObjectDeletedException ode)
// {
// //nothing to do
// } catch (HibernateException e)
// {
// throw new CallbackException(e);
// }
// }
// delete joint category
try {
session.setFlushMode(FlushMode.COMMIT);
String query = "from ActiveJointCategory as ajc where ajc.company.id = :id";
LOG.debug("----- deleting Active Joint Category Company ID="+this.getId()+" -------");
session.delete(query, new Object[]{new Long(this.getId())},
new Type[]{Hibernate.LONG});
String query2 = "from JointCategory as jc where jc.company.id = :id";
LOG.debug("----- deleting Joint Category Company ID="+this.getId()+" -------");
session.delete(query2, new Object[]{new Long(this.getId())},
new Type[]{Hibernate.LONG});
}
catch (HibernateException e1)
{
throw new CallbackException(e1);
}
/* User Entitlement Deletion Cascade */
try {
session.setFlushMode(FlushMode.COMMIT);
String query = "from UserEntitlementPermission as uep where uep.companyReference.id = :id";
LOG.debug("----- deleting User Entitlement Permission Company ID="+this.getId()+" -------");
session.delete(query, new Object[]{new Long(this.getId())},
new Type[]{Hibernate.LONG});
String query2 = "from UserSelfAdminPermission as usap where usap.companyReference.id = :id";
LOG.debug("----- deleting User Self Admin Permission Company ID="+this.getId()+" -------");
session.delete(query2, new Object[]{new Long(this.getId())},
new Type[]{Hibernate.LONG});
}
catch (HibernateException e1)
{
throw new CallbackException(e1);
}
try
{
session.setFlushMode(FlushMode.COMMIT);
String query = "from UserPermission as up where up.companyReference.id = :id";
LOG.debug("----- deleting User Permission Company ID="+this.getId()+" -------");
session.delete(query, new Object[]{new Long(this.getId())},
new Type[]{Hibernate.LONG});
String query2 = "from ActivePermission as ap where ap.companyReference.id = :id";
LOG.debug("----- deleting Active User Permission Company ID="+this.getId()+" -------");
session.delete(query2, new Object[]{new Long(this.getId())},
new Type[]{Hibernate.LONG});
} catch (HibernateException e1)
{
throw new CallbackException(e1);
}
try
{
session.setFlushMode(FlushMode.COMMIT);
String query = "from VerificationSetupPermission as vp where vp.companyReference.id = :id";
LOG.debug("----- deleting Verification Setup Permission Company ID="+this.getId()+" -------");
session.delete(query, new Object[]{new Long(this.getId())},
new Type[]{Hibernate.LONG});
} catch (HibernateException e1)
{
throw new CallbackException(e1);
}
/*
* Remove the links to master-regular on deletion.
*/
Set linkedCompanies = masterNumber.equals("Y")? this.regularCompanies:this.masterNumberCompanies;
if (linkedCompanies !=null)
{
// try
// {
for ( Iterator iter = linkedCompanies.iterator();iter.hasNext();)
{
Company linkedCompany = (Company)iter.next();
//linkedCompany = (Company)session.load(Company.class,linkedCompany.getSerializableId());
if ( masterNumber.equals("N"))
linkedCompany.getRegularCompanies().remove(this);
else
linkedCompany.getMasterNumberCompanies().remove(this);
}
// }catch(ObjectDeletedException e){}
// catch(HibernateException e)
// {
// throw new CallbackException(e);
// }
}
return super.onDelete(session);
}
/* (non-Javadoc)
* @see net.sf.hibernate.Lifecycle#onSave(net.sf.hibernate.Session)
*/
public boolean onSave(Session session) throws CallbackException
{
for (Iterator iter = customers.iterator(); iter.hasNext();)
{
Customer customer = (Customer) iter.next();
try
{
customer = (Customer) session.load(Customer.class, customer.getSerializableId());
customer.getCompanies().add(this);
} catch (net.sf.hibernate.ObjectDeletedException ode)
{
//nothing to do
} catch (HibernateException e)
{
throw new CallbackException(e);
}
}
for (Iterator iter = dbdcCDeliveryAddress.iterator(); iter.hasNext();)
{
DBDCDeliveryAddress dbdcDeliveryAddress = (DBDCDeliveryAddress) iter.next();
try
{
if(dbdcDeliveryAddress != null){
dbdcDeliveryAddress = (DBDCDeliveryAddress) session.load(DBDCDeliveryAddress.class, dbdcDeliveryAddress.getSerializableId());
dbdcDeliveryAddress.add(this);
// session.saveOrUpdate(dbdcDeliveryAddress);
session.flush();
session.evict(dbdcDeliveryAddress);
}
} catch (net.sf.hibernate.ObjectDeletedException ode)
{
//nothing to do
} catch (HibernateException e)
{
throw new CallbackException(e);
}
}
// for (Iterator iter = users.iterator(); iter.hasNext();)
// {
// User user = (User) iter.next();
// try
// {
// user = (User) session.load(User.class, user.getSerializableId());
// user.setCompany(this);
// } catch (net.sf.hibernate.ObjectDeletedException ode)
// {
// //nothing to do
// } catch (HibernateException e)
// {
// throw new CallbackException(e);
// }
// }
return super.onSave(session);
}
// i-flex solutions 27-Jun-06: Modifications for CAAA 3.0 Iteraion-1 Design Section : 2.3.1 Begin
/**
* @hibernate.property
* @hibernate.column
* name="MasterNumber"
* not-null="false"
* @return Returns the MasterNumber.
*/
public String getMasterNumber() {
return masterNumber;
}
public void setMasterNumber(String masterNumber) {
this.masterNumber = masterNumber;
}
/**
* @hibernate.set
* inverse="false"
* lazy="true"
* cascade="none"
* table="Company_MasterNumber"
* @hibernate.collection-key
* column="company_fk"
* @hibernate.collection-many-to-many
* column="MasterNumber_fk"
* class="com.db.caaa.domain.Company"
* @hibernate.collection-cache usage="nonstrict-read-write"
*
* @return Returns the accountProducts.
*/
public Set getMasterNumberCompanies() {
return masterNumberCompanies;
}
public void setMasterNumberCompanies(Set masterNumberCompanies) {
this.masterNumberCompanies = masterNumberCompanies;
}
/**
* @hibernate.set
* inverse="true"
* lazy="true"
* cascade="none"
* table="Company_MasterNumber"
* @hibernate.collection-key
* column="MasterNumber_fk"
* @hibernate.collection-many-to-many
* column="company_fk"
* class="com.db.caaa.domain.Company"
* @hibernate.collection-cache usage="nonstrict-read-write"
*
* @return Returns the accountProducts.
*/
public Set getRegularCompanies() {
return regularCompanies;
}
public void setRegularCompanies(Set regularCompanies) {
this.regularCompanies = regularCompanies;
}
/** Sharaf
* Adds a link to master number/legal company
*/
public void remove(Company company) throws EnvironmentException
{
this.fetchLinkedCompanies().remove(company);
company.fetchLinkedCompanies().remove(this);
}
/** Sharaf
* Adds a link to master number/legal company
*/
public void add(Company company) throws EnvironmentException
{
this.fetchLinkedCompanies().add(company);
company.fetchLinkedCompanies().add(this);
}
/**
* Dynamically retrieves the set of linked companies.
* If the object is a master company, then it returns the set of linked regular companies
* and vice-versa
*/
public Set fetchLinkedCompanies()
{
Set companies;
if ( this.getMasterNumber().equals("Y"))
companies = getRegularCompanies();
else
companies = getMasterNumberCompanies();
if ( companies == null )
{
companies = new HashSet();
if (getMasterNumber().equals("Y"))
this.regularCompanies = companies;
else
this.masterNumberCompanies = companies;
}
return companies;
}
/**
* Dynamically retrieves the set of linked companies.
* If the object is a master company, then it returns the set of linked regular companies
* and vice-versa
*/
public Set fetchLinkedCompanies(String mn)
{
Set companies;
if ( mn.equals("Y"))
companies = getRegularCompanies();
else
companies = getMasterNumberCompanies();
if ( companies == null ) companies = new HashSet();
return companies;
}
/**
* Method
* @return List
* @see com.db.caaa.approval.domain.Approvable#getDeepPendingChanges()
*/
public List getDeepPendingChanges()
{
List retVal = super.getDeepPendingChanges();
for(Iterator iter = this.companyProducts.iterator(); iter.hasNext();) {
CompanyProduct companyProduct = (CompanyProduct)iter.next();
retVal.addAll(companyProduct.getDeepPendingChanges());
}
return retVal;
}
/* (non-Javadoc)
* @see com.db.caaa.domain.ReplicableWithDependants#getReplicableDependants()
*/
public HashMap loadReplicableDependants()
{
HashMap dependants = new HashMap();
Set masters = this.getMasterNumberCompanies();
for (Iterator iter = masters.iterator(); iter.hasNext();)
{
Company company = (Company) iter.next();
dependants.put(new Long(company.getId()), company.getClass());
}
return dependants;
}
// Fx4Cash Phase2 dbdcDeliveryAddress change start
/**
* @hibernate.set
* lazy="false"
* cascade="all-delete-orphan"
* table="DBDCDELIVERYADDRESS"
* @hibernate.collection-key
* column="company_fk"
* @hibernate.collection-one-to-many
* class="com.db.caaa.domain.DBDCDeliveryAddress"
* @hibernate.collection-cache usage="nonstrict-read-write"
* @return Returns the fx4cashdebitcurrencies
*/
public Set getDbdcCDeliveryAddress() {
return dbdcCDeliveryAddress;
}
/**
* @param dbdcDeliveryAddress The dbdcDeliveryAddress to set.
*/
public void setDbdcCDeliveryAddress(Set dbdcDeliveryAddress) {
this.dbdcCDeliveryAddress = dbdcDeliveryAddress;
}
/**
* Method add
* @param dbdcDeliveryAddress dbdcDeliveryAddress
*/
public void add(DBDCDeliveryAddress dbdcDeliveryAddress)
{
this.dbdcCDeliveryAddress.add(dbdcDeliveryAddress);
}
/**
* Method remove
* @param dbdcDeliveryAddress dbdcDeliveryAddress
*/
public void remove(DBDCDeliveryAddress dbdcDeliveryAddress)
{
this.dbdcCDeliveryAddress.remove(dbdcDeliveryAddress);
}
// Fx4Cash Phase2 dbdcDeliveryAddress change end
// public String getModifiedDisplayValue()
// {
// if ( masterNumber!=null && masterNumber.equals("Y"))
// return this.getCompanyName()+"(M)";
// else
// return this.getCompanyName();
// }
// i-flex solutions 27-Jun-06: Modifications for CAAA 3.0 Iteraion-1 Design Section : 2.3.1 End
}
/**
*
*/
package com.db.caaa.domain;
import net.sf.hibernate.CallbackException;
import net.sf.hibernate.HibernateException;
import net.sf.hibernate.Lifecycle;
import net.sf.hibernate.Session;
import java.util.Iterator;
import java.util.Set;
/**
* @hibernate.class table="DBDCDELIVERYADDRESS"
*
* @hibernate.cache usage="nonstrict-read-write"
*
* @author T Sreenivasulu
* @version
*/
public class DBDCDeliveryAddress extends ApprovableBusinessObject
implements Replicable, Lifecycle {
private String senderID;
private String receiverID;
private String interchangeFileFormat;
private Company company;
/**
* Constructor for DBDCDeliveryAddress
*/
public DBDCDeliveryAddress()
{
super();
}
/**
* Constructor for DBDCDeliveryAddress
* @param senderID String
*/
public DBDCDeliveryAddress(String senderID)
{
this.senderID = senderID;
}
/**
* @hibernate.property
*
* @hibernate.column
* name="FileFormat"
* not-null="false"
*
* @return Returns the interchangeFileFormat.
*/
public String getInterchangeFileFormat() {
return interchangeFileFormat;
}
/**
* @param interchangeFileFormat the interchangeFileFormat to set
*/
public void setInterchangeFileFormat(String interchangeFileFormat) {
this.interchangeFileFormat = interchangeFileFormat;
}
/**
* @hibernate.property
*
* @hibernate.column
* name="ReceiverId"
* not-null="false"
* unique="false"
*
* @return Returns the receiverID.
*/
public String getReceiverID() {
return receiverID;
}
/**
* @param receiverID the receiverID to set
*/
public void setReceiverID(String receiverID) {
this.receiverID = receiverID;
}
/**
* @hibernate.property
*
* @hibernate.column
* name="SenderId"
* not-null="false"
* unique="false"
*
* @return Returns the senderID.
*/
public String getSenderID() {
return senderID;
}
/**
* @param senderID the senderID to set
*/
public void setSenderID(String senderID) {
this.senderID = senderID;
}
/**
*
* @hibernate.many-to-one
* column="company_fk"
* cascade="save-update"
*
* @return Returns the Company reference.
*/
public Company getCompany() {
return company;
}
/**
* @param company the company to set
*/
public void setCompany(Company company) {
this.company = company;
}
public void add(Company company){
this.company = company;
company.add(this);
}
public void remove(Company company){
company.remove(this);
this.company = null;
}
/* (non-Javadoc)
* @see net.sf.hibernate.Lifecycle#onSave(net.sf.hibernate.Session)
*/
public boolean onSave(Session session) throws CallbackException
{
try
{
if(company != null){
company = (Company) session.load(Company.class, company.getSerializableId());
company.add(this);
session.flush();
}
} catch (net.sf.hibernate.ObjectDeletedException ode)
{
//nothing to do
} catch (HibernateException e)
{
throw new CallbackException(e);
}
return super.onSave(session);
}
public boolean onDelete(Session session) throws CallbackException
{
try
{
company = (Company) session.load(Company.class, company.getSerializableId());
company.remove(this);
session.flush();
} catch (net.sf.hibernate.ObjectDeletedException ode)
{
//nothing to do
} catch (HibernateException e)
{
throw new CallbackException(e);
}
return super.onDelete(session);
}
}
Code:
[color=green][/color]
package com.db.caaa.domain;
import net.sf.hibernate.CallbackException;
import net.sf.hibernate.HibernateException;
import net.sf.hibernate.Lifecycle;
import net.sf.hibernate.Session;
import java.util.Iterator;
import java.util.Set;
/**
* @hibernate.class table="DBDCDELIVERYADDRESS"
*
* @hibernate.cache usage="nonstrict-read-write"
*
* @author T Sreenivasulu
* @version
*/
public class DBDCDeliveryAddress extends ApprovableBusinessObject
implements Replicable, Lifecycle {
private String senderID;
private String receiverID;
private String interchangeFileFormat;
private Company company;
/**
* Constructor for DBDCDeliveryAddress
*/
public DBDCDeliveryAddress()
{
super();
}
/**
* Constructor for DBDCDeliveryAddress
* @param senderID String
*/
public DBDCDeliveryAddress(String senderID)
{
this.senderID = senderID;
}
/**
* @hibernate.property
*
* @hibernate.column
* name="FileFormat"
* not-null="false"
*
* @return Returns the interchangeFileFormat.
*/
public String getInterchangeFileFormat() {
return interchangeFileFormat;
}
/**
* @param interchangeFileFormat the interchangeFileFormat to set
*/
public void setInterchangeFileFormat(String interchangeFileFormat) {
this.interchangeFileFormat = interchangeFileFormat;
}
/**
* @hibernate.property
*
* @hibernate.column
* name="ReceiverId"
* not-null="false"
* unique="false"
*
* @return Returns the receiverID.
*/
public String getReceiverID() {
return receiverID;
}
/**
* @param receiverID the receiverID to set
*/
public void setReceiverID(String receiverID) {
this.receiverID = receiverID;
}
/**
* @hibernate.property
*
* @hibernate.column
* name="SenderId"
* not-null="false"
* unique="false"
*
* @return Returns the senderID.
*/
public String getSenderID() {
return senderID;
}
/**
* @param senderID the senderID to set
*/
public void setSenderID(String senderID) {
this.senderID = senderID;
}
/**
*
* @hibernate.many-to-one
* column="company_fk"
* cascade="save-update"
*
* @return Returns the Company reference.
*/
public Company getCompany() {
return company;
}
/**
* @param company the company to set
*/
public void setCompany(Company company) {
this.company = company;
}
public void add(Company company){
this.company = company;
company.add(this);
}
public void remove(Company company){
company.remove(this);
this.company = null;
}
/* (non-Javadoc)
* @see net.sf.hibernate.Lifecycle#onSave(net.sf.hibernate.Session)
*/
public boolean onSave(Session session) throws CallbackException
{
try
{
if(company != null){
company = (Company) session.load(Company.class, company.getSerializableId());
company.add(this);
session.flush();
}
} catch (net.sf.hibernate.ObjectDeletedException ode)
{
//nothing to do
} catch (HibernateException e)
{
throw new CallbackException(e);
}
return super.onSave(session);
}
public boolean onDelete(Session session) throws CallbackException
{
try
{
company = (Company) session.load(Company.class, company.getSerializableId());
company.remove(this);
session.flush();
} catch (net.sf.hibernate.ObjectDeletedException ode)
{
//nothing to do
} catch (HibernateException e)
{
throw new CallbackException(e);
}
return super.onDelete(session);
}
}