-->
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.  [ 16 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: How to setup JNDI in JBOSS with HIBERNATE
PostPosted: Mon Jul 25, 2005 12:54 pm 
Beginner
Beginner

Joined: Thu Jun 30, 2005 4:14 pm
Posts: 25
Hi, Friends,

I am going to setup JNDI inJboss with hibernate, but I ahve no any idea.
I ahve done this link.
http://www.hibernate.org/66.html
Where can configure these Data souces and session factory name in Jboss? Thank you for help!

Edgy


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 25, 2005 2:06 pm 
Beginner
Beginner

Joined: Fri Jun 04, 2004 12:50 pm
Posts: 32
I have set up a JDBC pool with postgres. These are the basic steps.

You need to place a postgres-ds.xml in the deploy directory which looks something like this:

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

<datasources>
<local-tx-datasource>
<jndi-name>PostgresDS</jndi-name>
<connection-url>jdbc:postgresql://localhost/dbname</connection-url>
<driver-class>org.postgresql.Driver</driver-class>
<user-name>username</user-name>
<password>password</password>
</local-tx-datasource>
</datasources>

Before deploying this file make sure that the jdbc libraries are in the classpath. You can get the file from here: http://jdbc.postgresql.org/download.html

Put the jdbc driver file in server/default/lib directory and restart the server. Then deploy the postgres-ds.xml file.

Then when that is working you can set up the jndi with a jboss-service. You create a sar file with the following information in the jboss-service.xml file which is placed in <sar filename>/META-INF

<server>
<mbean code="org.hibernate.jmx.HibernateService" name="jboss.jca:service=HibernateFactory,
name=HibernateFactory">
<!-- <depends>jboss.jca:service=RARDeployer</depends> -->
<!-- <depends>jboss.jca:name=PostgresDS,service=LocalTxCM</depends> -->
<!-- Make it deploy ONLY after DataSource had been started -->
<attribute name="MapResources">com/camp/common/accounting/ApplicationAccounting.hbm.xml,
<attribute .....next resource file......../>
<attribute name="JndiName">java:/CAMP/HibernateFactory</attribute>
<attribute name="Datasource">java:/PostgresDS</attribute>
<attribute name="Dialect">org.hibernate.dialect.PostgreSQLDialect</attribute>
<attribute name="ShowSqlEnabled">true</attribute>
<attribute name="TransactionManagerLookupStrategy">org.hibernate.transaction.JBossTransactionManagerLookup</attribute>
<attribute name="UserTransactionName">UserTransaction</attribute>
<attribute name="SecondLevelCacheEnabled">true</attribute>
<attribute name="QueryCacheEnabled">true</attribute>
</mbean>
</server>

Note that the datasource for the jboss-service file is the same as the name of the datasource you gave it in the first postgres-ds.xml file.

You also need to place all the hbm.xml files and their corresponding .class files in the .sar file as well. Once that is created you should be able to deploy it.

Then, to create a sessionFactory do something like the following:

Context ctx = new InitialContext();
SessionFactory sessionFactory = ((SessionFactory) ctx.lookup("java:/CAMP/HibernateFactory")).openSession();

Hope that helps.

Cheers
Tom


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 25, 2005 6:52 pm 
Beginner
Beginner

Joined: Thu Jun 30, 2005 4:14 pm
Posts: 25
Tom,

Thank you very much for your help! I think the databse is bound.
But there is a error message after starting Jboss, HibernateFactory is not bound. please see the following error message:

-------------
16:36:53,951 INFO [ConnectionFactoryBindingService] Bound connection factory fo
r resource adapter for ConnectionManager 'jboss.jca:service=ConnectionFactoryBin
ding,name=JmsXA to JNDI name 'java:JmsXA'
16:36:54,061 INFO [WrapperDataSourceService] Bound connection factory for resou
rce adapter for ConnectionManager 'jboss.jca:service=DataSourceBinding,name=PDSS
TUDIO_DS to JNDI name 'java:PDSSTUDIO_DS'
16:36:54,107 INFO [TomcatDeployer] deploy, ctxPath=/jmx-console, warUrl=file:/D
:/jboss-4.0.1/server/default/deploy/jmx-console.war/
16:36:54,264 INFO [TomcatDeployer] deploy, ctxPath=/web-console, warUrl=file:/D
:/jboss-4.0.1/server/default/deploy/management/web-console.war/
16:36:54,982 ERROR [URLDeploymentScanner] Incomplete Deployment listing:
MBeans waiting for other MBeans:
ObjectName: jboss.jca:service=HibernateFactory, name
=HibernateFactory
state: CONFIGURED
I Depend On: jboss.jca:service=LocalTxCM,name=Datasource

Depends On Me:

MBEANS THAT ARE THE ROOT CAUSE OF THE PROBLEM:
ObjectName: jboss.jca:service=LocalTxCM,name=Datasource
state: NOTYETINSTALLED
I Depend On:
Depends On Me: jboss.jca:service=HibernateFactory,
name=HibernateFactory


16:36:55,154 INFO [Http11Protocol] Starting Coyote HTTP/1.1 on http-0.0.0.0-808
0
16:36:55,248 INFO [ChannelSocket] JK2: ajp13 listening on /0.0.0.0:8009
16:36:55,264 INFO [JkMain] Jk running ID=0 time=0/32 config=null
16:36:55,264 INFO [Server] JBoss (MX MicroKernel) [4.0.1 (build: CVSTag=JBoss_4
_0_1 date=200412230944)] Started in 13s:484ms

----------------------------------------------------------------------------

After I typed the application url in browser,

I can see this error message:


16:47:32,260 INFO [STDOUT] Problem looking up database : javax.naming.NameNotFo
undException: hibernate not bound

please help me, Thank you!

Edgy


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 25, 2005 10:55 pm 
Beginner
Beginner

Joined: Fri Jun 04, 2004 12:50 pm
Posts: 32
Edgy,

I actually get a similar problem when I add the jboss service. Test the service to see if it actually works by removing the service from the deploy directory, restart the server, and then once everything is up and running try and deploy it.

On my system the jboss service tries to start before the datasource even if I have the depends keywords in. Not quite sure what I am doing wrong to be honest.

If you deploy the jboss service after starting the server and there are no exceptions then it is just a dependency issue. If there are still exceptions then let me know.

Cheers
Tom


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 25, 2005 10:57 pm 
Beginner
Beginner

Joined: Fri Jun 04, 2004 12:50 pm
Posts: 32
Edgy,

Also, is your datasource definitely working properly? And post the two files you are using. We can see if there are any problems with them.

Cheers
Tom


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 26, 2005 11:49 am 
Beginner
Beginner

Joined: Thu Jun 30, 2005 4:14 pm
Posts: 25
Tom,

Thank you, I deleted all the services files. the isssue doesn't go away.
I wonder if I need delete all service files in deploy.

Here I attached the 2 files jboss jboss-service and mssql-ds.xml files.

And I am not sure this is for hibernate2 or hibernate3 or both.
Thank you very much again.

Edgy
---------------------------------------
<server>
<mbean code="org.hibernate.jmx.HibernateService" name="jboss.jca:service=HibernateFactory,
name=HibernateFactory">
<!--<depends>jboss.jca:service=RARDeployer</depends> -->
<depends>jboss.jca:service=LocalTxCM,name=Datasource</depends>
<!-- Make it deploy ONLY after DataSource had been started -->
<attribute name="MapResources">com/premierdata/pdsstudio/server/model/GroupTable.hbm.xml,
com/premierdata/pdsstudio/server/model/Group.hbm.xml
</attribute>
<attribute name="JndiName">java:/hibernate/HibernateFactory</attribute>
<attribute name="Datasource">java:/PDSSTUDIO_DS</attribute>
<attribute name="Dialect">net.sf.hibernate.dialect.SQLServerDialect</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">true</attribute>
<attribute name="UserTransactionName">UserTransaction</attribute>


</mbean>
</server>


---------------------------------------------

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


<datasources>
<local-tx-datasource>
<jndi-name>PDSSTUDIO_DS</jndi-name>
<connection-url>jdbc:jtds:sqlserver://localhost/PDSStudio</connection-url>
<driver-class>net.sourceforge.jtds.jdbc.Driver</driver-class>
<user-name>chwang</user-name>
<password>718823wl</password>
</local-tx-datasource>

</datasources>


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 26, 2005 1:47 pm 
Beginner
Beginner

Joined: Fri Jun 04, 2004 12:50 pm
Posts: 32
chwang wrote:
<depends>jboss.jca:service=LocalTxCM,name=Datasource</depends>


This will not help the cause much. Remove that line and try again. Also, if the password you sent is the one you use then you may want to not do that in future!! =)


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 26, 2005 4:17 pm 
Beginner
Beginner

