-->
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.  [ 7 posts ] 
Author Message
 Post subject: Using Hibernate with Jboss
PostPosted: Wed Jul 28, 2004 9:04 am 
Newbie

Joined: Fri Dec 05, 2003 11:07 am
Posts: 14
Hello,

I am using Hibernate with JBOSS. The first application I have is called
test.war and the directory structure is follows:

[ jboss\server\all\deploy\test.war ]
|----[WEB-INF]
| |----[classes]
| | |----all classes
| | |----hibernate.cfg.xml
| | |----test.hbm.xml
| |
| |----[lib]
| |----all hibernate jar files
|
|----all jsp files

When I run this application everything works fine.

The problem starts when I deploy another application with similar architechture. When I run the second application it loads the hibernate cofiguration from the first application and load its classes thus giving me exceptions.

How can I make both applications work. Is there a link to a tutorial that can help me out with this. Maybe I have to put the hibernate jar files in
"jboss\server\all\lib" but then where would I put the hibernate.cfg.xml file?

PLEASE HELP !!!

Thanks


Top
 Profile  
 
 Post subject: Additional Info
PostPosted: Wed Jul 28, 2004 9:34 am 
Newbie

Joined: Fri Dec 05, 2003 11:07 am
Posts: 14
In addition this is what my hibernate.cfg.xml files look like
The first app
-----------------
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-2.0.dtd">

<hibernate-configuration>

<session-factory>


<property name="show_sql">true</property>
<property name="use_outer_join">true</property>
<property name="dialect">net.sf.hibernate.dialect.SQLServerDialect</property>

<!-- Mapping files -->
<mapping resource="stdcostupdt.hbm.xml"/>

</session-factory>

</hibernate-configuration>


The second app
--------------------------
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-2.0.dtd">

<hibernate-configuration>

<session-factory>


<property name="show_sql">true</property>
<property name="use_outer_join">true</property>
<property name="dialect">net.sf.hibernate.dialect.DB2Dialect</property>

<!-- Mapping files -->
<mapping resource="Polls.hbm.xml"/>
<mapping resource="Pagerank.hbm.xml"/>

</session-factory>

</hibernate-configuration>


Top
 Profile  
 
 Post subject: Additional Info
PostPosted: Wed Jul 28, 2004 11:27 am 
Newbie

Joined: Fri Dec 05, 2003 11:07 am
Posts: 14
Sorry I read over and figured I needed to provide more info.
In both my applications I am using JDBC to connect to the database.
Here is the code.


SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();
Class.forName(dbDriver);
Connection con = DriverManager.getConnection(dbUrl + ";databaseName=" + dbName,dbUser,dbPass);
Session ses = sessionFactory.openSession(con);
Transaction transaction = ses.beginTransaction();
net.sf.hibernate.Query q = ses.createQuery("from ItemXstcost");
List lst = q.list();
int totalCount = lst.size();
int listnum = 0;
if (totalCount > 0) {
Iterator tempIter = lst.iterator();
.................


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 28, 2004 11:31 am 
Beginner
Beginner

Joined: Fri Mar 26, 2004 8:19 am
Posts: 49
there is a tutorial on the wiki here about how to package hibernate as an MBean for Jboss. I use that method and it works great. Your SessionFactory is available to all apps via JNDI.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 28, 2004 11:36 am 
Beginner
Beginner

Joined: Fri Mar 26, 2004 8:19 am
Posts: 49
http://www.hibernate.org/66.html


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 28, 2004 12:31 pm 
Newbie

Joined: Fri Dec 05, 2003 11:07 am
Posts: 14
I'm not sure If i should include

<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>

Since my apps connect to different datasource and I load the driver in the code.

Please suggest


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 28, 2004 3:24 pm 
Beginner
Beginner

Joined: Fri Mar 26, 2004 8:19 am
Posts: 49
Can't help you with that then, but with the MBean you won't have to do that. In your client code, just get the SessionFactory from JNDI and got to work. It's the best way from what I can tell.

:-)


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 7 posts ] 

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.