This is my java code.
Public class CustomerProfile {
public static Logger logger = Logger.getLogger(CustomerProfile.class);
public static void main(String[] args)
{
CustomerProfile custProfile = new CustomerProfile();
CustomerMaster cMaster = new CustomerMaster();
cMaster = custProfile.customerQueryExecution("N2C");
logger.debug("No: "+cMaster.getCmCustNo());
Iterator itr = cMaster.getPhoneAccsCollection().iterator();
while(itr.hasNext())
{
PhoneAccs pma = (PhoneAccs) itr.next();
PhoneAccs acc = new PhoneAccs();
PhoneList pl = new PhoneList();
pl.setPlPhNo(pma.getPmaPhNo().getPlPhNo());
acc.setPmaPhNo(pl);
acc.setPmaEqupCode(pma.getPmaEqupCode());
logger.debug("PNO: "+ acc.getPmaEqupCode() + " " + acc.getPmaPhNo().getPlPhNo());
}
}
public CustomerMaster customerQueryExecution(String custId)
{
Session session = null;
SessionFactory sessionFactory = null;
CustomerMaster customer = new CustomerMaster();
try {
sessionFactory = HibernateUtil.getEbppSessionFactory();
session = sessionFactory.openSession();
Transaction tr = session.beginTransaction();
String sqlQuery = "select cm from CustomerMaster cm,SubscriberMaster pm,PhoneAccs pma where cm.cmCustId='"+ custId +"' and pma.pmaStatus = 'A' ";
customer = (CustomerMaster) session.createQuery(sqlQuery).uniqueResult();
tr.commit();
}
catch (HibernateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
finally
{
session.close();
sessionFactory.close();
}
return customer;
}
}
CustomerMaster is my entity class.
when i try to retrieve the phonecollections (code is in main method) , i get the following error
Exception in thread "main" org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: com.ebpp.entity.CustomerMaster.phoneAccsCollection, no session or session was closed
at org.hibernate.collection.AbstractPersistentCollection.throwLazyInitializationException(AbstractPersistentCollection.java:358)
at org.hibernate.collection.AbstractPersistentCollection.throwLazyInitializationExceptionIfNotConnected(AbstractPersistentCollection.java:350)
at org.hibernate.collection.AbstractPersistentCollection.initialize(AbstractPersistentCollection.java:343)
at org.hibernate.collection.AbstractPersistentCollection.read(AbstractPersistentCollection.java:86)
at org.hibernate.collection.PersistentBag.iterator(PersistentBag.java:249)
at com.tcs.ebpp.mbean.CustomerProfile.main(CustomerProfile.java:37)
|