Hi Friend i am facing problem in fetch records that why i join this forum.
my problem is that i having database around 800 tables and i generate hbm and Pojo using Hibernate reverse Engineering wizard.that tool generate mapping file and pojo fine.but when i am testing it give 's error on building session factory.the error is:-
17:03:22,011 INFO SessionFactoryImpl:161 - building session factory Initial SessionFactory creation failed.java.lang.OutOfMemoryError: Java heap space Exception in thread "main" java.lang.ExceptionInInitializerError at com.factory.HibernateUtil.buildSessionFactory(HibernateUtil.java:17) at com.factory.HibernateUtil.<clinit>(HibernateUtil.java:6) at com.factory.First.main(First.java:32) Caused by: java.lang.OutOfMemoryError: Java heap space at java.util.Arrays.copyOfRange(Arrays.java:3209) at java.lang.String.<init>(String.java:216) at org.objectweb.asm.Type.getInternalName(Unknown Source) at net.sf.cglib.core.CodeEmitter.emit_field(CodeEmitter.java:468) at net.sf.cglib.core.CodeEmitter.getfield(CodeEmitter.java:425) at net.sf.cglib.proxy.Enhancer$6.beginMethod(Enhancer.java:924) at net.sf.cglib.proxy.InvocationHandlerGenerator.generate(InvocationHandlerGenerator.java:42) at net.sf.cglib.proxy.Enhancer.emitMethods(Enhancer.java:942) at net.sf.cglib.proxy.Enhancer.generateClass(Enhancer.java:498) at net.sf.cglib.core.DefaultGeneratorStrategy.generate(DefaultGeneratorStrategy.java:25) at net.sf.cglib.core.AbstractClassGenerator.create(AbstractClassGenerator.java:216) at net.sf.cglib.proxy.Enhancer.createHelper(Enhancer.java:377) at net.sf.cglib.proxy.Enhancer.createClass(Enhancer.java:317) at org.hibernate.proxy.pojo.cglib.CGLIBLazyInitializer.getProxyFactory(CGLIBLazyInitializer.java:127) at org.hibernate.proxy.pojo.cglib.CGLIBProxyFactory.postInstantiate(CGLIBProxyFactory.java:43) at org.hibernate.tuple.entity.PojoEntityTuplizer.buildProxyFactory(PojoEntityTuplizer.java:162) at org.hibernate.tuple.entity.AbstractEntityTuplizer.<init>(AbstractEntityTuplizer.java:135) at org.hibernate.tuple.entity.PojoEntityTuplizer.<init>(PojoEntityTuplizer.java:55) at org.hibernate.tuple.entity.EntityEntityModeToTuplizerMapping.<init>(EntityEntityModeToTuplizerMapping.java:56) at org.hibernate.tuple.entity.EntityMetamodel.<init>(EntityMetamodel.java:295) at org.hibernate.persister.entity.AbstractEntityPersister.<init>(AbstractEntityPersister.java:434) at org.hibernate.persister.entity.SingleTableEntityPersister.<init>(SingleTableEntityPersister.java:109) at org.hibernate.persister.PersisterFactory.createClassPersister(PersisterFactory.java:55) at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:226) at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1294) at org.hibernate.cfg.AnnotationConfiguration.buildSessionFactory(AnnotationConfiguration.java:915) at com.factory.HibernateUtil.buildSessionFactory(HibernateUtil.java:11) ... 2 more 17:04:12,283 INFO DriverManagerConnectionProvider:147 - cleaning up connection pool: jdbc:mysql://localhost:3306/enze-db
so i increase a size of eclipse heap then the result will same......some time its run but it giving out put very slowly.........
my session factory code is:- public class HibernateUtil { private static final SessionFactory sessionFactory = buildSessionFactory(); private static SessionFactory buildSessionFactory() { try { // Create the SessionFactory from hibernate.cfg.xml return new AnnotationConfiguration().configure().buildSessionFactory(); } catch (Throwable ex) { // Make sure you log the exception, as it might be swallowed System.err.println("Initial SessionFactory creation failed." + ex); throw new ExceptionInInitializerError(ex); } } public static SessionFactory getSessionFactory() { return sessionFactory; } public static void shutdown() { // Close caches and connection pools getSessionFactory().close(); }
}
and my testing class code is :-public class First {
public static void main(String[] args) { SessionFactory sf=HibernateUtil.getSessionFactory(); Statistics st=sf.getStatistics(); st.setStatisticsEnabled(true); Session session = sf.openSession(); try { String QUERY="from AccommodationClass a where a.accommodationClassId='001'"; Query query =session.createQuery(QUERY).setCacheable(true); List l =query.list(); System.out.println("QUERY EXECUTION TIME :----->"+st.getQueryExecutionMaxTime()); System.out.println("Collection FETCH Count :------>"+st.getCollectionFetchCount()); System.out.println("Collection LOAD Count :-------> "+st.getCollectionLoadCount()); System.out.println("Connect Count :-------> "+st.getConnectCount()); System.out.println(":Entiry-------> "+st.getEntityLoadCount()); System.out.println("===>"+l); } catch (HibernateException e) { e.printStackTrace(); session.flush(); session.clear();
session.close(); } finally { session.flush(); session.clear();
session.close(); }
}
}
plz give me sol..........iam using hibernate 3.2 and Annotations. Thanks AMit
|