Joined: Thu Jun 30, 2005 4:14 pm
Posts: 25
Tom,

I deleted this line, but another error came out.

Edgy

----


14:13:28,273 INFO [NamingHelper] JNDI InitialContext properties:{}
14:13:28,273 FATAL [DatasourceConnectionProvider] Could not find datasource: java:/PDSSTUDIO_DS
javax.naming.NameNotFoundException: PDSSTUDIO_DS not bound
at org.jnp.server.NamingServer.getBinding(NamingServer.java:491)
at org.jnp.server.NamingServer.getBinding(NamingServer.java:499)
at org.jnp.server.NamingServer.getObject(NamingServer.java:505)
at org.jnp.server.NamingServer.lookup(NamingServer.java:278)
at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:544)
at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:520)
at javax.naming.InitialContext.lookup(Unknown Source)
at net.sf.hibernate.connection.DatasourceConnectionProvider.configure(Da
tasourceConnectionProvider.java:44)
at net.sf.hibernate.connection.ConnectionProviderFactory.newConnectionPr
ovider(ConnectionProviderFactory.java:83)
at net.sf.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.ja
va:65)
at net.sf.hibernate.cfg.Configuration.buildSettings(Configuration.java:1
155)
at net.sf.hibernate.cfg.Configuration.buildSessionFactory(Configuration.
java:789)
at net.sf.hibernate.jmx.HibernateService.buildSessionFactory(HibernateSe
rvice.java:163)
at net.sf.hibernate.jmx.HibernateService.start(HibernateService.java:130
)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatch
er.java:144)
at org.jboss.mx.server.Invocation.dispatch(Invocation.java:80)
at org.jboss.mx.server.Invocation.invoke(Invocation.java:72)


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 26, 2005 4:20 pm 
Beginner
Beginner

