-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Hibernate Query Execution
PostPosted: Thu Apr 02, 2009 10:27 am 
Newbie

Joined: Thu Apr 02, 2009 10:12 am
Posts: 1
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)


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.