Archive for November, 2009


My last post dealt with Websphere configuration for Hibernate with a Datasource for MySQL.  I also mentioned how I typically use Apache Tomcat to do a lot of my testing before deploying to Websphere.  Smart readers will know that the types of applications I am referring to do not include JMS or EJBs but are straight Servlet or Web Services type apps.  Development and Testing for full J2EE based applications should take place using other Application Servers, and or development environments.

With that said, I thought I would post the steps I went through to configure Tomcat for a Datasource, and what I had to do to configure my Hibernate configuration file for that source.

First off, I made no changes to my hibernate.cfg.xml from the one I deployed to Websphere.  So the following configuration parameters are still the same.

<property name=”current_session_context_class”>thread</property>
<property name=”hibernate.bytecode.use_reflection_optimizer”>false</property>
<property name=”hibernate.connection.datasource”>java:comp/env/jdbc/mysqlblogpostdataref</property>
<property name=”show_sql”>true</property>
<property name=”dialect”>org.hibernate.dialect.MySQLDialect</property>
<property name=”hibernate.bytecode.use_reflection_optimizer”>false</property>
<property name=”hibernate.connection.datasource”>java:comp/env/jdbc/mysqlblogpostdataref</property>
<property name=”show_sql”>true</property>
<property name=”dialect”>org.hibernate.dialect.MySQLDialect</property>

I also kept my web.xml the same as my deployment to Websphere.


<resource-ref>
<description>My Blog DataSource</description>
<res-ref-name>jdbc/mysqlblogpostdataref</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>

Now edit your context.xml file stored in the $CATALINA_HOME/conf directory and add a Resource entry.


<Context path="/DBTest" docBase="DBTest"
debug="5" reloadable="true" crossContext="true">

<!-- maxActive: Maximum number of dB connections in pool. Make sure you
configure your mysqld max_connections large enough to handle
all of your db connections. Set to -1 for no limit.
-->

<!-- maxIdle: Maximum number of idle dB connections to retain in pool.
Set to -1 for no limit.  See also the DBCP documentation on this
and the minEvictableIdleTimeMillis configuration parameter.
-->

<!-- maxWait: Maximum time to wait for a dB connection to become available
in ms, in this example 10 seconds. An Exception is thrown if
this timeout is exceeded.  Set to -1 to wait indefinitely.
-->

<!-- username and password: MySQL dB username and password for dB connections  -->

<!-- driverClassName: Class name for the old mm.mysql JDBC driver is
org.gjt.mm.mysql.Driver - we recommend using Connector/J though.
Class name for the official MySQL Connector/J driver is com.mysql.jdbc.Driver.
-->

<!-- url: The JDBC connection url for connecting to your MySQL dB.
-->

<Resource name="jdbc/mysqlblogpostdataref" auth="Container" type="javax.sql.DataSource"
maxActive="100" maxIdle="30" maxWait="10000"
username="dbuser" password="yourpassword" driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost:3306/yourdatabase"/>
</Context>

The key here is to make sure your resource name in the context.xml matches your reference name in the web.xml, this is the only way Tomcat environments know how to map resources from your deployment descriptor to the context.xml.

Yes this is a bit of a tangent from my usual posts, but I like to geek out as much as the next guy, write some code, and deploy it to various Application servers.

I, as I suspect many programmers do, tend to develop my applications within Tomcat then build releases for other platforms such as WebSphere or Weblogic.   In doing so, I have come to the pretty obvious conclusion that it’s a good idea to use a Datasource references within my deployment descriptors, and allow the deployment managers to configure the AppServers for the given resources at deployment time. Over the last few days I have been struggling with how to properly configure a datasource within WebSphere and use the proper naming string within my hibernate.cfg.xml files.  I thought I would share my configuration steps in hopes that no one else has to go through this.

First You have to setup a JDBC Provider.  A JDBC provider is a JDBC driver that you can then use to connect to a database using a data source that you setup later in this example.

From the Administrative console, Open up the Resources pane, then expand JDBC.  Select JDBC Providers.

Figure 1. Depending on your scope selection, this screen shows all of the providers you have set up on your Websphere Server.

Select the Scope that you want this resource to be available at. Cell will make this resource available to all of the managed nodes and servers, but you can also make this resource available at the node or the server level.

Select New.

Figure 2. Set up your new resource.

Database Type: User Defined

Implementation Class Name: com.mysql.jdbc.jdbc2.optional.MysqlConnectionPoolDataSource

Name: That’s up to you.

Select Next, and setup your classpath to your mysql driver.

Figure 3. Setup Class Path

