I'm trying to use HikariCP together with DB2 but get the following error:
Failure in loading native library db2jcct2,
java.lang.UnsatisfiedLinkError: db2jcct2
I have db2jcc4.jar file at my class path and only it.
And the following hikari properties file:
dataSourceClassName=com.ibm.db2.jcc.DB2SimpleDataSource
dataSource.user=username
dataSource.password=password
dataSource.databaseName=database
dataSource.serverName=server:50000
From what I understand Hikari tries to use type 2 driver and therefor it requires native library db2jcct2 is it right? And if yes, how can I say it implicitly to look for type 4 driver?
Update:
Proposed answer doesn't solve my issue. It can give direction but I could't get the correct answer only by reading that answer. At the same time you can find the answer in the comments to this question.
This question is equivalent to Why is DB2 Type 4 JDBC Driver looking for native library db2jcct2?
If you were configuring the DataSource in code you would need to do this:
// Assuming dataSource is a com.ibm.db2.jcc.DB2SimpleDataSource
dataSource.setDriverType(4);
DataSources are javabeans. The convention of javabeans is that a pair of setXxxx/getXxxrepresents the property xxxx. So a setter setDriverType is equivalent to the property driverType.
The hikari properties configure a datasource by defining the properties (which are then set through reflection). To do the equivalent of setDriverType(4), you need to use property driverType=4. Given the convention used in that properties file that leads to:
datasource.driverType=4
For DB2 type 4 driver, please try the following configuration.
<bean id="hikariConfig" class="com.zaxxer.hikari.HikariConfig">
<property name="poolName" value="springHikariCP" />
<property name="dataSourceClassName" value="com.ibm.db2.jcc.DB2SimpleDataSource"/>
<property name="maximumPoolSize" value="${db.maxTotal}" />
<property name="dataSourceProperties">
<props>
<prop key="driverType">4</prop>
<prop key="serverName">192.168.xxx.xxx</prop>
<prop key="databaseName">dbname</prop>
<prop key="portNumber">50000</prop>
<prop key="user">db2inst1</prop>
<prop key="password">password</prop>
</props>
</property>
<property name="jdbcUrl" value="${db.url}" />
<property name="username" value="${db.username}" />
<property name="password" value="${db.password}" />
</bean>
<bean id="dataSource" class="com.zaxxer.hikari.HikariDataSource" destroy-method="close">
<constructor-arg ref="hikariConfig" />
</bean>
Related
I Recently migrated to using the spring framework for DI - working fine. I'm injecting a persistence manager which also works fine. On a new install, I get:
SEVERE: Required table missing .... Either your MetaData is incorrect, or you need to enable "datanucleus.autoCreateTables"
Fair enough, I'm not enabling autocreate tables.
I create my persistence manager like this in the spring context.xml per the doc:
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="org.h2.Driver"/>
<property name="url" value="jdbc:h2:./thedbpath.db;MV_STORE=FALSE;MVCC=FALSE;FILE_LOCK=NO"/>
<property name="username" value=""/>
<property name="password" value=""/>
</bean>
<bean id="pmf" class="org.datanucleus.api.jdo.JDOPersistenceManagerFactory" destroy-method="close">
<property name="connectionFactory" ref="dataSource"/>
<property name="nontransactionalRead" value="true"/>
</bean>
everything works - but i can't figure out where to set the datanucleus.autoCreateTables
This normally would be set in the persistence.xml - I don't see where to put datanucleus properties in the spring context.xml. Thanks in advance
edit: thanks to the answer below, this was the correct config:
<bean id="pmf" class="org.springframework.orm.jdo.LocalPersistenceManagerFactoryBean">
<property name="jdoProperties">
<props>
<prop key="javax.jdo.PersistenceManagerFactoryClass">
org.datanucleus.api.jdo.JDOPersistenceManagerFactory
</prop>
<prop key="javax.jdo.option.ConnectionURL">jdbc:h2:./database/db;MV_STORE=FALSE;MVCC=FALSE;;FILE_LOCK=NO</prop>
<prop key="javax.jdo.option.ConnectionUserName">sa</prop>
<prop key="javax.jdo.option.ConnectionPassword"></prop>
<prop key="javax.jdo.option.ConnectionDriverName">org.h2.Driver</prop>
<prop key="org.jpox.autoCreateSchema">true</prop>
<prop key="org.jpox.identifier.case">PreserveCase</prop>
<prop key="datanucleus.autoCreateTables">true</prop>
</props>
</property>
</bean>
This page
http://www.datanucleus.org/products/accessplatform_3_0/guides/jdo/springframework/index.html
has a "jdoProperties" property that can be used to specify JDO implementation-specific properties. Maybe try that?
I'm setting up a xml-free persistence JPA/Hibernate 4+/Spring 3+ using Intellij 13+. When I try to execute a query in the jpa console, I get the following error:
javax.persistence.PersistenceException: Unable to build entity manager factory
java.lang.RuntimeException: org.hibernate.boot.registry.selector.spi.StrategySelectionException: Unable to resolve name [org.hibernate.dialect.PostgreSQL9Dialectt.PostgreSQL9Dialect] as strategy [org.hibernate.dialect.Dialect]
With the default postgres dialect, I get the same error.
Any idea what's going on?
Configuration extract:
<bean id="entityManagerFactory"
class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="packagesToScan" value="com.wikiz.service.model.rep" />
<property name="jpaVendorAdapter">
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter" />
</property>
<property name="jpaProperties">
<props>
<prop key="hibernate.dialect">${hibernate.dialect}</prop>
<prop key="hibernate.show_sql">${hibernate.show_sql}</prop>
<prop key="hibernate.format_sql">${hibernate.format_sql}</prop>
<prop key="hibernate.hbm2ddl.auto">${hibernate.hbm2ddl.auto}</prop>
<prop key="jadira.usertype.autoRegisterUserTypes">true</prop>
<prop key="hibernate.ejb.naming_strategy">org.hibernate.cfg.ImprovedNamingStrategy</prop>
</props>
</property>
</bean>
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="${db.driver}"/>
<property name="url" value="${db.url}"/>
<property name="username" value="${db.user}"/>
<property name="password" value="${db.pass}"/>
</bean>
And variables:
hibernate.dialect=org.hibernate.dialect.PostgreSQL9Dialect
hibernate.show_sql=true
hibernate.format_sql=true
hibernate.hbm2ddl.auto=create
Ok here it is.
I am not 100% sure if this helps your case but I think this is what you need to do:
Add a jdbc connection to your database from the database tab (usually to your right)
Then add the hibernate facet to your module
Go to modules (alt+ctrl+shift+s) then add it:
Now you have enabled the persistance tab on your left (usually) and you can assign a datasource to your
Now add the hibernate configuration but you have to add the xml file of hibernate. I haven't tried it with just adding the spring application context instead of hibernate.cfg.xml. Maybe it will work...
Now you have enable the presistance configuration for intellij and you can assign a datasource to it.
Select that datasource that you want and you will be able to use the JPA console with your jpa POJOs and HSQLs
I need a little bit of help in configuring JBoss to work with MQ. I have created initial context in MQ using IBM MQ Explorer and have given a local directory for all bindings like file:/C:/jndi. I have created a connection factory for this initial context. Now JBoss documentation says to bind like this
<connection-definition class-name="com.ibm.mq.connector.outbound.ManagedConnectionFactoryImpl"
jndi-name="java:jboss/MQ.CONNECTIONFACTORY.NAME"
pool-name="MQ.CONNECTIONFACTORY.NAME">
I think I am missing some point here. How do I tell Jboss that my InitialContext bindings are in a directory. I have tried most of the combinations. May be I am not getting the concept right. Any pointers ?
When I try to access this MQ.CONNECTIONFACTORY.NAME from a test servlet I wrote I get javax.naming.NameNotFoundException . If I follow same steps in Java SE environment I am successfully able to establish a connection. I am new to application servers and the question might be naive
Regards
The description of the resources created via MQExplorer suggest that these have been put into JNDI backed by a File System context. This is perfectly fine, but what in theory needs to be done now is get JBOSS to read objects out that JNDI context rather than the usual JNDI provider provided by JBOSS. The settings that are in the connection definition extract are using the standard JBOSS JNDI context.
As an example of using JBOSS with the WebSphere MQ Resoruce Adapter have a look here http://pic.dhe.ibm.com/infocenter/wmqv7/v7r5/topic/com.ibm.mq.dev.doc/q031810_.htm
This links to an example set of definitions that store WMQ JMS administered objects in the JBOSS JNDI context.
This is an important question. I have used Spring for this, like this:
<util:properties id="remoteEnv">
<prop key="java.naming.provider.url">file:${my.config.path}/bindings</prop>
<prop key="java.naming.factory.url.pkgs">org.jboss.naming:org.jboss.naming.remote.client</prop>
<prop key="java.naming.factory.initial">com.sun.jndi.fscontext.RefFSContextFactory</prop>
<prop key="java.naming.security.principal">${mdb.user.name}</prop>
<prop key="java.naming.security.credentials">${mdb.user.pass}</prop>
</util:properties>
<bean id="remoteJNDITemplate" class="org.springframework.jndi.JndiTemplate">
<property name="environment" ref="remoteEnv" />
</bean>
<bean id="remoteJmsDestinationResolver" class="org.springframework.jms.support.destination.JndiDestinationResolver">
<property name="jndiTemplate" ref="remoteJNDITemplate" />
<property name="cache" value="true" />
</bean>
<jee:jndi-lookup id="senderQueue" jndi-name="MY_QUEUE_NAME" environment-ref="remoteEnv" />
<bean id="xamqconnectionFactory" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiTemplate">
<ref bean="remoteJNDITemplate"/>
</property>
<property name="jndiName" value="MYCONNECTIONFACTORYJNDINAME"/>
<property name="lookupOnStartup" value="false" />
<property name="proxyInterface" value="javax.jms.XAQueueConnectionFactory" />
</bean>
<bean id="xaMQSenderJMSTemplate" class="org.springframework.jms.core.JmsTemplate">
<property name="connectionFactory">
<ref bean="xamqconnectionFactory" />
</property>
<property name="pubSubDomain">
<value>false</value>
</property>
<property name="defaultDestination">
<ref bean="senderQueue" />
</property>
<property name="destinationResolver" ref="remoteJmsDestinationResolver" />
</bean>
however using the configuration above we bypass the resource adapter. That's no problem otherwise but it prevents transactions from joining the JBoss transaction, so JMS messages are send immediately, not with transaction commit. I haven't found a fix for that yet.
com.sun.jndi.fscontext.RefFSContextFactory, that is used to read .bindings file, can be found at this dependency:
<dependency>
<groupId>com.sun.messaging.mq</groupId>
<artifactId>fscontext</artifactId>
<version>4.6-b01</version>
</dependency>
I have a web application that uses spring and hibernate. My hibernate session factory is configured in spring as:
<bean id="mySessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource" ref="myDataSource" />
<property name="configurationClass">
<value>org.hibernate.cfg.AnnotationConfiguration</value>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.dialect">org.hibernate.dialect.SQLServer2005Dialect</prop>
<prop key="hibernate.cache.use_query_cache">false</prop>
<prop key="hibernate.cache.use_second_level_cache">false</prop>
</props>
</property>
<property name="packagesToScan">
<list>
<value>com.example.dslibweb.model</value>
</list>
</property>
</bean>
The data source as:
<bean id="myDataSource" class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName" value="${jdbc.driverClassName}" />
<property name="url" value="${jdbc.url}" />
<property name="username" value="${jdbc.username}" />
<property name="password" value="${jdbc.password}" />
<property name="maxActive" value="${jdbc.maxConnections}" />
</bean>
and the properties file for the data source is:
jdbc.username=sa
jdbc.password=***
jdbc.url=jdbc:sqlserver://10.62.0.105:1433;databaseName=example;useUnicode=true;characterEncoding=utf-8
jdbc.driverClassName=com.microsoft.sqlserver.jdbc.SQLServerDriver
jdbc.maxConnections=-1
I have a call:
DsActions action = (DsActions) this.hibernateCriteriaCommons.findById(id, new DsActions());
and findById is defined as:
public T findById(String id, Object model) {
return (T) this.sessionFactory.getCurrentSession().get(model.getClass(), id);
}
So I am calling the get method of hibernate session for a specific id and I expect an instance of type DsActions.
All works well when I run it from a local Tomcat instance (run through netbeans).
When I install it on a remote tomcat server, the instance of DsActions seems to have an encoding issue. When retriveing a field of DsActions instance I get question marks (??? ?????? ??????). The text is supposed to be greek characters
I am very confused, I do not understand why in the first case it is working and not in the second.
Note: the data is retrieved by the same database server, so no difference there. The only difference is the machine where the application is running.
Thank you all in advance.
I'm pretty sure that Hibernate retrieves that field correctly, and the problem is in the way you output these characters.
As a quick check you can add a condition such as f.contains("?") to your code and output its result - it should be false (if original string doesn't contain ?s, of course).
For possible problems in output see Unicode - How to get the characters right?.
I am trying to embed activemq broker in a Tomcat. The code base will be deployed in different environments. I want to externalize some parameters, but want to provide default values for those parameters in case the deployed environment does not provide values for place holders.
This is what I have :
<property name="properties">
<props>
<prop key="embed.broker.networkConnectorURI">static:(failover:(tcp://server01:61616,tcp://server02:61616))
</prop>
<prop key="embed.broker.transportConnectorURI">vm://localhost:61616</prop>
</props>
</property>
<bean id="broker" class="org.apache.activemq.broker.BrokerService"
init-method="start" destroy-method="stop">
<property name="networkConnectorURIs">
<list>
<ref >${embed.broker.networkConnectorURI}</ref>
</list>
</property>
<property name="transportConnectorURIs">
<list>
<value>${embed.broker.transportConnectorURI}</value>
</list>
</property>
<property name="brokerName" value="embed-broker" />
</bean>
When I deploy this in an environment where the place holders are missing, Tomcat throws "Could not resolve placeholder 'embed.broker.networkConnectorURI' " error. In other words, the default values are not being picked up.
Any help would be appreciated.
To have some default values, go on this way:
<bean id="myServer" class="com.gordondickens.myapp.MyServerConfig">
<property name="serverName" value="${server.name?localhost}" />
<property name="serverPort" value="${server.port?25}" />
</bean>
Use a PropertyOverrideConfigurer instead of a PropertyPlaceholderConfigurer. That way your defaults specified in the context file will be used if no overriding property file entries are found.