I am developing an application with spring and hibernate entityManager
The oracle database is outside the DMZ.
the connection will be interrupted after a period of inactivity by the firewall.
I added the ValidationQuery select 1 from dual in context.xml but it does not solve the problem.
In your datasource try to add the below. testWhileIdle
<Resource auth="Container"
type="javax.sql.DataSource"
name="jdbc/testt"
driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://********/mydb"
maxActive="10"
maxIdle="5"
validationQuery="SELECT 1"
testOnBorrow="true"
testWhileIdle="true"
timeBetweenEvictionRunsMillis="10000"
minEvictableIdleTimeMillis="60000"
username="..." password="..."/>
Related
I have a Spring Boot application which connects to different MySQL databases. I am planning to add connection pool support to this application. Does the Tomcat JDBC Connection Pool (default Spring boot pool) support more than one pool for each of my databases?
Not sure how this would be different under Spring Boot, but for standard web apps you can configure this at the webapp level, by adding in web.xml any number of the following:
<resource-ref>
<res-ref-name>jdbc/yourname</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
and in context.xml the corresponding number of the following:
<Resource name="jdbc/yourname" auth="Container" type="javax.sql.DataSource"
maxActive="30"
maxIdle="30"
maxWait="2000"
removeAbandoned="true"
...
I need to implement JTA transaction management using spring jdbc in liferay. I have two databases connected in liferay using jndi. In my project I am doing jdbc CRUD operation using jdbc spring dao and for liferay, it is through liferay build-in service api. For any exception, rollback is working fine for other db but it is not working for liferay.
Below is my code sample:
In portal-ext.prop I have defined
transaction.management.impl= <JTATransactionmanager>
In my project's context.xml of tomcat I have defined user transaction as mentioned at liferay's site :
context.xml
`<Resource name="UserTransaction" auth="Container" type="javax.transaction.UserTransaction" />
<Transaction factory="org.objectweb.jotm.UserTransactionFactory" jotm.timeout="600" /><br>
<Resource auth="Container" type="javax.sql.DataSource" factory="org.objectweb.jotm.datasource.DataSourceFactory" driverClassName="<postgresqldriver>" name="jdbc/LiferayPool" username="root" password="" url="jdbc:mysql://localhost/lportal?useUnicode=true&characterEncoding=UTF-8&useFastDateParsing=false" />}}}<br>
<Resource auth="Container" type="javax.sql.DataSource" factory="org.objectweb.jotm.datasource.DataSourceFactory" driverClassName="<postgresqldriver>" name="jdbc/test" username="root" password="" url="jdbc:mysql://localhost/test?useUnicode=true&characterEncoding=UTF-8&useFastDateParsing=false" />}}}
`
In bean.xml of my project :
<tx:annotation-driven transaction-manager="txManager"/>
<beans:bean id="dbDataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
<beans:property name="jndiName" value="java:comp/env/jdbc/test"/>
</beans:bean>
<bean id="txManager" class="org.springframework.transaction.jta.JtaTransactionManager" />
in my class:
#Transactional(rollback{myexception.class})
public void test()
first of all put an eye on this discussion.
What you wouldn't forget is that Liferay rollbacks both for PortalException or SystemException... but it rollbacks only the beans injected inside the current transaction context.
This means that you shouldn't use XLocalServiceUtil, but the injected xLocalService bean.
To get it you need to advice your service layer by service.xml declarations or, inside your serviceImpl class, by adding and referring to:
#BeanReference(type=XArticleLocalService.class)
protected XArticleLocalService xArticleLocalService;
I hope this can help you.
I believe you are using the XXXServiceUtil.java. Whenever you use ServiceUtil, any method you call executes under a different transaction manager (regardless of current thread transaction state) as it's a completely different class loader. Remember in Liferay, every portlet/plugin has its own class loader.
I am retriving data from oracle11g and displaying the data on IE8 and IE9 browser, but the couldn't display some special characters (eg. é)
In my webpage, I have explicitly declare 'UTF-8' encoding.
For my tomcat webserver, the server.xml
<Connector port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" URIEncoding="UTF-8" useBodyEncodingForURI="true"/>
I read some other questions in stackflow, they mentioned to also ensure the database connection is using 'UTF-8' too.
<Resource name="jdbc/AppDB"
auth="Container"
type="javax.sql.DataSource"
maxActive="20" maxIdle="10" maxWait="10000"
username="foo"
password="bar"
driverClassName="com.mysql.jdbc.Driver" url="jdbc:mysql://localhost:3306/ ID_development?useEncoding=true&characterEncoding=UTF-8"
/>
The solution given is for mysql.
How can i set the encoding if im using oracleDriver?
<Resource name="jdbc/AppDB"
auth="Container"
type="javax.sql.DataSource"
driverClassName="oracle.jdbc.OracleDriver"
url="jdbc:oracle:thin:#127.0.0.1:1521:ora11"
username="foo"
password="bar"
maxActive="20"
maxIdle="1000"
maxWait="-1" />
Please review this answer. Regardless of fact that it's focused on SQL Developer, it contains information about tuning JDBC driver and points out how to properly handle unicode character types in Oracle.
Update
Troubles with displaying characters on the client may be caused by wrong NLS_LANG settings on the database client (Tomcat in your case). For thin JDBC driver NLS_LANG value derived from java locale settings.
For possible variants you can look through the answers on this question and check Oracle documentation.
If a real source of the problem lies to character set of Oracle database connection, then there are only two possible end points to check: NLS_LANG and oracle.jdbc.defaultNChar . So you need to examine if both set properly to figure out what is happened.
I'm using an older Spring 2 application with Tomcat and Hibernate. I was under the impression that I could change some settings in hibernate.cfg.xml, restart Tomcat, and the new settings (like a database connection) would take effect. Yet the old settings persist. What do I have to do to make these new changes go through? Here is an example of the xml:
<property name="connection.username">career</property>
<property name="connection.url">jdbc:oracle:thin:#192.168.76.46:1521:ISDD</property>
<property name="dialect">org.hibernate.dialect.Oracle9Dialect</property>
<property name="myeclipse.connection.profile">my-careers</property>
<property name="connection.password">farcri</property>
<property name="connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
Let me know if more information is required.
i am not sure what your new settings are.Anyway they should be found.do you want to change database from one provider to oracle.Please put your tomcat output..You can do one thing that include log4j jar files so that you can see what tomcat is doing in detail manner.i think you are using myeclipse..do project clean such things..go to project and right click then do refresh..do close myeclipse and start again.
Hope this helps to you to figure out your problem.
As it turns out, hibernate.cfg.xml was not being read by the application. Instead, the database connection settings were placed in the ROOT.xml file in localhost. Not sure why this would be advantageous. Here is the relevant section of the ROOT.xml file:
<Resource name="jdbc/careers" auth="Container"
type="javax.sql.DataSource" driverClassName="oracle.jdbc.OracleDriver"
url="jdbc:oracle:thin:#192.168.76.55:1521:ISDD"
username="career" password="farcri" maxActive="20" maxIdle="10"
maxWait="-1"/>
I am developing a spring web application . A JAR file which I use in my application , is looking for DataSource using JNDI. I configured the element in my tomcat's server.xml. The configuration is as below ,
<GlobalNamingResources>
<Resource name="jdbc/abcd"
auth="Container"
type="javax.sql.DataSource"
maxActive="70"
maxWait="10000"
username="xxxx" password="yyyy"
validationQuery="SELECT 1 from dual"
driverClassName="oracle.jdbc.driver.OracleDriver"
url="jdbc:oracle:thin:#xx.xxx.xx.xx:xxxx:zzzz"
testOnBorrow="false"
testOnReturn="false"
testWhileIdle="true"
timeBetweenEvictionRunsMillis="120000"
minEvictableIdleTimeMillis="3600000"
/>
</GlobalNamingResources>
The Resource name configured above , "jdbc/abcd" is the same which the JAR is looking for,
But its not able to find this configured data source . Does anyone know what could be the reason ?
Am getting the below exception ,
javax.naming.NameNotFoundException: Name jdbc is not bound in this Context
You need to define a ResourceLink in the web application context that makes the global resource visible to the web application.
<ResourceLink
name="nameThatIsVisibleToTheWebApplication"
global="theGlobalName"
...
You need to do more than just configure Spring.
I'd recommend reading Tomcat JNDI documentation and this.