-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 19 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: Jboss Setup: How to organize Classes for Development?!
PostPosted: Thu Feb 19, 2004 4:59 am 
Regular
Regular

Joined: Thu Feb 19, 2004 4:48 am
Posts: 62
Hi,

i just started with using hibernate on jboss, using the tutorial(http://www.hibernate.org/66.html) - I managed to deploy the .sar - however, I'm not sure, how to organize the classes:

Right now, i have the persistent classes packaged with the sar: If i don't package them, hibernate complains with classnotfound - and I also saw, that ejb's can't load whats inside a .sar. However, the approach of packaging everything into an .ear (as proposed in the manual) does not look really practical from a development point of view: I'd like to deploy the sar and use it from many different components independently.

Is there another way to package this?! Maybe by having an extra .jar just for the classes and adding it to classpath-entry of the .sar&every other component that needs these classes?!

cheers
stf


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 19, 2004 11:30 am 
Senior
Senior

Joined: Tue Nov 25, 2003 9:35 am
Posts: 194
Location: San Francisco
Have a jar that contains the Hibernate classes separate from the SAR, and have that in server/default/lib. SARs, EARs and EJB jars will be able to find the classes then.


Sherman


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 19, 2004 12:18 pm 
Regular
Regular

Joined: Thu Feb 19, 2004 4:48 am
Posts: 62
Is this really such a good idea?! If i put them on the bootstap classpath, i cannot redeploy them without having to restart the server--- I have curently added the jar with the persisitent classes to the class-path of the manifest-files for all dependent components - this works fine and lets me deploy new components without having to package it all in an .ear.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 19, 2004 12:24 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
There is currently no really good solution I fear. You could try to package the classes in an indepentent jar and reference it both from the Classpath Entry in the manifest files of the sar and the ejb jars.

I currently don't have the persistent classes inside the sar but in a seperate jar. I have them in an ear however, I don't know if it would work without a surrounding ear.

But be patient, we are currently working on a more advanced Hibernate integration for JBoss which will solve many of those issues I hope.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 20, 2004 7:59 am 
Regular
Regular

Joined: Thu Feb 19, 2004 4:48 am
Posts: 62
ok, i tested that one out:

- I deployed the ejb-archive with a Class-Path-Reference to the jar containing the persistent classes

-I deployed the hibernate.sar with a Class-Path-reference to the persistent classes in the Manifest-File, along with the persistent classes

However, when you have deployed your .sar *before* the ejb's(which is the natural way to do it), you get a class-cast exception during deployment. I suspect, that this is due to the class-loader for the sar - does anyone have an idea how to set this up properly?! Or is the only solution left to package everything into an .ear?!


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 20, 2004 11:37 am 
Regular
Regular

Joined: Thu Feb 19, 2004 4:48 am
Posts: 62
looks like i can't get this to work: Even if I package everything in an ear, as it is proposed in the tutorial, i get this strange ClassCastException when Jboss tries to deploy the EJB. The ClassCastException happens independently from referencing hibernate or not - I even get the ClassCastException when i don't have any imports from hibernate at all.

The only annoying [INFO] i get says: Could not build SessionFactory using the MBean classpath - will try again using client classpath: could not instantiate CacheProvider: net.sf.ehcache.hibernate.Provider

although ehcache is present in the server/default/lib/

Anyway, following the tutorial, the hibernate-jars are in two places: Inside the .jar and on the servers classpath. Right now i have them on them in server/default/lib and *not* inside the ear - may this be the cause of the trouble?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 20, 2004 12:16 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
I do not put anything into the server classpath, just everything into the ear.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 20, 2004 1:23 pm 
Regular
Regular

Joined: Thu Feb 19, 2004 4:48 am
Posts: 62
I fixed my deployment and cleaned the classpath - now all jar's are only in the ear. I tracked the ClassCastIssues down to the lookup for the DataSource: Cause of the trouble is the failed lookup for the datasource: Although I deployed a datasource under the name "devbaseDS", the [DataSourceConnectionProvider] says: Could not find datasource: java:/devbaseDS - and the ClassCastException is just a result. The Deployment og the Datasource runs fine:
18:19:43,827 INFO [MainDeployer] Starting deployment of package: file:/data/src/jboss-3.2.3/server/default/deploy/devbase_bee-ds.xml
18:19:43,871 INFO [RARDeployment] Started jboss.jca:service=ManagedConnectionFactory,name=DevbaseDS
18:19:43,872 INFO [JBossManagedConnectionPool] Started jboss.jca:service=ManagedConnectionPool,name=DevbaseDS
18:19:43,895 INFO [DevbaseDS] Bound connection factory for resource adapter for ConnectionManager 'jboss.jca:service=LocalTxCM,name=DevbaseDS to JNDI name 'java:/DevbaseDS'
18:19:43,895 INFO [TxConnectionManager] Started jboss.jca:service=LocalTxCM,name=DevbaseDS

so i don't see any reason, why the DataSourceConnectionProvider can't find the DataSource???!!


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 20, 2004 1:34 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
Probably because you are once using java:/devbaseDS and once java:/DevbaseDS?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 24, 2004 8:18 am 
Regular
Regular

Joined: Thu Feb 19, 2004 4:48 am
Posts: 62
unfortunately no (although it was late on friday and I even had the queer idea, that jboss does not like DataSources that don't start with a capital...) - to make sure, that the DataSource is deployed correctly and can be found, I made up two setups:

- packaged the ejb alone&looking up the datasource from the ejb: This works fine.
- package the same ejb with the hibernate-.sar&looking up the datasource from the ejb: This way, I don't find the datasource(with the resulting class-cast-exception - do i have to package the DataSource inside the ear???!


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 24, 2004 8:23 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
No, surely not. Are you sure the JNDI names are exactly the same in your jboss-service.xml and the -ds.xml? This is case sensitive, too.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 26, 2004 1:20 pm 
Regular
Regular

Joined: Thu Feb 19, 2004 4:48 am
Posts: 62
yes, i'm sure that the names are right - that was the reason, i tested the lookup from the sessionbean - the lookup for java:/devbaseDS from the SessionBean works, if the sessionbean is deployed alone.

I tracked down the error to the line
Code:
ds = (DataSource) NamingHelper.getInitialContext(props).lookup(jndiName); 


in the DatasourceConnectionProvider - and (sorry for not reading the exception at once) - i get a ClassCastException, not a NotBoundException - so he finds the DataSource, but (maybe a class-loader-problem?!?) he is not able to cast it.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 02, 2004 9:52 am 
Regular
Regular

Joined: Thu Feb 19, 2004 4:48 am
Posts: 62
still struggling with this: Splitting the lookup&the casting in two, and adding some info lines to the DataSourceConnectionProvider reveals:

14:32:03,262 INFO [DatasourceConnectionProvider] Object found. Object is a <org.jboss.resource.adapter.jdbc.WrapperDataSource
14:32:03,285 INFO [DatasourceConnectionProvider] Object is an instance of DataSource:false
14:32:03,286 INFO [DatasourceConnectionProvider] Classloader for wrapper:org.jboss.mx.loading.UnifiedClassLoader3@ef2c60{ url=file:/data/src/jboss-3.2.3/server/default/tmp/deploy/tmp35370jboss-service.xml ,addedOrder=2}
14:32:03,286 INFO [DatasourceConnectionProvider] Classloader for DataSourceClassr:org.jboss.mx.loading.UnifiedClassLoader3@73b72{ url=file:/data/src/jboss-3.2.3/server/default/tmp/deploy/tmp35426company.ear ,addedOrder=42}


that the DataSource and the WrapperDataSource were loaded from two different classloaders - I would not have expected that javax.sql.DataSource is loaded by the ClassLoader for the ear - may this be the root of all evil?!


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 02, 2004 11:05 am 
Regular
Regular

Joined: Thu Feb 19, 2004 4:48 am
Posts: 62
Just to extend on this: if i have the lookup and the cast running in the SessionBean, i get:

15:59:38,232 INFO [STDOUT] ProjectSessionBean.ejbCreate()
15:59:38,237 INFO [STDOUT] Object found. Object is a <org.jboss.resource.adapter.jdbc.WrapperDataSource
15:59:38,238 INFO [STDOUT] Object is an instance of DataSource:true
15:59:38,238 INFO [STDOUT] Classloader for wrapper:org.jboss.mx.loading.UnifiedClassLoader3@ef2c60{ url=file:/data/src/jboss-3.2.3/server/default/tmp/deploy/tmp20677jboss-service.xml ,addedOrder=2}
15:59:38,239 INFO [STDOUT] Classloader for DataSource:null


So the difference between the two really seems to be the ClassLoader....


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 03, 2004 9:34 am 
Beginner
Beginner

Joined: Thu Aug 28, 2003 3:09 pm
Posts: 39
Location: Brazil
Hi mugwump.

In fact the problem is the class loader.

Here at my job I have tested the following setups with success:

put hibernate jars in the lib of jboss and put the persistent classes inside a sar inside my ear.

put the hibernate classes inside the .ear, specifying them as modules in the application.xml and puting my persistent classes inside a .sar and put this sar in my .ear

When putting the hibernate jars inside the ear, if you don't put the references in application.xml, it will give the classcast exception.

I hope it helps.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 19 posts ]  Go to page 1, 2  Next

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.