-->
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: Srping + tomcat + hibernate + jndi
PostPosted: Thu Dec 29, 2005 10:57 am 
Newbie

Joined: Thu Dec 29, 2005 10:36 am
Posts: 5
i'm developping in windows with netbeans 5.0

I have problem with the bundled Tomcat 5.5.9 in netbeans and Hibernate-2 wich is used with Spring-1.0 . I have set up a jndi source I use too MySQL server 4.1.11 and the connector is mysql-connector-java-3.1.11 and i have put the driver jar in %tomcat%/common/lib. But, I have troubles to access the database. Someone could help me ?


this is hibernate.properties file:

hibernate.connection.datasource=java:comp/env/jdbc/mabase
hibernate.cglib.use_reflection_optimizer=false
hibernate.dialect=net.sf.hibernate.dialect.MySQLDialect
hibernate.show_sql=false
hibernate.use_outer_join=true
hibernate.transaction.factory_class= net.sf.hibernate.transaction.JDBCTransactionFactory

this is the applicationContext-hibernate file for Spring:

<beans>

<!--data source definition-->
<bean id="myDataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName">
<value>java:comp/env/jdbc/wire</value>
</property>
</bean>

<!-- Hibernate session factory -->
<bean id="mySessionFactory" class="org.springframework.orm.hibernate.LocalSessionFactoryBean">

<property name="mappingResources">
<list>
<value>com/meagle/bo/Order.hbm.xml</value>
<value>com/meagle/bo/OrderLineItem.hbm.xml</value>
</list>
</property>

<property name="hibernateProperties">
<props>
<prop key="hibernate.cglib.use_reflection_optimizer">false</prop>
<prop key="hibernate.dialect">net.sf.hibernate.dialect.MySQLDialect</prop>
<prop key="hibernate.show_sql">false</prop>
<prop key="hibernate.use_outer_join">true</prop>
<prop key="hibernate.transaction.factory_class">net.sf.hibernate.transaction.JDBCTransactionFactory</prop>
</props>
</property>

<property name="dataSource">
<ref local="myDataSource"/>
</property>

</bean>

<!-- Transaction manager for a single Hibernate SessionFactory (alternative to JTA) -->
<bean id="myTransactionManager" class="org.springframework.orm.hibernate.HibernateTransactionManager">
<property name="sessionFactory">
<ref local="mySessionFactory"/>
</property>
</bean>

<!-- ***** ORDER SERVICE *****-->
<bean id="orderService" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">

<property name="transactionManager">
<ref local="myTransactionManager"/>
</property>

<property name="target">
<ref local="orderTarget"/>
</property>

<property name="transactionAttributes">
<props>
<prop key="find*">PROPAGATION_REQUIRED,readOnly,-OrderException</prop>
<prop key="save*">PROPAGATION_REQUIRED,-OrderException,-OrderMinimumAmountException</prop>
</props>
</property>

</bean>

<!-- OrderTarget primary business object implementation -->
<bean id="orderTarget" class="com.meagle.service.spring.OrderServiceSpringImpl">
<property name="orderDAO">
<ref local="orderDAO"/>
</property>
</bean>

<!-- DAO object: Hibernate implementation -->
<bean id="orderDAO" class="com.meagle.service.dao.hibernate.OrderHibernateDAO">
<property name="sessionFactory">
<ref local="mySessionFactory"/>
</property>
</bean>

<!-- Add more services here -->

</beans>


this is web.xml file :


......
<resource-ref>
<description>Mon Pool de connectionl</description>
<res-ref-name>jdbc/wire</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
<res-sharing-scope>Shareable</res-sharing-scope>
</resource-ref>

.........

this the tomcat log :


