After spending days on the net and the mailing lists I find something is
just not getting through to me. I feel that what I'm doing is
conceptually simple; yet I can't seem to actually implement any of it. I
think I have a rudimentary understanding of how to integrate Hibernate
into Struts, but I'm unsure on a few points.

First the datasource. I'm trying to set up a default data source that
all web applications can use. I use container based authentication and I
want my realm to use it as well. Trolling these lists showed me a
solution that does work with my realm (XML fragments follow below). But
when I try to use that same datasource with Hibernate, my web
application fails to load and I get the following error:

SEVERE: Could not find datasource: java:comp/env/jdbc/prospectingDB
javax.naming.NameNotFoundException: Name jdbc is not bound in this
Context

Here are the XML fragments from server.xml.

First, I set up a global resource:

<GlobalNamingResources>

<Resource name  = "jdbc/prospectingDB"
          auth  = "Container"
          scope = "Shareable"
          type  = "javax.sql.DataSource"/>
                   
<ResourceParams name="jdbc/prospectingDB">

... Usual parameters go here

Right under the engine tag I define my realm. This works for my
container based auth

<Engine name="Catalina" defaultHost="localhost" debug="10">

<Realm className      = "org.apache.catalina.realm.DataSourceRealm"
         debug          = "99"
       dataSourceName = "jdbc/prospectingDB"
       userTable      = "auth_roles_view"
       userNameCol    = "email"
       userCredCol    = "pwd"
       userRoleTable  = "auth_roles_view"
       roleNameCol    = "role"/>


Then I set up a resource link in the default context:

<DefaultContext>
<ResourceLink name   = "jdbc/prospectingDB"
              global = "jdbc/prospectingDB"
              type   = "javax.sql.DataSource" />
</DefaultContext>

As I said, that all seems to work. But Hibernate bails:

<hibernate-configuration>
  <session-factory name="prospecting/hibernate/SessionFactory">
  <property
name="connection.datasource">java:comp/env/jdbc/prospectingDB</property>
  <property name="show_sql">false</property>
  <property
name="dialect">net.sf.hibernate.dialect.PostgreSQLDialect</property>
  <mapping resource="Employee.hbm.xml"/>
  </session-factory>
</hibernate-configuration>

I can't seem to figure out why. If I change the server.xml to define the
datasource in my web-app context, then I get problems with container
based authentication not finding the datasource??

... and speaking of Hibernate, I think I figured out how to use the
HibernatePlugIn. I use that to set-up a Hibernate session factory on web
app instantiation. But what I'm not 100% sure on is why I need to set-up
a filter to implement the open session in view pattern. One of the
examples I found on the hibernate site doesn't seem to use that filter.
Instead, it looks up the session factory via JNDI right in the action
class. Do I have this right? Could I use either method to grab a
Hibernate session? If I extend the action class to do the JNDI look-up
(so I only need to write the lookup code once), would either method
provide a benefit over the other? 

I'm at a point where I feel like I have enough knowledge to build an
app, but at the same time I don't really understand the technology.
That's kind of precarious - I'm afraid I'm going to leave sessions open
... or something else that will cause errors and be hard to track down.

Thank in advance for any advice!



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to