Hi ,
I am new to hibernate and facing issues with composite key mapping.Please help,.While running class name Example,At line 36:-
List sites = session.createQuery("Select h from SiteStageDto h").list();
code is returning null pointer,the hql is returing right query but unable to fetch data to list.
I am also posting the configuration hbm.xml file for both my class SiteStageDto ans Site_Uda_Stage.
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;
import com.ericsson.hibernate.HibernateUtil;
public class Example
{
private static SessionFactory factory;
public static void main(String[] args) {
try{
factory = HibernateUtil.buildSessionFactory();
}catch (Throwable ex) {
System.err.println("Failed to create sessionFactory object." + ex);
throw new ExceptionInInitializerError(ex);
}
Example ex = new Example();
ex.getsite();
}
private void getsite() {
Session session = factory.openSession();
Transaction tx = null;
tx = session.beginTransaction();
List sites = session.createQuery("Select h from SiteStageDto h").list();
for (Iterator iterator = sites.iterator(); iterator.hasNext();)
{
SiteStageDto sitestage = (SiteStageDto) iterator.next();
System.out.print("SITE_ID: " + sitestage.getSiteId());
System.out.print("clli: " + sitestage.getClli());
System.out.println(" NUM: " + sitestage.getNum());
System.out.println(" BASE_NUM: " + sitestage.getBaseNum());
System.out.println(" LATITUDE: " + sitestage.getLatitude());
System.out.println(" LONGITUDE: " + sitestage.getLatitude());
System.out.println(" RESTRICTIONS: " + sitestage.getRestrictions());
System.out.println(" rdbName: " + sitestage.getRdbName());
System.out.println(" sourceOfData: " + sitestage.getSourceOfData());
System.out.println(" gamJobId: " + sitestage.getGamJobId());
Set siteudastagedto = sitestage.getSiteudastagedto();
for (Iterator iterator2 = siteudastagedto.iterator(); iterator2.hasNext();)
{
SiteUdaStageDto siteuda = (SiteUdaStageDto) iterator2.next();
System.out.println("GamJobId: " + siteuda.getGamJobId());
System.out.println("RdbName: " + siteuda.getRdbName());
System.out.println("SourceOfData: " + siteuda.getSourceOfData());
System.out.println("Uda: " + siteuda.getUda());
System.out.println("Udg: " + siteuda.getUdg());
System.out.println("Value: " + siteuda.getValue());
}
tx.commit();
}
//tx.commit();
}
}