2005-12-29 15:55:19,750 WARN hibernate.util.JDBCExceptionReporter:38 -> SQL Error: 0, SQLState: null
2005-12-29 15:55:19,765 ERROR hibernate.util.JDBCExceptionReporter:46 -> Cannot create PoolableConnectionFactory (Server connection failure during transaction.
Attemtped reconnect 3 times. Giving up.)
2005-12-29 15:55:19,765 WARN hibernate.util.JDBCExceptionReporter:38 -> SQL Error: 0, SQLState: null
2005-12-29 15:55:19,765 ERROR hibernate.util.JDBCExceptionReporter:46 -> Cannot create PoolableConnectionFactory (Server connection failure during transaction.
Attemtped reconnect 3 times. Giving up.)
2005-12-29 15:55:19,828 ERROR hibernate.util.JDBCExceptionReporter:38 -> Cannot open connection
org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (Server connection failure during transaction.
Attemtped reconnect 3 times. Giving up.)
at org.apache.tomcat.dbcp.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:855)
at org.apache.tomcat.dbcp.dbcp.BasicDataSource.getConnection(BasicDataSource.java:540)
at org.springframework.orm.hibernate.LocalDataSourceConnectionProvider.getConnection(LocalDataSourceConnectionProvider.java:76)
at net.sf.hibernate.impl.BatcherImpl.openConnection(BatcherImpl.java:286)
at net.sf.hibernate.impl.SessionImpl.connect(SessionImpl.java:3326)
at net.sf.hibernate.impl.SessionImpl.connection(SessionImpl.java:3286)
at org.springframework.orm.hibernate.HibernateTransactionManager.doBegin(HibernateTransactionManager.java:408)
at org.springframework.transaction.support.AbstractPlatformTransactionManager.getTransaction(AbstractPlatformTransactionManager.java:281)
at org.springframework.transaction.interceptor.TransactionAspectSupport.createTransactionIfNecessary(TransactionAspectSupport.java:217)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:89)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:144)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:174)
at $Proxy0.saveNewOrder(Unknown Source)
at com.meagle.action.SaveOrderAction.execute(SaveOrderAction.java:85)
at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:484)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:274)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1480)
at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:524)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:362)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:856)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:744)
at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
at java.lang.Thread.run(Thread.java:595)
Caused by: java.sql.SQLException: Server connection failure during transaction.
Attemtped reconnect 3 times. Giving up.
at com.mysql.jdbc.Connection.createNewIO(Connection.java:1639)
at com.mysql.jdbc.Connection.<init>(Connection.java:485)
at com.mysql.jdbc.Driver.connect(Driver.java:341)
at org.apache.tomcat.dbcp.dbcp.DriverConnectionFactory.createConnection(DriverConnectionFactory.java:37)
at org.apache.tomcat.dbcp.dbcp.PoolableConnectionFactory.makeObject(PoolableConnectionFactory.java:290)
at org.apache.tomcat.dbcp.dbcp.BasicDataSource.validateConnectionFactory(BasicDataSource.java:877)
at org.apache.tomcat.dbcp.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:851)
... 36 more
2005-12-29 15:55:19,828 WARN struts.action.RequestProcessor:538 -> Unhandled Exception thrown: class org.springframework.transaction.CannotCreateTransactionException
2005-12-29 15:55:20,000 ERROR [localhost].[/wiring].[action]:253 -> "Servlet.service()" pour la servlet action a généré une exception
org.springframework.transaction.CannotCreateTransactionException: Could not open Hibernate Session for transaction; nested exception is net.sf.hibernate.JDBCException: Cannot open connection
net.sf.hibernate.JDBCException: Cannot open connection
at net.sf.hibernate.impl.BatcherImpl.openConnection(BatcherImpl.java:289)
at net.sf.hibernate.impl.SessionImpl.connect(SessionImpl.java:3326)
at net.sf.hibernate.impl.SessionImpl.connection(SessionImpl.java:3286)
at org.springframework.orm.hibernate.HibernateTransactionManager.doBegin(HibernateTransactionManager.java:408)
at org.springframework.transaction.support.AbstractPlatformTransactionManager.getTransaction(AbstractPlatformTransactionManager.java:281)
at org.springframework.transaction.interceptor.TransactionAspectSupport.createTransactionIfNecessary(TransactionAspectSupport.java:217)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:89)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:144)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:174)
at $Proxy0.saveNewOrder(Unknown Source)
at com.meagle.action.SaveOrderAction.execute(SaveOrderAction.java:85)
at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:484)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:274)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1480)
at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:524)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:362)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:856)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:744)
at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
at java.lang.Thread.run(Thread.java:595)
Caused by: org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (Server connection failure during transaction.
Attemtped reconnect 3 times. Giving up.)
at org.apache.tomcat.dbcp.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:855)
at org.apache.tomcat.dbcp.dbcp.BasicDataSource.getConnection(BasicDataSource.java:540)
at org.springframework.orm.hibernate.LocalDataSourceConnectionProvider.getConnection(LocalDataSourceConnectionProvider.java:76)
at net.sf.hibernate.impl.BatcherImpl.openConnection(BatcherImpl.java:286)
... 33 more
Caused by: java.sql.SQLException: Server connection failure during transaction.
Attemtped reconnect 3 times. Giving up.
at com.mysql.jdbc.Connection.createNewIO(Connection.java:1639)
at com.mysql.jdbc.Connection.<init>(Connection.java:485)
at com.mysql.jdbc.Driver.connect(Driver.java:341)
at org.apache.tomcat.dbcp.dbcp.DriverConnectionFactory.createConnection(DriverConnectionFactory.java:37)
at org.apache.tomcat.dbcp.dbcp.PoolableConnectionFactory.makeObject(PoolableConnectionFactory.java:290)
at org.apache.tomcat.dbcp.dbcp.BasicDataSource.validateConnectionFactory(BasicDataSource.java:877)
at org.apache.tomcat.dbcp.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:851)
... 36 more


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 29, 2005 5:15 pm 
Regular
Regular

