<bean id="entityManagerFactory"
class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"
p:dataSource-ref="dataSource" p:packagesToScan="com.history"
p:jpaVendorAdapter-ref="jpaVendorAdapter">
<property name="jpaProperties" ref="hibernateProperties" />
</bean>
<bean id="jpaVendorAdapter"
class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
<property name="showSql" value="true" />
<property name="generateDdl" value="true" />
<property name="database" value="ORACLE" />
<property name="databasePlatform" value="org.hibernate.dialect.OracleDialect" />
</bean>
<util:map id="hibernateProperties">
<entry key="hibernate.connection.driver_class"
value="org.hibernate.hikaricp.internal.HikariCPConnectionProvider" />
<entry key="connection.url" value="${dataSource.url}" />
<entry key="connection.driver_class" value="${dataSource.driverClassName}" />
<entry key="connection.username" value="${dataSource.username}" />
<entry key="connection.password" value="${dataSource.password}" />
<entry key="hibernate.jdbc.batch_size" value="100" />
<entry key="hibernate.order_inserts" value="true" />
<entry key="hibernate.order_updates" value="true" />
</util:map>
<bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="${dataSource.driverClassName}" />
<property name="url" value="${dataSource.url}" />
<property name="username" value="${dataSource.username}" />
<property name="password" value="${dataSource.password}" />
</bean>
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager"
p:entityManagerFactory-ref="entityManagerFactory">
</bean>
答案 0 :(得分:0)
如果你想使用Hikari,你需要声明它,所以你的dataSource配置应该是
<bean id="dataSource"
class="com.zaxxer.hikari.HikariDataSource">
<property name="driverClassName" value="${dataSource.driverClassName}" />
<property name="jdbcUrl" value="${dataSource.url}" />
<property name="username" value="${dataSource.username}" />
<property name="password" value="${dataSource.password}" />
</bean>
答案 1 :(得分:0)
您的数据源配置应如下所示:
<beans:bean id="dataSource" class="com.zaxxer.hikari.HikariDataSource" destroy-method="close">
<beans:property name="dataSourceClassName" value="com.mysql.jdbc.jdbc2.optional.MysqlDataSource"/>
<beans:property name="maximumPoolSize" value="5" />
<beans:property name="maxLifetime" value="30000" />
<beans:property name="idleTimeout" value="30000" />
<beans:property name="dataSourceProperties">
<beans:props>
<beans:prop key="url">jdbc:mysql://localhost:3306/exampledb</beans:prop>
<beans:prop key="user">root</beans:prop>
<beans:prop key="password"></beans:prop>
<beans:prop key="prepStmtCacheSize">250</beans:prop>
<beans:prop key="prepStmtCacheSqlLimit">2048</beans:prop>
<beans:prop key="cachePrepStmts">true</beans:prop>
<beans:prop key="useServerPrepStmts">true</beans:prop>
</beans:props>
</beans:property>
</beans:bean>
可以在链接中找到要下载的示例项目的完整示例: http://frameworkonly.com/hikaricp-connection-pooling-in-spring-hibernate-jpa/
答案 2 :(得分:0)
我们也可以在下面的定制JPAConfiguration类中使用它,您可以在其中建立连接并创建实体Manager Factory对象。
DECLARE @Columns_Updated VARCHAR(500)
DECLARE @Columns_Updated_Values AS NVARCHAR(500);
DECLARE @CUV_temp TABLE(value NVARCHAR (500))
DECLARE @sqlQuery AS NVARCHAR(200) = 'SELECT CONCAT(' + REPLACE(@Columns_Updated,',',','','',') + ') from inserted';
INSERT INTO @CUV_temp
EXEC(@sqlQuery)
SELECT @Columns_Updated_Values = value
FROM @CUV_temp
INSERT INTO Crm_Log (ModifedFields, ModifiedValues)
SELECT @Columns_Updated, @Columns_Updated_Values