`
zhangljerry
  • 浏览: 144436 次
  • 性别: Icon_minigender_1
  • 来自: 杭州
社区版块
存档分类
最新评论

Using Hibernate with JBoss

阅读更多

NOTE THAT THIS IS A PAGE MAINTAINED BY HIBERNATE USERS, NOT JBOSS INC!

Please read the Hibernate reference documentation and JBoss AS documentation before doing anything listed here!


This guide is intended for developers who use JBoss as the target platform for their J2EE applications.

The first method used here is derived from Konstantin Pribluda's Hibernate demo package in the forum - http://sourceforge.net/forum/message.php?msg_id=1801820 - and can be used on JBoss 3.0.x and 3.2 with Hibernate 1.2.2, and without XDoclet (which most developers use though).

The second discussion outlines the use of the service with JBoss 3.2.X, Hibernate 2.1 and XDoclet.

Steps to deploy a Hibernate 1.X or 2.0 service in JBoss

1. Prepare your JDBC DataSource for use with Hibernate.

Please refer to JBoss docs, or the examples included in the JBoss distribution.

2. Copy the necessary jars to ${JBOSS_HOME}/server/default/lib.

The following jars are required (maybe redundant?), which can be found in ${HIBERNATE_HOME}/lib:

  • cglib.jar
  • commons-collections.jar
  • commons-logging.jar
  • commons-lang.jar
  • jcs.jar
  • odmg.jar
  • and of course, hiberna

Due to some mysterious ClassLoader problems in JBoss, these jars have to be copied to ${JBOSS_HOME}/server/default/lib. And in addition, you may need to use the latest versions of the commons-*.jar if JBoss failed to start up after copying (the commons-*.jar in Hibernate's distribution seems to cause conflict with JBoss itself... maybe it means not all the commons-*.jar are necessary? :\).

3. Prepare the directory structure of the service archive.

The Hibernate service will be deployed as a service archive (SAR), which will include all the entity objects, mapping XML files, and the JBoss service XML file itself.

Prepare a directory structure like this:

org/mytest/objects/MasterAccount.class
org/mytest/objects/SubAccount.class
org/mytest/objects/Password.class
mappings/MasterAccount.hbm.xml
mappings/SubAccount.hbm.xml
mappings/Password.hbm.xml
META-INF/

4. Prepare the service XML file.

Fire up your favorite text editor and type in the Hibernate service MBean configuration, like the one below:

<server>
<mbean code="cirrus.hibernate.jmx.HibernateService" name="jboss.jca:service=HibernateFactory,
name=HibernateFactory">
<depends>jboss.jca:service=RARDeployer</depends>
<!-- Make it deploy ONLY after D.hbm.xml,  XXX SOMETHING IS MISSING HERE, PLEASE FIX !! XXX
mappings/SubAccount.hbm.xml,
mappings/Password.hbm.xml</attribute>
<attribute name="JndiName">java:/hibernate/HibernateFactory</attribute>
<attribute name="Datasource">java:/jdbc/DataSource</attribute>
<attribute name="Dialect">cirrus.hibernate.sql.MySQLDialect</attribute>
<attribute name="TransactionStrategy">cirrus.hibernate.transaction.JTATransactionFactory</attribute>
<attribute name="TransactionManagerLookupStrategy">
cirrus.hibernate.transaction.JBossTransactionManagerLookup
</attribute>
<attribute name="UseOuterJoin">false</attribute>
<attribute name="ShowSql">false</attribute>
<attribute name="UserTransactionName">java:/UserTransaction</attribute>
</mbean>
</server>

The following classpaths will work with hibernate 2.x

<server>
<mbean code="net.sf.hibernate.jmx.HibernateService" name="jboss.jca:service=HibernateFactory,
name=HibernateFactory">
<depends>jboss.jca:service=RARDeployer</depends>
<depends>jboss.jca:service=LocalTxCM,name=MySqlDS</depends>
<!-- Make it deploy ONLY after DataSource had been started -->
<attribute name="MapResources">mappings/Attribute.hbm.xml</attribute>
<attribute name="JndiName">java:/hibernate/HibernateFactory</attribute>
<attribute name="Datasource">java:/MySqlDS</attribute>
<attribute name="Dialect">net.sf.hibernate.dialect.MySQLDialect</attribute>
<attribute name="TransactionStrategy">net.sf.hibernate.transaction.JTATransactionFactory</attribute>
<attribute name="TransactionManagerLookupStrategy">net.sf.hibernate.transaction.JBossTransactionManagerLookup</attribute>
<attribute name="UseOuterJoin">false</attribute>
<attribute name="ShowSql">false</attribute>
<attribute name="UserTransactionName">UserTransaction</attribute>
</mbean>
</server>

Of course, you will want to change the attributes above.

Save this file as jboss-service.xml and put it under META-INF of your directory structure.

5. Pack the directory up as a JAR with .sar as extension.

Issue a jar command to jar the above contents to a service archive, which ends with .sar. It is not required to use sar as its extension, just for some sort of conformance... :)

You may also want to do this job with an Ant target.

6. Copy the archive to ${JBOSS_HOME}/server/default/deploy.

You will then see the Hibernate service initialized. You may need to check with your mappings and/or jboss-service.xml in case any exception is thrown.

Using the JBoss MBean with Hibernate 2.1, JBoss 3.2.X and XDoclet

1. Prepare your JDBC DataSource for use with Hibernate.

Please refer to JBoss docs, or the examples included in the JBoss distribution.

2. Set up for XDoclet

See the excellent tutorial http://www.hibernate.org/72.html

The only differences are:

Use XDoclet 1.2beta4. Then you don't have to do "Calling XDoclet from your Ant build script" Step 4 because beta4 has been fixed for Hibernate 2.

Your hibernatedoclet Ant task should look as follows:

<!-- =================================================================== -->
<!-- generates the hibernate HBM.XML files and SAR descriptor -->
<!-- =================================================================== -->

<target name="generate-Hibernate"
description="Generates Hibernate class descriptor files."
depends="compile">

<!-- copy additional resources for the Hibernate XDoclet task to the mergedir -->

<copy todir="${build.resources}/sar/hibernate">
<fileset dir="${src.dir}">
<include name="**/hibernate/hibernate-properties-*.xml"/>
</fileset>
<fileset dir="${resources}/sar/hibernate">
<include name="jboss-service-custom.xdt"/>
</fileset>
</copy>

<!-- Execute the hibernatedoclet task -->
<hibernatedoclet
destdir="${build.resources}/sar/hibernate"
excludedtags="@version,@author,@todo,@see,@desc"
addedtags="@xdoclet-generated at ${TODAY}@copyright yourCompany,@author yourCompany,@version ${version}"
force="${xdoclet.force}"
mergedir="${build.resources}/sar/hibernate"
verbose="false">

<fileset dir="${src.dir}">
<include name="**/hibernate/*.java"/>
</fileset>

<hibernate version="2.0"/>

<jbossservice
destdir="${build.resources}/sar/hibernate"
serviceName="Hibernate"
jndiName="${hibernate.jndi.name}"
dataSource="${hibernate.datasource.name}"
dialect="${hibernate.dialect}"
useOuterJoin="true"
transactionManagerStrategy="net.sf.hibernate.transaction.JBossTransactionManagerLookup"
transactionStrategy="net.sf.hibernate.transaction.JTATransactionFactory"
userTransactionName="UserTransaction"
/>

</hibernatedoclet>
</target>

Running this target gets you all the hbm.xml s and a jboss-service.xml in the destdir, as follows:

jboss-service.xml
com/yourcompany/package1/YourClass1.hbm.xml
com/yourcompany/package1/YourClass2.hbm.xml
com/yourcompany/package1/YourClass3.hbm.xml
com/yourcompany/package1/subpackage2/YourClass4.hbm.xml
...

The jboss-service.xml looks like:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE server>

<!-- Generated file - Do not edit! -->

<server>
<mbean code="net.sf.hibernate.jmx.HibernateService" name="jboss.jca:service=Hibernate">
<depends>jboss.jca:service=RARDeployer</depends>
<attribute name="MapResources">com/yourcompany/package1/YourClass1.hbm.xml,
com/yourcompany/package1/YourClass2.hbm.xml,
com/yourcompany/package1/YourClass3.hbm.xml,
com/yourcompany/package1/subpackage1/YourClass4.hbm.xml
</attribute>
<attribute name="JndiName">java:/HibernateFactory</attribute>
<attribute name="Datasource">java:/myDS</attribute>
<attribute name="Dialect">net.sf.hibernate.dialect.PostgreSQLDialect</attribute>
<attribute name="UseOuterJoin">true</attribute>
<attribute name="ShowSql">false</attribute>
<attribute name="UserTransactionName">UserTransaction</attribute>
<attribute name="TransactionStrategy">net.sf.hibernate.transaction.JTATransactionFactory</attribute>
<attribute name="TransactionManagerLookupStrategy">net.sf.hibernate.transaction.JBossTransactionManagerLookup</attribute>
</mbean>

</server>

3. Package the Hibernate SAR

Again, an Ant task:

<!-- =================================================================== -->
<!-- Hibernate SAR build -->
<!-- =================================================================== -->

<target depends="generate-Hibernate" name="hibernate-sar">

<jar destfile="${build.lib}/hibernateStartup.sar">

<!-- Get the generated hbm.xml files -->
<fileset dir="${build.resources}/sar/hibernate">
<include name="**/*.hbm.xml"/>
</fileset>

<!--
<fileset dir="${lib.dir}">
<include name="cglib2.jar"/>
<include name="commons-collections.jar"/>
<include name="commons-logging.jar"/>
<include name="dom4j.jar"/>
<include name="hibernate2.jar"/>
<include name="odmg.jar"/>
<include name="ehcache.jar"/>
</fileset>
-->
<metainf dir="${build.resources}/sar/hibernate">
<include name="jboss-service.xml"/>
</metainf>
</jar>

<antcall target="hibernate-schemaexport" />

</target>

A couple of things to note:

  • I do not have my Hibernate Java class files in the SAR. In my case, the class files are used by the rest of my code including a WAR, so I have them in a separate jar that is in my EAR classpath. In my experience with JBoss, code in a WAR cannot find classes in a SAR.
  • See the next section for an explanation of why the fileset with the jars is commented out.

4. Hibernate Support jars and Final packaging

As of Hibernate 2.1 rc1, this is the set of jars from the Hibernate distribution that you need:

hibernate2.jar
cglib2.jar
commons-collections.jar
commons-logging.jar
dom4j.jar
odmg.jar
ehcache.jar

All other jars that Hibernate needs are supplied by the base JBoss default deployment.

As of 2.1 rc1, ehcache is the required and the only caching scheme you can use. The final release of 2.1 will allow you to change the caching scheme via:

<attribute name="CacheProvider">net.sf.ehcache.hibernate.Provider</attribute>

in the jboss-service.xml. See below for the implications for using XDoclet.

Each caching scheme requires a different set of supporting jars. Check out lib/libs-readme.txt in the Hibernate distribution about the requirements of the different schemes.

In the build of the SAR above, the fileset tag with the jars is commented out because I am still experimenting with the packaging. Currently, those jars go in my EAR and are referred to in my EAR application.xml (see below).

If you want to deploy the Hibernate SAR on its own outside of an EAR, including the above Hibernate related JARs in the SAR should work. Dropping this SAR into the server/default/deploy directory does a hot deploy.

In an EAR, I have:

hibernateStartup.sar (as built above)
myHibernateClasses.jar
hibernate2.jar
cglib2.jar
commons-collections.jar
commons-logging.jar
dom4j.jar
odmg.jar
ehcache.jar
meta-inf/application.xml
meta-inf/jboss-app.xml

My application.xml looks like:

<application>
<display-name>Company server</display-name>
<description>Company server</description>

<!-- uses session beans to get to Hibernate POJOs -->

<module>
<web>
<web-uri>CompanyUI.war</web-uri>
<context-root>/company</context-root>
</web>
</module>

<!-- Just session beans accessing hibernate -->

<module>
<ejb>companyEJB.jar</ejb>
</module>

<module>
<java>myHibernateClasses.jar</java>
</module>

<module>
<java>hibernate2.jar</java>
</module>

<module>
<java>cglib2.jar</java>
</module>

<module>
<java>commons-logging.jar</java>
</module>

<module>
<java>commons-collections.jar</java>
</module>


<module>
<java>dom4j.jar</java>
</module>

<module>
<java>odmg.jar</java>
</module>

<module>
<java>ehcache.jar</java>
</module>

</application>

My jboss-app.xml looks like:

<?xml version="1.0"?>

<jboss-app>
<loader-repository>company:loader=company.ear</loader-repository>

<module>
<service>hibernateStartup.sar</service>
</module>

</jboss-app>

5. Additional attributes for the SAR jboss-service.xml

  • MapResources
  • JndiName
  • UserName
  • Password
  • Datasource
  • Dialect
  • UseOuterJoin
  • ShowSql
  • UserTransactionName
  • TransactionStrategy
  • TransactionManagerLookupStrategy

UserTransactionName, TransactionStrategy and TransactionManagerLookupStrategy appear to be required under JBoss if you are using Hibernate transactions.

Based on looking at the code coming out for 2.1 final (but not 2.1 rc1, which still has only the original set of attributes from Hibernate 2), the following new attributes can appear in the jboss-service.xml:

  • MaxFetchDepth
  • JdbcFetchSize
  • CacheProvider
  • UseQueryCache
  • QuerySubstitutions
  • DefaultSchema

See the documentation elsewhere about hibernate.properties and hibernate.cfg.xml for details.

6. Generating a complete jboss-service.xml from XDoclet for Hibernate 2.1

If you check back in the section in the hibernatedoclet Ant task, you will see that the jbossservice tag has a limited set of attributes. With Hibernate 2.1, the set of attributes that can be given in the jboss-service.xml for the MBean is expanded, and there will be no out of the box method for setting them via the hibernatedoclet task in XDoclet 1.2beta4.

All is not lost! You can include a merge point for XDoclet, which is a file that is included as is by XDoclet into the jboss-service.xml.

In the mergedir directory specified in the hibernatedoclet task, put a file named jboss-service-custom.xdt. This should contain the text you want to include into the jboss-service.xml that you can't with hibernatedoclet, ala:

<depends>jboss.jca:service=LocalTxCM,name=MySqlDS</depends>
<attribute name="CacheProvider">net.sf.ehcache.hibernate.Provider</attribute>

There is a bug in XDoclet 1.2beta3 and 1.2beta4, which means the contents of jboss-service-custom.xdt are included in the wrong place. See the comments below for the fix.

Commentary

Question: What are the advantages to this as opposed to getting a pooled connection and relying on JBoss for transaction handling?

Using Object-Relation-Mapping make application layer seperated from the Database access layer. Compare with the tradition Object-Storage in EJB, it allow better control on the data in the relational database. Also connection pooling could be done inside Hibernate.

Question: Why will I want to use this method to integrate Hibernate service into JBoss?

Of course, you can use the traditional "hibernate.cfg.xml" or "hibernate.properties" method which will also work seamlessly in JBoss. However, using the JMX integration method, the Hibernate service is deployed as a JMX MBean, which you can modify its properties through the JMX console.

That is, you can change the JDBC data source the service uses, include/ exclude mapping files included in the .sar, enable/ disable SQL verbose to the console, etc. while the server is running.

This was (supposed to be) why the Hibernate JBoss MBean was written.

Not using the MBean

If you are going to try to get JBoss working without using the service, the libraries listed above are a good place to start. The classloader errors that JBoss gives are not necessarily for the actual class that is missing, JBoss merely reports the top-level class it was trying to load if there is a failure anywhere inside the transitive closure of all the libraries Hibernate needs. It can be very confusing and take a while to debug. So save yourself the hassle of trying to figure out what the minimum set of libraries that are needed from the distro -- this is the list.

The other thing to consider in regards to the JBoss classloader is that other strange errors can be introduced if you have utility code (static Session recovery methods, for instance) that is shared by both the web and EJB tiers of your app. If the code gets too complex, you can find yourself in the weeds trying to figure out why your webapp is suddenly throwing NoClassDefFoundError in a very strange location of the application that you had not touched for many days or weeks. This is often a sign of a new dependency within the common code that is causing the object graph to get much much larger (think about adding one person to your friendster.com account ;) and suddenly everything stops. So by using the service, you can isolate the dependencies better between the tiers and save yourself a visit from Mr. Murphy two days after you forgot all the classloader details that you had studied a month ago.

So, basically, use the MBean!

Other guides

JBossHibernate JBoss WIKI page (JBoss 4.0 and Hibernate)

http://www.jboss.org/wiki/Wiki.jsp?page=JBossHibernate

JBoss 4.0 includes Hibernate 2.1.5 and ready to use Hibernate.

JBossHibernate-old JBoss WIKI page (JBoss 3.x.x and Hibernate)

http://www.jboss.org/wiki/Wiki.jsp?page=JBossHibernate-old

A bit obsolete guide.


  NEW COMMENT

Mr. Murphy
29 Oct 2003, 10:52
csak
I'm a newbie at J2EE technoilogies, so this might not be relevant.
For my installation of JBoss (3.2.1) the UserTransaction service's JNDI
name is not "java:/UserTransaction" but "UserTransaction". This can be
verified on the JMX console.
Thus the correct syntax of a hibernate2 service would be:

<server>
<mbean code="net.sf.hibernate.jmx.HibernateService"
name="jboss.jca:service=HibernateFactory,
                            name=HibernateFactory">
    <depends>jboss.jca:service=RARDeployer</depends>
    <depends>jboss.jca:service=LocalTxCM,name=MySqlDS</depends>
    <!-- Make it deploy ONLY after DataSource had been started -->
    <attribute name="MapResources">mappings/Attribute.hbm.xml</attribute>
    <attribute name="JndiName">java:/hibernate/HibernateFactory</attribute>
    <attribute name="Datasource">java:/MySqlDS</attribute>
    <attribute
name="Dialect">net.sf.hibernate.dialect.MySQLDialect</attribute>
    <attribute
name="TransactionStrategy">net.sf.hibernate.transaction.JTATransactionFactory</attribute>
    <attribute
name="TransactionManagerLookupStrategy">net.sf.hibernate.transaction.JBossTransactionManagerLookup</attribute>
    <attribute name="UseOuterJoin">false</attribute>
    <attribute name="ShowSql">false</attribute>
    <attribute name="UserTransactionName">UserTransaction</attribute>
</mbean>
</server>

This might save a couple of hours, for those who run into the same problem.
 
Using Hibernate with JBoss / initilization order
03 Nov 2003, 17:48
jschulz
Hmm. This approach worked relativly good for me, I just avoided 
copying the hibernate libs into the server's lib directories by 
packing them into the '.sar'. 

However, when I restart the JBoss server, the hibernate service will 
not initlialize, because the the datasource I've configured isn't 
loaded at the point the '.sar' is loaded.
After this happend, the only way to get the hibernate service running 
again, is to re-deploy it. :-/

Is there a way to configure my hibernate service in a way that it only 
initializes AFTER the datasource is ready?

thanks for any comment,

J
 
Re: Using Hibernate with JBoss / initilization order
18 Nov 2003, 17:24
csak
On 03 Nov 2003 17:48, jschulz wrote:

>Hmm. This approach worked relativly good for me, I just avoided
>copying the hibernate libs into the server's lib directories by
>packing them into the '.sar'.

>However, when I restart the JBoss server, the hibernate service will
>not initlialize, because the the datasource I've configured isn't
>loaded at the point the '.sar' is loaded.
>After this happend, the only way to get the hibernate service running
>again, is to re-deploy it. :-/

>Is there a way to configure my hibernate service in a way that it only
>initializes AFTER the datasource is ready?

This part:

"...
    <depends>jboss.jca:service=RARDeployer</depends>
    <depends>jboss.jca:service=LocalTxCM,name=MySqlDS</depends>
..."

of the service description ensures that the sar is loaded after the
datasource is ready. You've probably omitted this part from the
configuration.
It works for me this way.
 
XDoclet Merge Dir
09 Dec 2003, 19:43
rollatwork
I've seen this talked about on the XDoclet mailing list, however, 
there was no answer posted.  Since this article discusses it, I'll put 
my question here and hopefully someone can respond:

The jboss-service-custom.xdt when merged puts the new elements outside 
the mbean for which I would like for it to be child nodes of.  Is 
there anyway to accomplish this.

My xdt looks like this:

<depends>jboss.jca:service=LocalTxCM,name=MySqlDS</depends>

I'm using XDoclet 1.2b4 with Maven RC1.

Regards,
Roll
 
Re: XDoclet Merge Dir
11 Dec 2003, 14:13
sgwood
On 09 Dec 2003 19:43, rollatwork wrote:

>I've seen this talked about on the XDoclet mailing list, however,
>there was no answer posted.  Since this article discusses it, I'll put
>my question here and hopefully someone can respond:

>The jboss-service-custom.xdt when merged puts the new elements outside
>the mbean for which I would like for it to be child nodes of.  Is
>there anyway to accomplish this.

>My xdt looks like this:

><depends>jboss.jca:service=LocalTxCM,name=MySqlDS</depends>

>I'm using XDoclet 1.2b4 with Maven RC1.

>Regards,
>Roll

In XDoclet 1.2b4, there is a bug in the jboss-service.xdt (XDoclet
template) which does this. I'll do a fix, and post it here and in the
Hibernate and XDoclet forums.

Ask this sort of question in the Hibernate forums - I doubt people are
looking at this page to answer you.

Cheers,


Sherman
 
Re: XDoclet Merge Dir
11 Dec 2003, 15:23
sgwood
On 11 Dec 2003 14:13, sgwood wrote:

>On 09 Dec 2003 19:43, rollatwork wrote:

>>I've seen this talked about on the XDoclet mailing list, however,
>>there was no answer posted.  Since this article discusses it, I'll put
>>my question here and hopefully someone can respond:

>>The jboss-service-custom.xdt when merged puts the new elements outside
>>the mbean for which I would like for it to be child nodes of.  Is
>>there anyway to accomplish this.

>>My xdt looks like this:

>><depends>jboss.jca:service=LocalTxCM,name=MySqlDS</depends>

>>I'm using XDoclet 1.2b4 with Maven RC1.

>>Regards,
>>Roll

>In XDoclet 1.2b4, there is a bug in the jboss-service.xdt (XDoclet
>template) which does this. I'll do a fix, and post it here and in the
>Hibernate and XDoclet forums.

>Ask this sort of question in the Hibernate forums - I doubt people are
>looking at this page to answer you.

>Cheers,


>Sherman

Check out issues on XDoclet JIRA:

For the fix to your problem:

http://opensource.atlassian.com/projects/xdoclet/secure/ViewIssue.jspa?key=XDT-556


Hibernate 2.1 JBoss XDoclet:

http://opensource.atlassian.com/projects/xdoclet/secure/ViewIssue.jspa?key=XDT-734
 
Alternative JBoss configuration
16 Dec 2003, 19:33
jarkko
Hello, 
 Is it possible to configure JBoss/Hibernate so that hibernate can
lookup the mapping files from another jar (e.g. myHibernateClasses.jar)

Example:
myEar.ear
 hibernateStartup.sar
   META-INF/
            jboss-service.xml

 myHibernateClasses.jar
   eg/
      package/
             MyClass.class
             MyClass.hbm.xml


This configuration would allow to deploy the EAR in exploded format.
 
jboss-service-custom.xml?
16 Dec 2003, 20:28
craigduncan
In the example hibernatedoclet task near the top of this post you are
copying some files to the ${build.resources}/sar/hibernate directory.

What are the hibernate-properties-*.xml files for?  It looks like most
of the hibernate properties are set in the jboss-service.xml, so I was
wondering what these files are for?

Also, your example copies a jboss-service-custom.xml file.  Should that
be  a jboss-service-custom.xdt file?  I read the other posts about the
problem with the xdt provided with the 1.2.b4 release of xdoclet, but I
am still a little confused.  

Thanks for this great post on JBoss and Hibernate.  I am currently
trying to switch our product over to java.  We already have an existing
database so I am going the route of middlegen, hbm2java,
hibernatedoclet, sar to try to get it all working.
 
Re: jboss-service-custom.xml?
16 Dec 2003, 20:59
sgwood
On 16 Dec 2003 20:28, craigduncan wrote:

>In the example hibernatedoclet task near the top of this post you are
>copying some files to the ${build.resources}/sar/hibernate directory.

>What are the hibernate-properties-*.xml files for?  It looks like most
>of the hibernate properties are set in the jboss-service.xml, so I was
>wondering what these files are for?

There are some parts of a Hibernate hbm.xml file that cannot be
generated from XDoclet hibernatedoclet @tags in your source with XDoclet
1.2.b4. In my case, I needed to include:

<!-- Included by Hibernate XDoclet task into the hbm.xml -->

	<any name="referredToObject" id-type="long">
    	<column name="objectClass" length="128" not-null="true"/>
	    <column name="objectId" not-null="true"/>
	</any>

in one of my class mappings. So in my source tree I have:

com/galenworks/hibernate/DocumentCrossReference.java
com/galenworks/hibernate/hibernate-properties-DocumentCrossReference.xml

The hibernate-properties-DocumentCrossReference.xml contains the needed
snippet. Doing the copy of this file into
${build.resources}/sar/hibernate/com/galenworks/hibernate and then
running hibernatedoclet includes the snippet at the end of the class
tag, ie.

<!DOCTYPE hibernate-mapping PUBLIC
    "-//Hibernate/Hibernate Mapping DTD 2.0//EN" 
    "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">

<hibernate-mapping>
    <class
        name="com.galenworks.procedurelink.hibernate.DocumentCrossReference"
        table="DocumentXref"
        dynamic-update="false"
        dynamic-insert="false"
    >

        <id
            name="documentXrefId"
            column="documentXrefId"
            type="long"
        >
            <generator class="sequence">
                <param name="sequence">documentXrefSeq</param>
            </generator>
        </id>

        <property
            name="documentXPath"
            type="string"
            update="true"
            insert="true"
            column="documentXPath"
            length="255"
            not-null="true"
        />


[snip]


<!-- Included by Hibernate XDoclet task into the hbm.xml -->

	<any name="referredToObject" id-type="long">
    	<column name="objectClass" length="128" not-null="true"/>
	    <column name="objectId" not-null="true"/>
	</any>

    </class>

</hibernate-mapping>


>Also, your example copies a jboss-service-custom.xml file.  Should that
>be  a jboss-service-custom.xdt file?  I read the other posts about the
>problem with the xdt provided with the 1.2.b4 release of xdoclet, but I
>am still a little confused.

You are right - it should be "jboss-service-custom.xdt". I'll update the
wiki page.
 
Re: Alternative JBoss configuration
16 Dec 2003, 21:08
sgwood
On 16 Dec 2003 19:33, jarkko wrote:

>Hello,
> Is it possible to configure JBoss/Hibernate so that hibernate can
>lookup the mapping files from another jar (e.g. myHibernateClasses.jar)

>Example:
>myEar.ear
> hibernateStartup.sar
>   META-INF/
>            jboss-service.xml

> myHibernateClasses.jar
>   eg/
>      package/
>             MyClass.class
>             MyClass.hbm.xml


>This configuration would allow to deploy the EAR in exploded format.

I think the closest you are going to get is:

myEar.ear
 hibernateStartup.sar
   META-INF/
            jboss-service.xml
   eg/
      package/
             MyClass.hbm.xml

 myHibernateClasses.jar
   eg/
      package/
             MyClass.class

The Jboss Hibernate MBean needs to be able to find the hbm.xml files
specified in the MapResources attribute in the MBean descriptor on the
classpath of the SAR.
 
Some help needed
18 Dec 2003, 00:12
craigduncan
I posted to the hibernate forum with a question I was hoping you could
take a look at.

http://forum.hibernate.org/viewtopic.php?p=2182874#2182874

Thanks

Craig
 
Container managed JTA Session Service
20 Dec 2003, 14:20
ivelin
As suggested in an earlier post, I would like to propose the following
convenience service for the JBoss integration:

http://cocoonhive.org/jboss/jtasession.zip 

The initial proposal can be found here:
http://forum.hibernate.org/viewtopic.php?t=925357

An independent but related thread:
http://forum.hibernate.org/viewtopic.php?t=926369

Here is the rationale behind this service:
	This service is applicable when the application uses JTA transactions.
	Either directly, via transaction servlet filter, or EJB.
	http://java.sun.com/products/jta/javadocs-1.0.1/javax/transaction/UserTransaction.html
	http://java.sun.com/blueprints/code/adventure/1.0/src/com/sun/j2ee/blueprints/waf/controller/web/TransactionFilter.java.html
	http://java.sun.com/products/ejb/2.0.html

	The JTAHibernateFactory maintains one HibernateSession per JTA
transaction. 
	It obtains a new session when requested for the first time and binds it
to the underlying
	UserTransaction. If there is no JTA transaction at the time that the
session is requested,
	the factory will throw an exception.
    
	Subsequent requests for a Hibernate session from this factory will
return the existing one.
	Once bound to the UserTransaction, the factory registers a Transaction
Synchronization,
	which ensures that the session is properly closed before the
transaction ends.

	The relationship between each HibernateSession obtain through this factory 
	and the underlying UserTransactions is one to one.
	There is at most one HibernateSession for each UserTransaction and 
	each HibernateSession is related to exactly one UserTransaction.
	
	This eliminates the thread safety problem and allows for a efficient
use of the session cache.
	
	Usage example:
  	public void saveAccount( Account account ) throws HibernateException
 	{
 		Session s = DBHelper.getSession();
 		s.saveOrUpdate(account);
 		// no need to close the session manually
 	}
 	
 	where DBHelper.getHibernateSession() is:
 	
	public static Session getHibernateSession()
	{
		try
		{
			InitialContext ctx = new InitialContext();
			JTASessionFactory jtaf =
(JTASessionFactory)ctx.lookup("java:/hibernate/JTASessionFactory");
			return jtaf.getSession();
		}
		catch(NamingException ne)
		{
			throw new RuntimeException("Failed obtaining hibernate JTA session,
because of: " + ne.getMessage(), ne);
		}
	}
 
Missing the excellent xdoclet tutorial
06 Jan 2004, 16:36
olve
The tutorial pointed too by 
http://www.hibernate.org/72.html

is missing. Does anyone know where it is now?

Thx...
Olve
 
Re: Missing the excellent xdoclet tutorial
08 Jan 2004, 06:42
sgwood
On 06 Jan 2004 16:36, olve wrote:

>The tutorial pointed too by
>http://www.hibernate.org/72.html

>is missing. Does anyone know where it is now?

>Thx...
>Olve

Someone deleted it. It is back now.

Sherman
 
hot deploy in jboss.... (HIBERNATE, JAAS)
10 Feb 2004, 21:44
nobodyhere
I work in an environment where we have many different applications 
deployed to jboss using hibernate as persistence engine. We add a new 
application every couple of weeks. 
It would be nice to be able to deploy the application without having 
to restart JBoss. 
(I am creating an EAR file per application with it's own loader in 
jboss... 
My config: j2sdk1.4.2_02, hibernate-2.1.1, jboss-3.2.2) 

But there is a problem with JAAS... every application must validate 
security throught JAAS using a Database validation 
(using custom login of jboss org.jboss.security.ClientLoginModule and 
org.jboss.security.auth.spi.DatabaseServerLoginModule) 

Is it possible to 'hot deploy' a JAAS login module or configuration 
for my new published apps? 
Do I have to create a SAR or something inside a specific path in the 
EAR file? 

I am not a JAAS guru and I would be curious to know if this is not 
possible or if it has just not been done yet. 

Please help 
thanks.
 
Re: Container managed JTA Session Service
16 Feb 2004, 00:06
Horst Dehmer
Hi, Ivelin!

First of all, thanx for your contribution. 

I downloaded/build/deployed/installed jtasession.zip. Everything's 
fine. I even get a JTA hibernate session from the factory which works 
well. 
Now the problem: Before the end of the transaction/SLSB call, JBoss 
[CachedConnectionManager] closes the session's connection before 
JTASessionSynchronization gets the chance to do so...

DEBUG [JTASessionFactory] implementing transaction class: 
org.jboss.tm.TransactionImpl
DEBUG [JTASessionFactory] opening a new Hibernate session for 
transaction: TransactionImpl:XidImpl [FormatId=257, 
GlobalId=MEDUSA//3, BranchQual=]
DEBUG [JTASessionSynchronization] ctor: tx (TransactionImpl:XidImpl 
[FormatId=257, GlobalId=MEDUSA//3, BranchQual=]), sessionMap 
({TransactionImpl:XidImpl [FormatId=257, G
lobalId=MEDUSA//3, BranchQual=]
=net.sf.hibernate.impl.SessionImpl@16721bd})
INFO  [CachedConnectionManager] Successfully closed a connection for 
you.  Please close them yourself: 
org.jboss.resource.adapter.jdbc.WrappedConnection@14fcd9a
java.lang.Exception: Stack Trace
        at 
org.jboss.resource.connectionmanager.CachedConnectionManager.closeAll
(CachedConnectionManager.java:376)
        at 
org.jboss.resource.connectionmanager.CachedConnectionManager.popMetaAwa
reObject(CachedConnectionManager.java:199)
        at 
org.jboss.resource.connectionmanager.CachedConnectionInterceptor.invoke
(CachedConnectionInterceptor.java:190)
        at 
org.jboss.ejb.plugins.StatelessSessionInstanceInterceptor.invoke
(StatelessSessionInstanceInterceptor.java:72)
        ....
DEBUG [JTASessionSynchronization] called: beforeCompletion()
DEBUG [JTASessionSynchronization] called: afterCompletion(txStatus (3))

I tried with JBoss 3.2.0/3.2.2RC1 and Hibernate 2.1.1/2.1.2.

Here my simple code:

String jndiName = "java:/hibernate/JTASessionFactory";
InitialContext ctx = new InitialContext();
JTASessionFactory jtaf = (JTASessionFactory)ctx.lookup(jndiName);
Session session = jtaf.getSession();
ProductData data = (ProductData)session.load(ProductData.class, new 
Integer(id));

Have I missed a point. Probably configuration problems. I deployed my 
hib
分享到:
评论

相关推荐

    hibernate+jboss-logging

    标题“hibernate+jboss-logging”涉及到两个关键领域:Hibernate和JBoss Logging,而描述中提到了三个具体的jar文件,它们是实现这些技术的重要组件。让我们深入了解一下这些技术和库。 **Hibernate** 是一个非常...

    eclipse安装hibernate的jboss tools插件

    标题中的“eclipse安装hibernate的jboss tools插件”指的是在Eclipse集成开发环境中安装用于支持Hibernate的JBoss Tools扩展。这个过程是开发者为了提高在Eclipse中使用Hibernate框架进行开发的便利性,通过添加插件...

    Hibernate Jboss cache

    ### Hibernate与Jboss Cache结合实现二级缓存机制 #### 概览 在现代的企业级应用开发中,提高数据访问效率是提升系统性能的关键之一。Hibernate作为一款流行的Java持久层框架,通过提供对象关系映射(ORM)技术...

    Hibernate所需jar包

    hibernate-c3p0-4.3.5.Final hibernate-commons-annotations-4.0.4.Final hibernate-core-4.3.5.Final hibernate-jpa-2.1-api-1.0.0.Final jandex-1.1.0.Final javassist-3.18.1-GA jboss-logging-3.1.3.GA jboss-...

    jbosstools-hibernate:JBoss工具

    Hibernate Eclipse Tools是一部分,可以从中单独或与完整的JBoss Tools发行版一起。 获取代码 开始编写代码的最简单方法是 ,然后克隆fork: $ git clone git@github.com:&lt;you&gt;/jbosstools-hibernate.git $ cd ...

    使用Hibernate tools,生成带中文注释的类和hbm文件

    下载并安装hibernate tools插件,下载地址:http://download.jboss.org/jbosstools/static/neon/stable/updates/core/jbosstools-4.4.1.Final-updatesite-core.zip 安装过程参考...

    Business Process Management with JBoss jBPM.pdf

    《Business Process Management with JBoss jBPM》是一本专为业务分析师撰写的实用指南,旨在帮助读者掌握如何利用JBoss jBPM这一强大的开源框架来设计、实现和优化业务流程。本书由Matt Cumberlidge撰写,并于2007...

    getting started with jboss

    ### JBoss入门与J2EE应用实践 #### 概述 本书主要介绍如何在JBoss 3.2.x系列上使用J2EE 1.3技术。撰写时最新的版本为3.2.3,建议使用该版本或更高版本进行学习。书中首先介绍了JBoss的下载与安装,并演示了如何...

    Jboss下hibernate整合EJB

    本文将详细讲解如何在JBoss应用服务器上整合Hibernate和EJB。 **一、EJB简介** EJB是Java EE平台的一部分,它提供了一种标准的方式来创建分布式、事务处理、安全和可管理的企业级服务。EJB类型主要包括会话Bean...

    Getting Started with JBoss Developer Studio.mht

    Getting Started with JBoss Developer Studio.mht,入门,网页格式

    Business Process Management with JBoss jBPM

    《Business Process Management with JBoss jBPM》一书由Matt Cumberlidge撰写,旨在为业务分析师提供实用指南,教授如何利用JBoss jBPM平台构建高效的业务流程。 #### 二、业务流程管理(BPM)概述 业务流程管理...

    Hibernate 2nd-level cache: JBoss Caching 配置与注意事项

    本文将深入探讨如何配置Hibernate使用JBoss Caching作为二级缓存,并提醒你在实现过程中需要注意的一些关键点。 **一、Hibernate 二级缓存概念** 在Hibernate中,一级缓存是Session级别的,每个Session都有一个...

    Jboss6.0.0 M4配置jndi和hibernate

    **JBoss 6.0.0 M4 配置 JNDI 和 Hibernate 深度解析** JBoss 是一个开源的应用服务器,版本6.0.0 M4是它的一个里程碑版本,提供了对Java EE 5规范的支持。在这个版本中,配置JNDI(Java Naming and Directory ...

    jbosstools-4.0.1.Final

    jbosstools-4.0.1.Final JBoss Tools 原名为JBoss IDE,现在统一改名为 JBossTools,JBoss Tools包含了JSF,Hibernate,JBossSeam,jBPM等一系列的开发工具。

    jboss-logging-

    jboss-logging

    JbossTools for Eclipse4.5.2

    首先,JBoss Tools的核心特性之一是它集成了Hibernate Tools。Hibernate是一款优秀的对象关系映射(ORM)框架,使得Java开发者可以更加便捷地处理数据库操作。通过这个插件,开发者可以在Eclipse环境中进行直观的...

    Getting Started with JBoss 4[1].0 中文版.pdf

    以上是基于《Getting Started with JBoss 4[1].0 中文版.pdf》文档内容总结的关键知识点,旨在帮助读者快速了解 JBoss 4.0.x 的安装配置、服务器管理、核心服务配置、安全性配置等方面的基础知识,并通过具体示例...

    解决eclipse安装Jboss Tools插件后自动提示变慢.pdf

    6. Hibernate与Jboss Tools:Hibernate是一个流行的Java ORM(对象关系映射)框架,而Jboss Tools提供了一系列工具来支持Hibernate和其他JBoss技术的开发。如果项目不使用Hibernate,则与Hibernate相关的工具和插件...

Global site tag (gtag.js) - Google Analytics