Joined: Thu Jun 30, 2005 4:14 pm
Posts: 25
looks like this line <depends>jboss.jca:service=LocalTxCM,name=Datasource</depends>

points to this line

<attribute name="Datasource">java:/PDSSTUDIO_DS</attribute>


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 26, 2005 5:19 pm 
Beginner
Beginner

Joined: Thu Jun 30, 2005 4:14 pm
Posts: 25
Tom,
I forgot to tell you. Currently,
I am using JBOSS 1.0.4 and Hibernate2

so my jboss-service.xml files is like this


<server>
<mbean code="net.sf.hibernate.jmx.HibernateService" name="jboss.jca:service=HibernateFactory,
name=HibernateFactory">


....

</server>


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 27, 2005 11:00 am 
Beginner
Beginner

Joined: Fri Jun 04, 2004 12:50 pm
Posts: 32
ok, you need to delete the depends line from the jboss service for the moment. I think it is causing problems.

secondly, your datasource is not bound or you are incorrectly naming it in your jboss-service. Hence the error:

Quote:
14:13:28,273 FATAL [DatasourceConnectionProvider] Could not find datasource: java:/PDSSTUDIO_DS
javax.naming.NameNotFoundException: PDSSTUDIO_DS not bound


When you start jboss, look for the line that binds your datasource. It should look something like this:

Quote:
08:53:17,372 INFO [WrapperDataSourceService] Bound connection factory for resource adapter for ConnectionManager 'jboss
.jca:name=DefaultDS,service=DataSourceBinding to JNDI name 'java:PostgresDS'


Then, in your jboss-service.xml file the datasource using the above example should be:

<attribute name="Datasource">java:/PostgresDS</attribute>


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 27, 2005 3:54 pm 
Beginner
Beginner

Joined: Thu Jun 30, 2005 4:14 pm
Posts: 25
Thank you very much!!!!!!! Tom, I fixed this issue. you are right. I typed a little wrong for dabase name.

It works perfect!!

Best Regrads.

Edgy


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 27, 2005 4:09 pm 
Beginner
Beginner

Joined: Thu Jun 30, 2005 4:14 pm
Posts: 25
Tom,

I still have a couple of questions.

1. )Can I change mssql-ds.xml name. I changed this name to like mssql-pdsstudiods.xml, exceptions came out.

2.) How can I handel mutilple databases with this mssql-ds.xml files.

Thank very much again. You are super!!!

Edgy


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 27, 2005 4:55 pm 
Beginner
Beginner

Joined: Fri Jun 04, 2004 12:50 pm
Posts: 32
chwang,

Good to know things are working for you. =)

No, I think you need to leave it at mssql-ds.xml. There are examples in the jboss distribution under docs\examples\jca. It looks like there is a mssql-ds.xml file so I would leave it at that. You may be able to change it but I think you would have to change other files as well. Not sure on that one though.

As for multiple databases, what do you mean by that? Do you mean multiple databases off of the same datasource or multiple datasources? If you mean multiple datasources then you should be able to just add them in under the first one like this:

Code:
<datasources>

<local-tx-datasource>
<jndi-name>PostgresDS1</jndi-name>
<connection-url>jdbc:postgresql://localhost/dbname1</connection-url>
<driver-class>org.postgresql.Driver</driver-class>
<user-name>username</user-name>
<password>password</password>
</local-tx-datasource>

<local-tx-datasource>
<jndi-name>PostgresDS2</jndi-name>
<connection-url>jdbc:postgresql://localhost/dbname2</connection-url>
<driver-class>org.postgresql.Driver</driver-class>
<user-name>username</user-name>
<password>password</password>
</local-tx-datasource>

</datasources>

I haven't actually tried it but I am almost positive this will work.

Cheers
Tom


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 28, 2005 11:41 am 
Beginner
Beginner

Joined: Thu Jun 30, 2005 4:14 pm
Posts: 25
Tom,

Thank you. if I change name like *****-ds.xml, it works.

Your post code is what I mean. I will try later.

Thank you very much!

Edgy


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 16 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.