Steffi wrote:
In Java it looks like this:
Struts Action class:
// I get the country oid from the select box from the view
Country country = businessDelegate.getCountryByOid(new Long(Long.parseLong(countryOid)));
address.setCountry(country);
businessDelegate.saveAddress(address);
DAO classes:
public Country getCountryByOid(Long countryOid){
Session session = HibernateUtil.currentSession();
Transaction tx= session.beginTransaction();
country = (Country) session.get(Country.class, countryOid);
tx.commit();
HibernateUtil.closeSession();
...
}
public void saveAddress(Address address){
Session session = HibernateUtil.currentSession();
Transaction tx= session.beginTransaction();
session.save(address);
tx.commit();
HibernateUtil.closeSession();
...
}
Address.java:
private Country country = new Country();
// with setter and getter
Mapping of address:
<many-to-one
name="country"
class="de.woco.moslokal.businessobject.Country"
column="country_id"
unique="true"
cascade="none"
lazy="true"/>
1. In adress java, do not create new Country as;
private Country country = new Country();
let it be private Country country;
2. In DAO part , you dont need a transaction for getting objects
Try now.