How to get logging info for HikariCP - hikaricp

Using Hibernate 4.3.1, Hikari 2.3.2.
I have configured this in the hibernate persistence xml
...
<property name="hibernate.hikari.leakDetectionThreshold" value="3000" />
<property name="hibernate.hikari.poolName" value="KikariTest" />
<property name="hibernate.hikari.registerMbeans" value="true" />
And this in my log4j.properties
log4j.logger.com.zaxxer.hikari=DEBUG
log4j.additivity.com.zaxxer.hikari=false
Im not seeing any logging information printed. Any ideas?

It took me a whole day to get this right! Turns out I was using log4j libs only, whereas a needed to include the slf4j libs.

I think you want log4j.additivity.com.zaxxer.hikari=true (or not set at all, left at default). additivity=false means don't inherit the parent's appender, which probably means there is no appender at all.

Remove theese jars from your classpath or lib directory if you have.
logback-classic-1.1.7.jar
logback-core-1.1.7.jar

Related

JPA 2-level caching

Sorry for a providing a less specific title. Actually I am in a mess.
My actual problem: To improve performance of the application.
Good Thing: The data is inserted/updated through JPA through out the application.
Technology used so far: Spring 3.2 framework with JPA 2.0 and hibernate 3.2.
So far we don't have a direct dependency on Hibernate anywhere in our code.
Coming back to the problem:
I am planing to implement 2nd level Query caching for some queries which always fetch same data (dropdown values).
My 1st question :Does JPA provides 2nd level caching by itself(without using EHcache or any such dependency)?
What I found so far is using this property we can enable 2nd level caching
query.setHint("org.hibernate.cacheable", true);
My 2nd Question: Do I need to provide dependency for Ehcache or Hibernate-Ehcache is enough?
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-ehcache</artifactId>
<version>4.0.0</version>
</dependency>
or should I also need to provide
<dependency>
<groupId>net.sf.ehcache</groupId>
<artifactId>ehcache-core</artifactId>
<version>${ehcacheVersion}</version>
</dependency>
My third question: What are the properties I need to add in my persistence.xml.
I am sure about these two properties:
<property name="hibernate.cache.use_query_cache" value="true"/>
<property name="hibernate.cache.use_second_level_cache" value="true"/>
=====Thanks for the answer.This is the update might help the fellow developers.====
I am putting down the properties needs to be defined for enabling EHcache as lots of people face this exception
Caused by: org.hibernate.cache.NoCachingEnabledException: Second-level cache is not enabled for usage [hibernate.cache.use_second_level_cache | hibernate.cache.use_query_cache]
because of property mismatch and dependency mismatch.
The following property should work for hibernate 4.x along with Ehcache 2.4.3
<property name="hibernate.cache.use_second_level_cache" value="true"/>
<property name="hibernate.cache.use_query_cache" value="true"/>
<property name="hibernate.generate_statistics" value="true"/>
<property name="hibernate.cache.provider_configuration_file_resource_path" value="classpath:ehcache.xml" />
<property name="hibernate.cache.region.factory_class" value="org.hibernate.cache.ehcache.SingletonEhCacheRegionFactory"/>
My 1st question :Does JPA provides 2nd level caching by itself (without
using EHcache or any such dependency)?
No, it doesn't. JPA is just a standard and doesn't provide any implementation. Hibernate provides implementation for JPA (EntityManager, EntityMangerFactory, etc) along with its own ORM implementation (Session, Session Factory, etc). Therefore, you need EHCache to support 2nd level cache. However, you can use JPA annotations/config for caching but that requires changes in persistence.xml.
Following two links explains each configuration options:
Caching using Hibernate specific classes/annotations.
Caching using JPA specific classes/annotations (with Hibernate as JPA provider)
My 2nd Question: Do I need to provide dependency for Ehcache or
Hibernate-Ehcache is enough?
You need to add ehcache-core, hibernate-ehcache and slf4j-simple (EHCache uses slf4j for logging). For dependencies details, check Hibernate EHCache Maven Dependencies section on this link.
My third question: What are the properties I need to add in my
persistence.xml.
If you go by JPA way, then the sample persistence.xml would be like:
<persistence-unit name="FooPu" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
...
<shared-cache-mode>ENABLE_SELECTIVE</shared-cache-mode>
<properties>
...
<property name="hibernate.cache.provider_class" value="org.hibernate.cache.SingletonEhCacheProvider"/>
<property name="hibernate.cache.use_second_level_cache" value="true"/>
<property name="hibernate.cache.use_query_cache" value="true"/>
</properties>
</persistence-unit>

Ignore persistence unit definitions that have PersistenceUnitTransactionType = RESOURCE_LOCAL

I have a Wildfly 8 container and an EAR with a persistence.xml inside. There are multiple persistence units defined.
Is there a way to ignore the process of the persistence unit definitions that have PersistenceUnitTransactionType = RESOURCE_LOCAL at the deployment of the EAR?
I was able to tell wildfly to ignore specific peristence-unit in peristence.xml by adding property
<properties>
<property name="jboss.as.jpa.managed" value="false" />
</properties>
So wildfly will not ignore all peristence-units with PersistenceUnitTransactionType=RESOURCE_LOCAL but all with the property set.

Interrogation about Yeoman, Maven and the location of Thymeleaf HTML templates

