It looks like a hard road getting Hibernate work, but I'm getting closer. Stdout below clearly tells me that Hibernate engine is up and running, but I still get an NoClassDefFoundError with no classname or anything to point me in the right direction. Exception is thrown at MenuItems' row
Session session = HibernateUtil.currentSession();. After that the program enters HibernateUtils
static-block but the first row throws the exception. This is a long post, I know, but I am stuck:)
thanks,
Jari
HibernateUtil:
Code:
public class HibernateUtil {
private static final SessionFactory sessionFactory;
static {
try {
sessionFactory = new Configuration().configure(HibernateUtil.
class.getClassLoader().getResource("hibernate.cfg.xml")).buildSessionFactory();
} catch (HibernateException ex) {
throw new RuntimeException("Exception building SessionFactory: " + ex.getMessage(), ex);
}
}
public static final ThreadLocal session = new ThreadLocal();
public static Session currentSession() throws HibernateException {
Session s = (Session) session.get();
// Open a new Session, if this Thread has none yet
if (s == null) {
s = sessionFactory.openSession();
session.set(s);
}
return s;
}
public static void closeSession() throws HibernateException {
Session s = (Session) session.get();
session.set(null);
if (s != null)
s.close();
}
}
MenuItems:Code:
public class MenuItems {
private SessionFactory sessions;
public Materialclass[] getMaterialclasses() throws Exception {
try {
// the row below causes the exception
Session session = HibernateUtil.currentSession();
Materialclass[] classes;
Transaction tx= session.beginTransaction();
List list = session.find("from Materialclass matClass order by matClass.definition");
tx.commit();
System.out.println("lista: " + list.size());
classes = (Materialclass[]) list.toArray();
return classes;
} catch (Exception ex) {
System.out.println(ex.getMessage());
ex.printStackTrace();
return null;
} finally {
try {
HibernateUtil.closeSession();
} catch (HibernateException e) {
System.out.println(e.getMessage());
}
}
}
}
Exception:Code:
2003-12-31 13:11:05 StandardWrapperValve[action]: Servlet.service() for servlet action threw exception
java.lang.NoClassDefFoundError
at emove2.hibernate.MenuItems.getMaterialclasses(MenuItems.java:34)
at emove2.struts.action.MenuAction.initReceiverMenu(MenuAction.java:29)
at emove2.struts.action.MenuAction.execute(MenuAction.java:18)
at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:484)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:274)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1482)
at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:507)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:743)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:284)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:204)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:256)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:151)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:564)
at org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:245)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:199)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:151)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:594)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:149)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:564)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:195)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:151)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:164)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:149)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:564)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:156)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:151)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:564)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:972)
at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:211)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:805)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:696)
at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:605)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:677)
at java.lang.Thread.run(Unknown Source)
Stdout:Code:
13:11:03,453 INFO Environment:432 - Hibernate 2.1.1
13:11:03,468 INFO Environment:461 - hibernate.properties not found
13:11:03,468 INFO Environment:481 - using CGLIB reflection optimizer
13:11:03,484 INFO Configuration:858 - configuring from url: file:/E:/Apache/Tomcat50/work/Catalina/localhost/emove2/WEB-INF/classes/hibernate.cfg.xml
13:11:03,609 DEBUG DTDEntityResolver:20 - trying to locate http://hibernate.sourceforge.net/hibernate-configuration-2.0.dtd in classpath under net/sf/hibernate/
13:11:03,812 DEBUG DTDEntityResolver:29 - found http://hibernate.sourceforge.net/hibernate-configuration-2.0.dtd in classpath
13:11:03,890 DEBUG Configuration:801 - connection.datasource=java:comp/env/jdbc/emove2DS
13:11:03,906 DEBUG Configuration:801 - show_sql=false
13:11:03,906 DEBUG Configuration:801 - use_outer_join=true
13:11:03,906 DEBUG Configuration:801 - transaction.factory_class=net.sf.hibernate.transaction.JTATransactionFactory
13:11:03,906 DEBUG Configuration:801 - dialect=net.sf.hibernate.dialect.Oracle9Dialect
13:11:03,906 DEBUG Configuration:952 - null<-org.dom4j.tree.DefaultAttribute@1759d12 [Attribute: name resource value "hibernate.hbm.xml"]
13:11:03,906 INFO Configuration:300 - Mapping resource: hibernate.hbm.xml
13:11:03,921 DEBUG DTDEntityResolver:20 - trying to locate http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd in classpath under net/sf/hibernate/
13:11:03,921 DEBUG DTDEntityResolver:29 - found http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd in classpath
13:11:04,093 INFO Binder:225 - Mapping class: emove2.hibernate.model.Materialclass -> EMOVE_CODE_MATERIALCLASS
13:11:04,234 DEBUG Binder:449 - Mapped property: uid -> uid, type: integer
13:11:04,281 DEBUG Binder:449 - Mapped property: codeGroup -> codeGroup, type: string
13:11:04,281 DEBUG Binder:449 - Mapped property: definition -> definition, type: string
13:11:04,281 DEBUG Binder:449 - Mapped property: materialclass -> materialclass, type: big_decimal
13:11:04,281 INFO Configuration:998 - Configured SessionFactory: null
13:11:04,281 DEBUG Configuration:999 - properties: { lots of properties...}
13:11:04,546 INFO Configuration:584 - processing one-to-many association mappings
13:11:04,546 INFO Configuration:593 - processing one-to-one association property references
13:11:04,546 INFO Configuration:618 - processing foreign key constraints
13:11:04,593 INFO Dialect:82 - Using dialect: net.sf.hibernate.dialect.Oracle9Dialect
13:11:04,593 INFO SettingsFactory:62 - Use outer join fetching: true
13:11:04,625 INFO NamingHelper:26 - JNDI InitialContext properties:{}
13:11:04,656 INFO DatasourceConnectionProvider:51 - Using datasource: java:comp/env/jdbc/emove2DS
13:11:04,671 INFO TransactionFactoryFactory:31 - Transaction strategy: net.sf.hibernate.transaction.JTATransactionFactory
13:11:04,671 INFO NamingHelper:26 - JNDI InitialContext properties:{}
13:11:04,687 INFO TransactionManagerLookupFactory:33 - No TransactionManagerLookup configured (in JTA environment, use of process level read-write cache is not recommended)
13:11:04,687 INFO TransactionManagerLookupFactory:33 - No TransactionManagerLookup configured (in JTA environment, use of process level read-write cache is not recommended)
AbandonedObjectPool is used (org.apache.commons.dbcp.AbandonedObjectPool@694f12)
LogAbandoned: false
RemoveAbandoned: true
RemoveAbandonedTimeout: 30
13:11:05,312 INFO SettingsFactory:89 - Use scrollable result sets: true
13:11:05,312 INFO SettingsFactory:90 - JDBC 2 max batch size: 15
13:11:05,312 INFO SettingsFactory:99 - Query language substitutions: {}
13:11:05,312 INFO SettingsFactory:110 - cache provider: net.sf.ehcache.hibernate.Provider