Now I want to use JPA second level cache by ehache. I made some configuration and it seems work. But I still can see the query sql. I'm not sure ehcache is working. Does anybody know about that? Thanks.
1.some part of persistence.xml
<property name="hibernate.cache.region.factory_class" value="org.hibernate.cache.ehcache.EhCacheRegionFactory" />
<property name="hibernate.cache.provider_configuration" value="/ehcache.xml" />
<property name="hibernate.generate_statistics" value="true" />
<property name="hibernate.cache.use_second_level_cache" value="true" />
<property name="hibernate.cache.use_query_cache" value="true" />
<property name="hibernate.show_sql" value="true" />
2.ehcache.xml
<?xml version="1.0" encoding="UTF-8"?>
<ehcache>
<defaultCache maxElementsInMemory="1" eternal="false"
timeToIdleSeconds="1200" timeToLiveSeconds="1200" overflowToDisk="true" clearOnFlush="true">
</defaultCache>
<cache name="org.test.persistent.entity.Scenario"
maxElementsInMemory="10000"
eternal="false"
timeToIdleSeconds="1800"
timeToLiveSeconds="3600"
overflowToDisk="true">
</cache>
<cache name="org.hibernate.cache.spi.UpdateTimestampsCache"
maxElementsInMemory="10000"
timeToIdleSeconds="1800"
timeToLiveSeconds="3600"
eternal="false">
</cache>
</ehcache>
3. sql
TypedQuery<Scenario> query = em.createQuery(
"from Scenario as s where s.obsolete!=1 and s.parentId=? order by s.name, s.scenarioStatusId",
Scenario.class);
query.setParameter(1, parentId);
query.setHint("org.hibernate.cacheable", true);
List<Scenario> scenarios = null;
org.hibernate.Query hbQuery = null;
if (query instanceof org.hibernate.ejb.QueryImpl) {
hbQuery = ((org.hibernate.ejb.QueryImpl)query).getHibernateQuery();
hbQuery.setCacheable(true);
scenarios = hbQuery.list();
} else {
scenarios = query.getResultList();
}
Ehcache setting is having its default value maxElementsInMemory="10000". It has to be tuned according to the hits.
One way to do this is, You can increase maxElementsInMemory and check if you want to solve this by "Trial and error" method.
Other way (reliable) is that you have to publish the Mbeans and watch for the cache usage and cache misses in JConsole. According to the report you can increase 'maxElementsInMemory'. Please refer how you should do that in http://hibernate-jcons.sourceforge.net/usage.html
I write cache data to disk by adding "". It seems work well and I find some data in the directory. But I still not find the reason of why it still execute sql.
Related
Im developing a Jee webapp using JPA/Hibernate as ORM framework, PostgreSQL as db, and Tomcat as server.
When i start the app i want entitymanager to inject some data in my db.
I do that whith
<property name="javax.persistence.sql-load-script-source" value="META-INF/data.sql"/>
in persistence.xml
Everything works fine except that i get some bad encoding like "Ardèche" instead of "Ardèche".
My whole project is in utf-8, my database too.
I had encoding output problems in Intelli-j terminal with tomcat, that i managed to resolve using -Dfile.encoding=UTF-8 in Help | Edit Custom VM Options.
But my data in my db is still wrong, even if in Intelli-J output i get the good result.
If i execute the script straight into pgadmin there is no problem.
I tried everything i could find to solve that, but nothing worked.
I probably have conflict in the configuration now, cause i tried too many different stuff.
My persistence.xml
<properties>
<property name="javax.persistence.jdbc.driver" value="org.postgresql.Driver" />
<property name="javax.persistence.jdbc.url" value="jdbc:postgresql://localhost:5432/DB" />
<property name="javax.persistence.jdbc.user" value="db" />
<property name="javax.persistence.jdbc.password" value="" />
<property name="hibernate.connection.useUnicode" value="true" />
<property name="hibernate.connection.characterEncoding" value="UTF-8" />
<property name="hibernate.connection.charSet" value="UTF-8"/>
<property name="hibernate.show_sql" value="true" />
<property name="hibernate.hbm2ddl.auto" value="create" />
<property name="javax.persistence.sql-load-script-source" value="META-INF/data.sql"/>
<property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQL95Dialect"/>
<property name="hibernate.connection.autocommit" value="true" />
</properties>
It's my first message on stackoverflow so i hope i did everything properly !
Thanks !
thanks for your answer, i just managed to fix it by adding <property name="hibernate.hbm2ddl.charset_name" value="UTF-8"/> to persistence.xml. I didn't check enough the hibernate doc !
I am using 2.2.7.RELEASE version of Spring Batch in my project.
I have a batch which is using JdbcPagingItemReader to read records from DB2. In that I have a JOIN on 2 tables and have some where conditions. At the last I am providing column by which I want to sort my records. But because I am using table aliases, its giving me error. When skipping alias name, then its give problem while fetching the next set of result.
I searched and found that this issue got resolved in 2.1.9 Release but I couldn't find the fix in later releases. Anybody has any idea about this issue and the solution too.
You can find the code snippet of query configuration below.
<bean id="releaseSqlPagingQueryProvider" class="org.springframework.batch.item.database.support.SqlPagingQueryProviderFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="selectClause" value="SELECT M.* " />
<property name="fromClause" value="FROM MASTER AS M JOIN RELEASE AS R ON M.EMPLOYEE_ID = R.EMPLOYEE_ID " />
<property name="whereClause" >
<value>
<![CDATA[
WHERE R.COLUMN_1 = ?
]]>
</value>
</property>
<property name="sortKey" value="EMPLOYEE_ID" />
I am wondering if there is a place where we can configure -- how many characters can be searched on for a wildcard. I am using ATG 10.1.2 and Endeca 3.1.2
Currently I am facing an issue in OOTB CRS application, if I search for one character and a '*' (asterisk), the search returns results, however when I do the same with 3 or more characters from the returned results, no results are returned. It returns again after 5 chars and a *.
I am testing this on the auto suggest feature in CRS, also tested the same on the endeca jspref app, same behavior.
I have searched for any flags that can be used to alter the configuration, but there are none as per http://docs.oracle.com/cd/E29584_01/webhelp/IAPAdmin/toc.htm#Dgraph%20flags
Help is appreciated!
UPDATE
I found that the wild card search was not enabled at all. The search query reaching the MDEX contained the * but the results only appeared for exact matches or after auto correction.
FIX
When I found that wildcard search was not working, I changed my schema.csv to contain the dimensions with wildcardsearch set to true. but that didn't help until I changed my
fcm.context.xml
changed the part starting with the comment as described below ::
<!-- this encodes the property default values from the schema feed xls spreadsheet -->
<bean id="propertyTemplate" class="com.endeca.itl.fcm.beans.PropertyConfiguration">
<property name="language" value="${LANGUAGE_ID}" />
<property name="isSearchable" value="false" />
<property name="isWildcardSearchable" value="true" />
<property name="isSortable" value="false" />
<property name="isFilterable" value="false" />
<property name="showOnListPage" value="true" />
<property name="showOnDetailPage" value="true" />
<property name="enableForRollup" value="false" />
</bean>
now it's working fine.
I've just started working with activity and integrated it in my project (postgres based) in an embedded way (sample spring configuration file snip)
(...)
<!-- Activiti components -->
<bean id="processEngineConfiguration" class="org.activiti.spring.SpringProcessEngineConfiguration">
<property name="dataSource" ref="dataSource" />
<property name="transactionManager" ref="transactionManager" />
<property name="databaseSchemaUpdate" value="true" />
<property name="jobExecutorActivate" value="false" />
</bean>
<bean id="processEngine" class="org.activiti.spring.ProcessEngineFactoryBean">
<property name="processEngineConfiguration" ref="processEngineConfiguration" />
</bean>
<bean id="repositoryService" factory-bean="processEngine" factory-method="getRepositoryService" />
<bean id="runtimeService" factory-bean="processEngine" factory-method="getRuntimeService" />
<bean id="taskService" factory-bean="processEngine" factory-method="getTaskService" />
<bean id="historyService" factory-bean="processEngine" factory-method="getHistoryService" />
<bean id="managementService" factory-bean="processEngine" factory-method="getManagementService" />
(...)
It works well and create a lot of tables on my application schema at startup.
My problem is : tables are created in the 'public' schema in my postgres database. I would have preferred to put those tables in a separate schema, say 'activity'.
Fact is that after browsing the documentation / the net for almost two hours, I didn't found any way to change the default schema target creation behavior.
Any help... greatly appreciated ! ;)
Since Postgres 9.4 JDBC driver you can specify the default schema in the JDBC url like this:
jdbc:postgresql://localhost:5432/mydatabase?currentSchema=myschema
With this URL, all Activiti tables are created in the myschema schema instead of the default one in the search path, usually public.
Sources: this response on Stack Overflow and the latest documentation.
I am using mybatis 3.0.4 for a test against a mysql 5.5 database with mysql-connector JDBC driver, version 5.1.16.
The problem I am experiencing is that if I get a SqlSession via openSession() method and i retrieve data via a select from database, subsequent selects in same session are not aware of changes made (and committed) to database even if i call clearCache() on session. To concurrently modify database I am using Mysql command line client. Setting cacheEnabled as false in configuration file doesn't help too.
I enclose configuration file.
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configuration
PUBLIC "-//ibatis.apache.org//DTD Config 3.0//EN"
"http://ibatis.apache.org/dtd/ibatis-3-config.dtd">
<configuration>
<settings>
<setting name="lazyLoadingEnabled" value="false"/>
<setting name="cacheEnabled" value="false"/>
</settings>
<environments default="development">
<environment id="development">
<transactionManager type="JDBC" />
<dataSource type="POOLED">
<property name="poolMaximumIdleConnections" value="20"></property>
<property name="poolMaximumActiveConnections" value="80"></property>
<property name="poolMaximumCheckoutTime" value="600"></property>
<property name="poolTimeToWait" value="600"></property>
<property name="driver" value="com.mysql.jdbc.Driver"/>
<property name="url" value="jdbc:mysql://localhost:3306/testdb"/>
<property name="username" value="root"/>
<property name="password" value="password"/>
</dataSource>
</environment>
</environments>
<mappers>
<mapper resource="mappers/TestMapper.xml" />
</mappers>
</configuration>
Ok, solved by myself. It was not a mybatis issue, it depended on Transaction isolation on JDBC driver, which was by default TRANSACTION_REPEATABLE_READ, I needed TRANSACTION_READ_COMMITTED instead. Solved with:
getSessionFactory().openSession(TransactionIsolationLevel.READ_COMMITTED);