0 Replies Latest reply on Jul 3, 2008 2:54 AM by Roberto López López

    Problems configuring Hibernate on JBoss

    Roberto López López Newbie

      Hi there!

      I'm configuring a struts project to access a mysql db through hibernate. It's my first time configuring hibernate in a project, so I have some problems.

      The most important, and the only I can't solve is this:

      - I have written my hibernate.cfg.xml with the config stuff.
      - I have written some table mappings (and their beans) and introduced them into hibernate.cfg.xml.
      - I have written a plugin to hook hibernate into struts, and declared it into struts-config.xml.

      I package the whole project (struts + hibernate) and deploy it to my JBoss 4.2.2 server. Then, I get the following output:

      11:39:03,021 INFO [TomcatDeployer] deploy, ctxPath=/XXXXXXX, warUrl=.../tmp/deploy/tmp23130XXXXXXX-exp.war/
      11:39:03,391 INFO [ActionServlet] Loading chain catalog from jndi:/localhost/XXXXXXX/WEB-INF/chain-config.xml
      11:39:03,924 INFO [TilesPlugin] Tiles definition factory loaded for module ''.
      11:39:04,003 INFO [Environment] Hibernate 3.2.6
      11:39:04,010 INFO [Environment] hibernate.properties not found
      11:39:04,015 INFO [Environment] Bytecode provider name : javassist
      11:39:04,024 INFO [Environment] using JDK 1.4 java.sql.Timestamp handling
      11:39:04,141 INFO [Configuration] configuring from url: file:/opt/jboss-4.2.2.GA/server/default/tmp/deploy/tmp23130XXXXXXX-exp.war/WEB-INF/hibernate.cfg.xml
      11:39:04,151 INFO [Configuration] Reading mappings from resource : /com/mmm/XXXXXXX/hibernate/mappings/Paises.hbm.xml
      11:39:05,535 INFO [HbmBinder] Mapping class: com.mmm.XXXXXXX.hibernate.beans.Paises -> paises
      11:39:05,570 INFO [Configuration] Reading mappings from resource : /com/mmm/XXXXXXX/hibernate/mappings/Subcategorias.hbm.xml
      11:39:06,870 INFO [HbmBinder] Mapping class: com.mmm.XXXXXXX.hibernate.beans.Subcategorias -> subcategorias
      11:39:06,874 INFO [Configuration] Reading mappings from resource : /com/mmm/XXXXXXX/hibernate/mappings/SubcategoriasUser.hbm.xml
      11:39:08,213 INFO [HbmBinder] Mapping class: com.mmm.XXXXXXX.hibernate.beans.SubcategoriasUser -> subcategorias_user
      11:39:08,214 INFO [Configuration] Configured SessionFactory: null
      11:39:08,383 INFO [DriverManagerConnectionProvider] Using Hibernate built-in connection pool (not for production use!)
      11:39:08,383 INFO [DriverManagerConnectionProvider] Hibernate connection pool size: 20
      11:39:08,383 INFO [DriverManagerConnectionProvider] autocommit mode: false
      11:39:08,384 INFO [DriverManagerConnectionProvider] using driver: com.mysql.jdbc.Driver at URL: jdbc:mysql://localhost:3306/XXXXXXX
      11:39:08,384 INFO [DriverManagerConnectionProvider] connection properties: {user=administrador, password=ubuntur00t}
      11:39:08,397 INFO [SettingsFactory] RDBMS: MySQL, version: 5.0.51a-3ubuntu5.1
      11:39:08,397 INFO [SettingsFactory] JDBC driver: MySQL-AB JDBC Driver, version: mysql-connector-java-5.1.5 ( Revision: ${svn.Revision} )
      11:39:08,421 INFO [Dialect] Using dialect: org.hibernate.dialect.MySQLDialect
      11:39:08,428 INFO [TransactionFactoryFactory] Transaction strategy: org.hibernate.transaction.JDBCTransactionFactory
      11:39:08,431 INFO [TransactionManagerLookupFactory] No TransactionManagerLookup configured (in JTA environment, use of read-write or transactional second-level cache is not recommended)
      [...]
      [...SettingsFactory info...]
      [...]
      11:39:08,506 INFO [SessionFactoryImpl] building session factory
      11:39:09,058 INFO [DriverManagerConnectionProvider] cleaning up connection pool: jdbc:mysql://localhost:3306/XXXXXXX
      11:39:09,251 INFO [SessionFactoryObjectFactory] Not binding factory to JNDI, no JNDI name configured



      As you can read on the last line, the factory isn't bound to any JNDI uri. Could anyone help me? Bellow are my config files.

      hibernate.hbm.xml:

      <?xml version='1.0' encoding='UTF-8'?>
       <!DOCTYPE hibernate-configuration PUBLIC
       "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
       "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
       <hibernate-configuration>
       <session-factory>
      
       <property name="connection.url">jdbc:mysql://localhost:3306/XXXXXXX</property>
       <property name="connection.username">XXX</property>
       <property name="connection.driver_class">com.mysql.jdbc.Driver</property>
       <property name="dialect">org.hibernate.dialect.MySQLDialect</property>
       <property name="connection.password">XXXX</property>
       <property name="transaction.factory_class">org.hibernate.transaction.JDBCTransactionFactory</property>
       <!-- thread is the short name for
       org.hibernate.context.ThreadLocalSessionContext
       and let Hibernate bind the session automatically to the thread
       -->
       <property name="current_session_context_class">thread</property>
       <!-- this will show us all sql statements -->
       <property name="hibernate.show_sql">true</property>
      
       <!-- mapping files -->
       <mapping resource="/com/mmm/XXXXXXX/hibernate/mappings/Paises.hbm.xml"/>
       <mapping resource="/com/mmm/XXXXXXX/hibernate/mappings/Subcategorias.hbm.xml"/>
       <mapping resource="/com/mmm/XXXXXXX/hibernate/mappings/SubcategoriasUser.hbm.xml"/>
      
       </session-factory>
       </hibernate-configuration>




      struts-config.xml:

      <struts-config>
       <!-- ... -->
       <plug-in className="com.mmm.XXXXXXX.hibernate.plugin.HibernatePlugin">
       <set-property property="path" value="/WEB-INF/hibernate.cfg.xml"/>
       </plug-in>
       </struts-config>




      By the way, I can't understand hibernate-service.xml. I have read that I need to introduce the server datasource I want hibernate to use, but in hibernate.cfg.xml I have written the uri of mysql. Isn't it redundant? It's necessary to introduce the datasource in hibernate-service.xml??? Bellow its code:

      <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/XXXXXXX</attribute>
       <attribute name="CacheProviderClass">
       net.sf.hibernate.cache.HashtableCacheProvider
       </attribute>
      
       <attribute name="Hbm2ddlAuto">create-drop</attribute>
       <attribute name="ShowSqlEnabled">true</attribute>
       </mbean>
       </server>



      The last question: do I need to separately package the hibernate application to access it from my struts webapp? I'm using ant to package and deploy my war, is there any ant task to package a har? I've searched on google and didn't found anything.

      Thank you very much in advance.