-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: HowTo: Bind Hibernate to JBoss DataSource, Securely
PostPosted: Thu Aug 02, 2007 2:54 pm 
Beginner
Beginner

Joined: Tue Jul 25, 2006 12:34 pm
Posts: 25
I am trying to figure out how to create a SessionFactory when my web app is instantiated, securely. By securely, I'm trying to use the J2EE/JBoss security-domain setup where login-config.xml lists an <application-policy> which is then referenced in the <jboss-web.xml> file as a security-domain. Then, in my -ds.xml file, I reference the domain and remove the user name and password.

The problem seems to be that Hibernate is NOT seeing the JBoss JNDI bound DataSource objects.

Hibernate version: 3.x

Mapping documents:

Data Source

Code:
<local-tx-datasource>
   <jndi-name>us/tx/state/oag/dev/ApplicationSecurity</jndi-name>
   <connection-url>jdbc:jtds:sybase://sydev1a:9000/application_security</connection-url>
   <driver-class>net.sourceforge.jtds.jdbcx.JtdsDataSource</driver-class>
   <security-domain>OagWebAppDomainDev</security-domain>
   <min-pool-size>3</min-pool-size>
   <max-pool-size>5</max-pool-size>
</local-tx-datasource>


Code:
<session-factory name="SessFacApplicationSecurity">

   <!-- Settings for this session factory -->
   <property name="transaction.flush_before_completion">
      false
   </property>
   <property name="transaction.auto_close_session">false</property>

   <!-- Disable second-level cache. -->
   <property name="cache.provider_class">
      org.hibernate.cache.NoCacheProvider
   </property>
   <property name="cache.use_query_cache">false</property>
   <property name="cache.use_minimal_puts">false</property>
   <property name="max_fetch_depth">3</property>

   <!-- Print SQL to stdout. -->
   <property name="show_sql">true</property>
   <property name="format_sql">true</property>

   <!-- Bind the getCurrentSession() method to the thread. -->
   <property name="current_session_context_class">thread</property>

    <!--  store this SessionFactory in JNDI -->
    <property name="session_factory_name">
       java:hibernate/SessFacApplicationSecurity
    </property>
   
   <property name="connection.datasource">
      java:us/tx/state/oag/dev/ApplicationSecurity
   </property>
   <property name="transaction.factory_class">
      org.hibernate.transaction.JTATransactionFactory
   </property>
   <property name="transaction.manager_lookup_class">
      org.hibernate.transaction.JBossTransactionManagerLookup
   </property>

   ...



Full stack trace of any exception that occurs:

JBoss Bootup...the JNDI objects ARE being registered...
    13:33:56,359 INFO [RARDeployment] Required license terms exist, view META-INF/ra.xml in .../deploy/mail-ra.rar
    13:33:57,187 INFO [WrapperDataSourceService] Bound ConnectionManager 'jboss.jca:service=DataSourceBinding,name=us/tx/state/oag/dev/ApplicationSecurity' to JNDI name 'java:us/tx/state/oag/dev/ApplicationSecurity'
    13:33:57,234 INFO [WrapperDataSourceService] Bound ConnectionManager 'jboss.jca:service=DataSourceBinding,name=us/tx/state/oag/dev/Common' to JNDI name 'java:us/tx/state/oag/dev/Common'
    13:33:57,296 INFO [WrapperDataSourceService] Bound ConnectionManager 'jboss.jca:service=DataSourceBinding,name=us/tx/state/oag/dev/Workflows' to JNDI name 'java:us/tx/state/oag/dev/Workflows'
    13:33:57,328 INFO [WrapperDataSourceService] Bound ConnectionManager 'jboss.jca:service=DataSourceBinding,name=us/tx/state/oag/dev/EmployeeWarehouse' to JNDI name 'java:us/tx/state/oag/dev/EmployeeWarehouse'
    13:33:57,546 INFO [WrapperDataSourceService] Bound ConnectionManager 'jboss.jca:service=DataSourceBinding,name=us/tx/state/oag/prd/ApplicationSecurity' to JNDI name 'java:us/tx/state/oag/prd/ApplicationSecurity'
    13:33:57,796 INFO [WrapperDataSourceService] Bound ConnectionManager 'jboss.jca:service=DataSourceBinding,name=us/tx/state/oag/prd/DpsLicenses' to JNDI name 'java:us/tx/state/oag/prd/DpsLicenses'
    13:33:57,875 INFO [TomcatDeployer] deploy, ctxPath=/OagPortalRegistration, warUrl=.../deploy/OagPortalRegistration.war/

Then, as Hibernate creates a session factory...

    13:34:05,140 INFO [HbmBinder] Mapping class: us.tx.state.oag.ApplicationSecurity.ddl.StateNames -> StateNames
    13:34:05,156 WARN [HbmBinder] Could not perform validation checks for component as the class us.tx.state.oag.ApplicationSecurity.ddl.StateNames was not found
    13:34:05,156 INFO [Configuration] Mapping resource: us/tx/state/oag/ApplicationSecurity/ddl/DdlPublicApplications.hbm.xml
    13:34:05,187 INFO [HbmBinder] Mapping class: us.tx.state.oag.ApplicationSecurity.ddl.HbmDdlPublicApplication -> HbmDdlPublicApplication
    13:34:05,187 INFO [Configuration] Configured SessionFactory: SessFacApplicationSecurity
    13:34:05,187 INFO [Configuration] processing extends queue
    13:34:05,187 INFO [Configuration] processing collection mappings
    13:34:05,187 INFO [Configuration] processing association property references
    13:34:05,187 INFO [Configuration] processing foreign key constraints
    13:34:06,234 INFO [NamingHelper] JNDI InitialContext properties:{}
    13:34:06,593 FATAL [DatasourceConnectionProvider] Could not find datasource: java:us/tx/state/oag/dev/ApplicationSecurity
    javax.naming.NameNotFoundException: us not bound
    at org.jnp.server.NamingServer.getBinding(NamingServer.java:529)
    at org.jnp.server.NamingServer.getBinding(NamingServer.java:537)
    at org.jnp.server.NamingServer.getObject(NamingServer.java:543)
    at org.jnp.server.NamingServer.lookup(NamingServer.java:267)
    at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:625)
    at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:587)
    at javax.naming.InitialContext.lookup(InitialContext.java:351)
    at org.hibernate.connection.DatasourceConnectionProvider.configure(DatasourceConnectionProvider.java:44)

This is how the context listener class configures Hibernate:

Code:
            String ls_fileName = contextEvent.getServletContext().getRealPath(
                AppSecJdbcConstants.APPSEC_HIBERNATE_CONFIG_FILENAME);
            // load the AppSec library configuration file
            lo_configFile = new File(ls_fileName);
            // create a new hibernate configuration
            lo_hbmConfig = new Configuration().configure(lo_configFile);
           
            // now, create hibernate session factory based on that configuration and store it in the session
            co_AppSecSessFactory = lo_hbmConfig.buildSessionFactory();



Name and version of the database you are using: Sybase 12.x

The generated SQL (show_sql=true): N/A


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.