Hit Next then Finish.  Don’t forget to Save this setup to the master configuration.

Under the JDBC node, Select Data Providers.

Figure 4. Data Sources List

Select New.

Figure 5. New Data Source

Data Source Name: Up to you

JNDI Name: this is up to you, but the standard naming convention should be;  jdbc/datasourcerefname.  For this example we will use jdbc/mysqlblogpost.

Select Next

Figure 6. Select an Exisiting JDBC Provider

Make sure on this screen you select the JDBC provider you setup earlier.

Select Next

Figure 7. Leave the default as is.

Hit Next and then Finish.  — Remember to save this to your master configuration.

Figure 8. Your Data Source List should look something like this now.

Select the data source you just created and select the JAAS-J2C authentication data link to the side.

Figure 9. JAAS List

Select New.

Figure 9. New User/Password Reference

Hit Ok, and Save.

Go back to your Datasource and select Custom Properties.

Either set or add the following properties.

Property
Name
Type Value
databaseName java.lang.String mysqlDB
Port java.lang.String 3306
serverName java.lang.String <server-name>

After you add this..  Remember to save the changes to your master configuration.

Now lets get to your Application.

Setup a Resource Reference in your Deployment Descriptor.

When you deploy this application Websphere will ask you to map this resource.  You will be mapping it to the data source you just set up. jdbc/mysqlblogpost


<resource-ref>

<description>Your New DataSource</description>

<res-ref-name>jdbc/mysqlblogpostdataref</res-ref-name>

<res-type>javax.sql.DataSource</res-type>

<res-auth>Container</res-auth>

</resource-ref>

Then your Hibernate Configuration file can reference your web.xml’s reference.

Hibernate.cfg.xml
<property name="current_session_context_class">thread</property>
<property name="hibernate.bytecode.use_reflection_optimizer">false</property>
<property name="hibernate.connection.datasource">java:comp/env/jdbc/mysqlblogpostdataref</property>
<property name="show_sql">true</property>
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>

That’s It!!  Happy Deploying!!

IT Architecture is the evolution of a career, in that it takes years of experience designing, building, and rolling out systems that match a set of criteria.   The hardest part as I have detailed in previous posts is not the technology however, but matching the technology to the requirements.   Knowing which questions to ask at the right time, so that you can flush out more from your clients and customers than just a set of screen shots, or a bullet point list of hardware requirements.  The Architect must take a broader outlook then this, always having in the back of their mind what other factors could be impacting the solution, or strategy that have not been communicated.

I recently posted this question on LinkedIn and got a few key responses I wanted to highlight here.

IT architects are visionaries, coaches, team leaders, business-to-technical liaisons, computer scientists, and industry experts. – OpenGroup.com

I believe that a crucial role of a Solution Architect is to act as the link between business stakeholders and technology experts. You need to exchange ideas effectively with both groups and need significant technical and business understanding for this to be possible, without necessariy being an expert in either area yourself. Typically, architects come from a business background and acquire technical knowledge or come from a techincal background and acquire business understanding. In my experience, the latter case is more common and architects are therefore more likely to lean to the technical.  – Paul Harris – CRM and Integration Consultant

In short, the Architect is the only guy in the room who has decent street cred with the Development and Marketing folks. He’s diplomatic and savvy when it matters, and can think very critically about architecture and applying technology where it counts.  AD Kent – Managing Partner at DocuConsulting

As all three quotes explain, the Architect is the link between business and technology, which means that he or she has to be able to communicate and build relationships with both sides.   For instance, if the Architect is in a meeting with the CFO of an organization, project and operational cost are important. It is important to communicate how the given project or strategy will cut costs to the organization.  If you don’t know hard numbers, be prepared to at least communicate in terms of hours spent in the current environment to generate output, and how a new architecture, system, or solution, will cut that down over time.   Many CFO’s can calculate simple math in their head, and when they hear “reduction in hours to produce” they know your talking in terms of savings to the company.    The better your statistics are, the more inclined they are to support your initiative.

This conversation is completely different than the one you would have with engineers and developers.  When communicating with these folks, you must similarly direct your conversation to something that matters to them.  Performance, Design, Quality, Extensibility, Importance to the organization, are all characteristics of an Architectural knowledge base.   It’s also important as the Open Group states, to coach, mentor, and encourage your teams as part of the production endeavor.

So in short, the answer to the overriding question is yes.  The Architect must be someone who can operate with many different hats and gain the respect of peers, those reporting to them, management, and even sales and marketing.   This is often a result of many years of experience in all facets of business technology, and a general understanding of what each component of the business requires to be successful.

Follow

Get every new post delivered to your Inbox.