1 Reply Latest reply on Jul 22, 2008 11:24 AM by Peter Johnson

    JBoss 4.2.2.GA + Hibernate + tutorial application from Getti

    Pavel Klavík Newbie

      Hi,

      I am new user to JBoss and Hibernate. I wanted to test deploy sample application. I have downloaded http://docs.jboss.org/jbossas/getting_started/v5/pdf/startguide.pdf and started go step by step throught chapter 9. I downloaded source codes http://docs.jboss.org/jbossas/getting_started/v3/startguide40.zip.

      Because I am using MySQL in JBoss, I made some reconfigurations in hibernate example, first hibernate-service.xml:

      <server>
       <mbean code="org.jboss.hibernate.jmx.Hibernate"
       name="jboss.har:service=Hibernate">
       <attribute name="DatasourceName">java:/DefaultDS</attribute>
       <attribute name="Dialect">org.hibernate.dialect.MySQLDialect</attribute>
       <attribute name="SessionFactoryName">java:/hibernate/SessionFactory</attribute>
       <attribute name="CacheProviderClass">org.hibernate.cache.HashtableCacheProvider</attribute>
       <!-- <attribute name="Hbm2ddlAuto">create-drop</attribute> -->
       </mbean>
      </server>
      


      Here is my mysql_ds.xml:

      <?xml version="1.0" encoding="UTF-8"?>
      
      <!-- $Id: mysql-ds.xml 63175 2007-05-21 16:26:06Z rrajesh $ -->
      <!-- Datasource config for MySQL using 3.0.9 available from:
      http://www.mysql.com/downloads/api-jdbc-stable.html
      -->
      
      <datasources>
       <local-tx-datasource>
       <jndi-name>DefaultDS</jndi-name>
       <connection-url>jdbc:mysql://localhost:3306/cezAS</connection-url>
       <driver-class>com.mysql.jdbc.Driver</driver-class>
       <user-name>username</user-name>
       <password>password</password>
       <exception-sorter-class-name>org.jboss.resource.adapter.jdbc.vendor.MySQLExceptionSorter</exception-sorter-class-name>
       <!-- should only be used on drivers after 3.22.1 with "ping" support
       <valid-connection-checker-class-name>org.jboss.resource.adapter.jdbc.vendor.MySQLValidConnectionChecker</valid-connection-checker-class-name>
       -->
       <!-- sql to call when connection is created
       <new-connection-sql>some arbitrary sql</new-connection-sql>
       -->
       <!-- sql to call on an existing pooled connection when it is obtained from pool - MySQLValidConnectionChecker is preferred for newer drivers
       <check-valid-connection-sql>some arbitrary sql</check-valid-connection-sql>
       -->
      
       <!-- corresponding type-mapping in the standardjbosscmp-jdbc.xml -->
       <metadata>
       <type-mapping>mySQL</type-mapping>
       </metadata>
       </local-tx-datasource>
      </datasources>
      


      Then I tried to deploy example:
      ant -f jboss-build.xml


      and everything went fine:
      12:30:54,462 INFO [TomcatDeployer] undeploy, ctxPath=/roster, warUrl=.../tmp/deploy/tmp42306HibernateRoster.ear-contents/roster-exp.war/
      12:30:54,514 INFO [SessionFactoryImpl] closing
      12:30:54,559 INFO [EARDeployer] Undeploying J2EE application, destroy step: file:/usr/jboss/jboss-4.2.2.GA/server/default/deploy/HibernateRoster.ear
      12:30:54,564 INFO [EARDeployer] Undeployed J2EE application: file:/usr/jboss/jboss-4.2.2.GA/server/default/deploy/HibernateRoster.ear
      12:30:54,570 INFO [EARDeployer] Init J2EE application: file:/usr/jboss/jboss-4.2.2.GA/server/default/deploy/HibernateRoster.ear
      12:30:54,744 INFO [Configuration] Searching for mapping documents in jar: roster.har
      12:30:54,751 INFO [Configuration] Found mapping document in jar: org/jboss/roster/Player.hbm.xml
      12:30:54,761 ERROR [DTDEntityResolver] Don't use old DTDs, read the Hibernate 3.x Migration Guide!
      12:30:55,997 INFO [HbmBinder] Mapping class: org.jboss.roster.Player -> PlayerBean
      12:30:55,999 INFO [NamingHelper] JNDI InitialContext properties:{}
      12:30:56,008 INFO [DatasourceConnectionProvider] Using datasource: java:/DefaultDS
      12:30:56,009 INFO [SettingsFactory] RDBMS: MySQL, version: 5.0.51a
      12:30:56,010 INFO [SettingsFactory] JDBC driver: MySQL-AB JDBC Driver, version: mysql-connector-java-5.1.6 ( Revision: ${svn.Revision} )
      12:30:56,010 INFO [Dialect] Using dialect: org.hibernate.dialect.MySQLDialect
      12:30:56,011 INFO [TransactionFactoryFactory] Transaction strategy: org.hibernate.transaction.JTATransactionFactory
      12:30:56,011 INFO [NamingHelper] JNDI InitialContext properties:{}
      12:30:56,012 INFO [TransactionManagerLookupFactory] instantiating TransactionManagerLookup: org.hibernate.transaction.JBossTransactionManagerLookup
      12:30:56,012 INFO [TransactionManagerLookupFactory] instantiated TransactionManagerLookup
      12:30:56,012 INFO [TransactionManagerLookupFactory] instantiating TransactionManagerLookup: org.hibernate.transaction.JBossTransactionManagerLookup
      12:30:56,012 INFO [TransactionManagerLookupFactory] instantiated TransactionManagerLookup
      12:30:56,012 INFO [SettingsFactory] Automatic flush during beforeCompletion(): enabled
      12:30:56,012 INFO [SettingsFactory] Automatic session close at end of transaction: enabled
      12:30:56,013 INFO [SettingsFactory] JDBC batch size: 15
      12:30:56,013 INFO [SettingsFactory] JDBC batch updates for versioned data: disabled
      12:30:56,013 INFO [SettingsFactory] Scrollable result sets: enabled
      12:30:56,013 INFO [SettingsFactory] JDBC3 getGeneratedKeys(): enabled
      12:30:56,013 INFO [SettingsFactory] Connection release mode: after_statement
      12:30:56,013 INFO [SettingsFactory] Maximum outer join fetch depth: 2
      12:30:56,013 INFO [SettingsFactory] Default batch fetch size: 1
      12:30:56,013 INFO [SettingsFactory] Generate SQL with comments: disabled
      12:30:56,013 INFO [SettingsFactory] Order SQL updates by primary key: disabled
      12:30:56,013 INFO [SettingsFactory] Order SQL inserts for batching: disabled
      12:30:56,014 INFO [SettingsFactory] Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory
      12:30:56,014 INFO [ASTQueryTranslatorFactory] Using ASTQueryTranslatorFactory
      12:30:56,015 INFO [SettingsFactory] Query language substitutions: {}
      12:30:56,015 INFO [SettingsFactory] JPA-QL strict compliance: disabled
      12:30:56,015 INFO [SettingsFactory] Second-level cache: enabled
      12:30:56,015 INFO [SettingsFactory] Query cache: disabled
      12:30:56,015 INFO [SettingsFactory] Cache provider: org.hibernate.cache.HashtableCacheProvider
      12:30:56,015 INFO [SettingsFactory] Optimize cache for minimal puts: disabled
      12:30:56,016 INFO [SettingsFactory] Structured second-level cache entries: disabled
      12:30:56,016 INFO [SettingsFactory] Statistics: disabled
      12:30:56,016 INFO [SettingsFactory] Deleted entity synthetic identifier rollback: disabled
      12:30:56,016 INFO [SettingsFactory] Default entity-mode: pojo
      12:30:56,016 INFO [SettingsFactory] Named query checking : enabled
      12:30:56,020 INFO [SessionFactoryImpl] building session factory
      12:30:56,041 INFO [SessionFactoryObjectFactory] Not binding factory to JNDI, no JNDI name configured
      12:30:56,042 INFO [NamingHelper] JNDI InitialContext properties:{}
      12:30:56,047 INFO [Hibernate] SessionFactory successfully built and bound into JNDI [java:/hibernate/SessionFactory]
      12:30:56,063 INFO [TomcatDeployer] deploy, ctxPath=/roster, warUrl=.../tmp/deploy/tmp42307HibernateRoster.ear-contents/roster-exp.war/
      12:30:56,204 INFO [EARDeployer] Started J2EE application: file:/usr/jboss/jboss-4.2.2.GA/server/default/deploy/HibernateRoster.ear
      


      But when I have tried to test client at http://localhost:8080/roster/players.jsp, i got following:
      12:31:40,164 ERROR [[jsp]] Servlet.service() for servlet jsp threw exception
      org.apache.jasper.JasperException: Unable to compile class for JSP:
      
      An error occurred at line: 8 in the jsp file: /players.jsp
      SessionFactory cannot be resolved to a type
      5:
      6: <%
      7: InitialContext ctx = new InitialContext();
      8: SessionFactory factory = (SessionFactory)
      9: ctx.lookup("java:/hibernate/SessionFactory");
      10: Session hsession = factory.openSession();
      11: try {
      
      
      An error occurred at line: 8 in the jsp file: /players.jsp
      SessionFactory cannot be resolved to a type
      5:
      6: <%
      7: InitialContext ctx = new InitialContext();
      8: SessionFactory factory = (SessionFactory)
      9: ctx.lookup("java:/hibernate/SessionFactory");
      10: Session hsession = factory.openSession();
      11: try {
      
      
      An error occurred at line: 10 in the jsp file: /players.jsp
      Session cannot be resolved to a type
      7: InitialContext ctx = new InitialContext();
      8: SessionFactory factory = (SessionFactory)
      9: ctx.lookup("java:/hibernate/SessionFactory");
      10: Session hsession = factory.openSession();
      11: try {
      12: request.setAttribute("players",
      13: hsession.find("from org.jboss.roster.Player order by name"));
      
      
      Stacktrace:
       at org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:92)
       at org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:330)
       at org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:415)
       at org.apache.jasper.compiler.Compiler.compile(Compiler.java:308)
       at org.apache.jasper.compiler.Compiler.compile(Compiler.java:286)
       at org.apache.jasper.compiler.Compiler.compile(Compiler.java:273)
       at org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:566)
       at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:316)
       at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:336)
       at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
       at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
       at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
       at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
       at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
       at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
       at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
       at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230)
       at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
       at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:179)
       at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:84)
       at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
       at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
       at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:157)
       at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
       at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:262)
       at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
       at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
       at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:446)
       at java.lang.Thread.run(Thread.java:619)
      


      Please, help me. Does anyone know, where can be problem??

      Thanks!