I recently discovered Yeoman, a tool that greatly facilitates JS dependency and build lifecycle management.
Furthermore, I use Maven as my Java dependency and build tool. I am actually seeking to integrate both tools so that I get the best of both worlds.
It seems the community has put a lot of effort into Maven/Yeoman integration with various articles such as this one: http://addyosmani.com/blog/making-maven-grunt/ as well as a yeoman-maven plugin: https://github.com/trecloux/yeoman-maven-plugin
Last, I use Thymeleaf as my Spring-MVC templating solution.
Assuming the following directory layout (see yeoman-maven-plugin above):
pom.xml
- src
- main
- java
- webapp
- …
- test
- ..
- yo
package.json
component.json
Gruntfile.js
- app
index.html
...
- test
...
- dist
...
My question is where should my Thymeleaf templates reside?
Under the yo/app directory? (they would be subsequently copied into appropriate directory by maven)
Directly under the src/main/webapp/WEB-INF/templates directory?
What I can't figure out in the case of an AngularJS application for instance, is when and how templates/pages including server-side content can interact with the servlet container given that Yeoman assumes they live under its app directory...
If you are using Thymeleaf as your templating engine with Spring, I assume you have something like
<bean id="templateResolver"
class="org.thymeleaf.templateresolver.ServletContextTemplateResolver">
<property name="prefix" value="/WEB-INF/templates/" />
<property name="suffix" value=".html" />
<property name="templateMode" value="HTML5" />
</bean>
<bean id="templateEngine"
class="org.thymeleaf.spring3.SpringTemplateEngine">
<property name="templateResolver" ref="templateResolver" />
</bean>
<bean class="org.thymeleaf.spring3.view.ThymeleafViewResolver">
<property name="templateEngine" ref="templateEngine" />
</bean>
In other words, your templates should reside in the folder specified in the ServletContextTemplateResolver property prefix. In the above example, that's /WEB-INF/templates. These should therefore be in /src/main/webapp/WEB-INF/templates.
If you are not using a ServletContextTemplateResolver, but instead using a ClassLoaderTemplateResolver, you can put them anywhere on your application classpath and specify it in that bean's properties. There's also a FileTemplateResolver in which you can specify an absolute path to anywhere on your file system.
When building the application with Eclipse (maven plugin), having the folders
/src
/main
/webapp
/WEB-INF
/templates
/some-template.html
/index.html
/java
/com
/yourcompany
/Main.java
/resources
/some-properties.properties
maven will generate the following
/WEB-INF
/templates
/some-template.html
/index.html
/classes
/com
/yourcompany
/Main.class
/some-properties.properties
As a expanded .war and provide that to your servlet container, ex. Tomcat.

which jar be responsible for parsing hibernate.cfg.xml?

I met a configuration problem like below:
when I am executing example by hibernate tool
After I have write
<session-factory>
<property name="hibernate.connection.driver_class">org.hsqldb.jdbcDriver</property>
<property name="hibernate.connection.url">jdbc:hsqldb:hsql://127.0.0.1</property>
<property name="hibernate.connection.username">sa</property>
<property name="connection.password"></property>
<property name="connection.pool_size">1</property>
<property name="hibernate.dialect"> org.hibernate.dialect.HSQLDialect</property>
<property name="show_sql">true</property>
<property name="hbm2ddl.auto">create</property>
<mapping?resource="com/vaannila/course/Course.hbm.xml"/>
<session-factory>
and open HSQLDB connection(using java -cp ./lib/hsqldb.jar org.hsqldb.Server and java -cp ./lib/hsqldb.jar org.hsqldb.util.DatabaseManager), when I use Hibernate Code Generation in Eclipse, why it pop up the error message:
In former step for the jar, instead of using package slf4j* ,I have used log4j, and I remember I have not include the changed jar to my classpath as vannilla required, do it have affects for the error? thanks first :)
hibernate3.jar is responsible for parsing hibernate.cfg.xml.
<property? //wrong
<property> //correct
Those question marks in <property?name.. are wrong - they should not be there. Remove them and try again.
If the ? characters aren't visible in your editor, they are probably some other unicode space character which the XML parser doesn't recognise. You'll have to select each one and re-type a space character. ( maybe?). Did you copy an example configuration from a web page?

JBoss Microcontainer + AOP in a standalone app

I'm trying to create a standalone app using JBoss Microcontainer for IoC and JBoss AOP for, well, AOP.
I've boot-strapped, deployed a descriptor with AOP XML, so far so good.
But the aspect is not performed. Do I need to enable AOP plugin or something?
Note that I don't want to add a build step - I want it to work like Spring AOP.
Please check the code below.
Thanks for help.
<deployment xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="urn:jboss:bean-deployer:2.0 bean-deployer_2_0.xsd"
xmlns="urn:jboss:bean-deployer:2.0"
xmlns:aop="urn:jboss:aop-beans:1.0">
<bean name="myGarage" class="jbmctest.Garage">
<property name="car">
<bean name="myCar" class="jbmctest.Car">
<property name="name">Red Devil</property>
</bean>
</property>
</bean>
<aop:interceptor name="FuelInterceptor" class="jbmctest.FuelInterceptor"/>
<aop:bind pointcut="execution(* *->*(..)">
<aop:interceptor-ref name="FuelInterceptor"/>
</aop:bind>
</deployment>
You're missing the pieces that are in aop.xml in JBossAS5 -> conf/bootstrap/aop.xml.
I've eventually solved this, and wrote an article for those who will try the same.
http://ondra.zizka.cz/stranky/programovani/java/jboss-aop-howto-example-standalone-app.texy