Warlock wrote:
So the persistence.xml contains only the reference to the hibernate.cfg.xml where you load the annotated classes?
Does Hibernate still run as a JMX Service MBean using this configuration (in fact the style of a mbean is like this: <mbean code="...">...</mbean>, isn't it?)
Regards
Manuel
No, it doesn't deploy as a JMX service.
I found that you can deploy it using a jboss-service.xml and then load the hibernate.cfg.xml at runtime. That way you get the JMX managment.
Here is my jboss-service.xml
<server>
<mbean code="org.jboss.hibernate.jmx.Hibernate"
name="jboss.har:service=MyHibernate">
<attribute name="DatasourceName">
java:/mysqlDataService
</attribute>
<attribute name="Dialect">
org.hibernate.dialect.MySQLDialect
</attribute>
<attribute name="SessionFactoryName">
java:/hibernate/SimpleSessionFactory
</attribute>
<attribute name="ShowSqlEnabled">
false
</attribute>
<attribute name="CacheProviderClass">
org.hibernate.cache.HashtableCacheProvider
</attribute>
<attribute name="Hbm2ddlAuto">
create-drop
</attribute>
</mbean>
</server>
I used the same hibernate.cfg.xml mentioned in my earlier post. To
load the hibernate.cfg.xml, I modified my HibernateUtil class to use
an AnnotationConfiguration object. The code below will load the
hibernate.cfg.xml file ( as long as it's on the classpath )
static {
try {
// Create the SessionFactory
AnnotationConfiguration cfg = new AnnotationConfiguration();
sessionFactory = (SessionFactory) cfg.configure().buildSessionFactory();
} catch (Throwable ex) {
// Make sure you log the exception, as it might be swallowed
log.error("Initial SessionFactory creation failed.", ex);
throw new ExceptionInInitializerError(ex);
}
if ( sessionFactory == null )
throw new ExceptionInInitializerError("Creation of Hibernate SessionFactory using JNDI failed.");
}