Section 5.3. Hibernate MBean Service Descriptor


5.3. Hibernate MBean Service Descriptor

Now that we have the HBM file in place, we must create an MBean service configuration file for Hibernate. Hibernate is a service, no different than Hypersonic or any of the others. Each MBean needs a service configuration file like Example 5-4 so that JBoss will recognize it and run it on startup.

Example 5-4. hibernate-service.xml
 <server>     <mbean code="org.jboss.hibernate.jmx.Hibernate"            name="jboss.har:service=Hibernate">         <attribute name="DatasourceName">java:/JBossAtWorkDS</attribute>         <attribute name="Dialect"> org.hibernate.dialect.HSQLDialect</attribute>         <attribute name="SessionFactoryName">                    java:/hibernate/SessionFactory</attribute>         <attribute name="CacheProviderClass">            org.hibernate.cache.HashtableCacheProvider         </attribute>     </mbean> </server> 

Let's step through it line by line.

  • The <mbean> element names the service and specifies the implementing class.

  • The <attribute name="DatasourceName"> element is a link to your Hypersonic datasource using the global JNDI name.

  • The <attribute name="Dialect"> element tells Hibernate which type of database it talks to. As much as we'd like to believe the "s" in SQL stands for "standard," the acronym is short for "Structured Query Language." Each database vendor's implementation of SQL varies, and this setting allows Hibernate to generate well-formed SQL for the specific database in question. Other common dialects include org.hibernate.dialect.Oracle9Dialect and org.hibernate.dialect.MySQLDialect.

  • The <attribute name="SessionFactoryName"> element is the global JNDI name for this service's SessionFactory. We'll use this name in jboss-web.xml (and map it to a local ENC-style name in web.xml).

  • Finally, the <attribute name="CacheProviderClass"> element tells Hibernate what caching strategy to use. Rather than going round trip to the database for each request, Hibernate caches the results to improve performance. (See the Hibernate documentation for a more in-depth discussion of the different CacheProviders.)



JBoss at Work. A Practical Guide
JBoss at Work: A Practical Guide
ISBN: 0596007345
EAN: 2147483647
Year: 2004
Pages: 197

Similar book on Amazon

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net