Joined: Fri Sep 09, 2005 11:35 am
Posts: 101
Quote:
Caused by: java.sql.SQLException: Server connection failure during transaction.
Attemtped reconnect 3 times. Giving up.
at com.mysql.jdbc.Connection.createNewIO(Connection.java:1639)
at com.mysql.jdbc.Connection.<init>(Connection.java:485)
at com.mysql.jdbc.Driver.connect(Driver.java:341)
at org.apache.tomcat.dbcp.dbcp.DriverConnectionFactory.createConnection(DriverConnectionFactory.java:37)
at org.apache.tomcat.dbcp.dbcp.PoolableConnectionFactory.makeObject(PoolableConnectionFactory.java:290)
at org.apache.tomcat.dbcp.dbcp.BasicDataSource.validateConnectionFactory(BasicDataSource.java:877)
at org.apache.tomcat.dbcp.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:851)
... 36 more


Tomcat cannot connect to your database server.
Are you sure your database is running?
Or you may have incorrect connection configuration.


Top
 Profile  
 
 Post subject: tomcat
PostPosted: Thu Dec 29, 2005 8:37 pm 
Newbie

Joined: Thu Dec 29, 2005 10:36 am
Posts: 5
Well mysql was running and that's the problem.

But you said something interesting, and I was wondering if Tomcat is well configured for data access;


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 30, 2005 10:48 am 
Regular
Regular

Joined: Fri Sep 09, 2005 11:35 am
Posts: 101
i could not see your database configuration anywhere. It has to be defined in either tomcat's server.xml or yout context.xml.


Top
 Profile  
 
 Post subject: server.xml
PostPosted: Fri Dec 30, 2005 7:48 pm 
Newbie

Joined: Thu Dec 29, 2005 10:36 am
Posts: 5
You mean the server.xml wich is located in the folder conf of where Tomcat is set up. I think it's not necesary since I have added the datasource thanks to the admin tool of Tomcat. But i don't know how to configure the server.xml.


Top
 Profile  
 
 Post subject: Re: server.xml
PostPosted: Sun Jan 01, 2006 11:32 pm 
Regular
Regular

Joined: Fri Sep 09, 2005 11:35 am
Posts: 101
kaizer wrote:
You mean the server.xml wich is located in the folder conf of where Tomcat is set up. I think it's not necesary since I have added the datasource thanks to the admin tool of Tomcat. But i don't know how to configure the server.xml.


Check out the tomcat datasource configuration docs at
http://tomcat.apache.org/tomcat-5.5-doc ... howto.html


Top
 Profile  
 
 Post subject: tomcat
PostPosted: Mon Jan 02, 2006 8:28 am 
Newbie

Joined: Thu Dec 29, 2005 10:36 am
Posts: 5
Well, I check the configuration abd I noticed that it was well configured.

But I resolved the problem. It was due to privileges on the user who is connecting to the databases. All I had to due, was simply to use the command grant ...

thanks for trying to help me .


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.