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

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?

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>

How to get logging info for 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

Bold not working in Jaspersoft Studio for fonts other than sans serif

In Jaspersoft Studio I have created a report where I want to display title in bold. If I use sans serif font then it is working correctly. If I use other fonts, bold is displayed in the preview of Jaspersoft Studio, but is not showing when the report is run in the Jasper server.
Please help.
Adding maven artifact worked for me
<dependency>
<groupId>net.sf.jasperreports</groupId>
<artifactId>jasperreports-fonts</artifactId>
<version>6.16.0</version>
</dependency>
You need to create a jasper fonts extension jar and place it into your classpath both compile-time (while compiling the jrxmls) as well as run-time (while running reports). Here is how the jar (e.g. jasperreports-fonts-5.5.2.jar) should look:
The jasperreports_extension.properties should contain few properties to initialize fonts. (I have used spring based fonts initialization. You might need to add couple of spring jars like spring-core, spring-beans etc. to your classpath if not already present.)
net.sf.jasperreports.extension.registry.factory.fonts=net.sf.jasperreports.extensions.SpringExtensionsRegistryFactory
net.sf.jasperreports.extension.fonts.spring.beans.resource=fonts/fonts_def.xml
Now the fonts.xml to defined what fonts you want to add.
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
<bean id="fontBean001" class="net.sf.jasperreports.engine.fonts.SimpleFontFamily">
<property name="name" value="Tahoma"/>
<property name="normal" value="fonts/Tahoma.ttf"/>
<property name="bold" value="fonts/Tahoma_Bold.ttf"/>
<property name="pdfEmbedded" value="true"/>
</bean>
<bean id="fontBean002" class="net.sf.jasperreports.engine.fonts.SimpleFontFamily">
<property name="name" value="Arial"/>
<property name="normal" value="fonts/Arial.ttf"/>
<property name="bold" value="fonts/Arial_Bold.ttf"/>
<property name="italic" value="fonts/Arial_Italic.ttf"/>
<property name="boldItalic" value="fonts/Arial_Bold_Italic.ttf"/>
<property name="pdfEmbedded" value="true"/>
</bean>
</beans>
Note the property "pdfEmbedded" is "true". Finally add the .ttf file for the fonts you want to add to jar.
Just go to this site for adding your custom fonts to PDF with Jasper:
Custom Font with the Font Extension
There's an illustrated guide showing you how to create it. Just download a *.ttf file for your font (eg.: Arial.ttf.)
Create the extension and export it as a *.jar file with the help of Eclipse.
Finally add the *.jar to your project. That's it.

PropertyPlaceholderConfigurer works from Maven command line, but not from Eclipse?

I have Eclipse configured to use an external maven instance. Nonetheless I have an integration test that runs fine from the command line, but fails from within Eclipse. The error is a class Spring application context bean error:
Cannot convert value of type [java.lang.String] to required type
The culprit it a bean that sets property values using a PropertyPlaceholderConfigurer.
<!-- property settings for non-JNDI database connections -->
<bean id="placeholderConfigUuid" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="systemPropertiesModeName" value="SYSTEM_PROPERTIES_MODE_OVERRIDE" />
<property name="location" value="classpath:database.properties" />
<property name="placeholderPrefix" value="$DS{" />
</bean>
I know which bean is failing because it appears in the stack trace and because when I replace the $DS{hibernate.dialect} with a static value it works.
EDIT: Here is where the property values are used:
<bean id="myTestLocalEmf" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="persistenceUnitName" value="myapp-core" />
.......ommitted for brevity.......
<property name="jpaVendorAdapter">
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
<property name="showSql" value="true" />
<!-- The following use the PropertyPlaceholderConfigurer but it doesn't work in Eclipse -->
<property name="database" value="$DS{hibernate.database}" />
<property name="databasePlatform" value="$DS{hibernate.dialect}" />
</bean>
</property>
</bean>
I have two questions:
1) Since M2Eclipse is using the same Maven setup as the command line, why does one work and the other fail?
2) How to fix this? I really like the ability to run a single jUnit test from within Eclipse on demand.
Does filtering work for a "regular" unit test under Eclipse?
Is m2eclipse configured to process resources and tests resources on resource changes:
alt text http://www.imagebanana.com/img/rwd919ek/screenshot_008.png
Is there anything particular to mention about your integration tests (from a Maven point of view)?
You are using M2Eclipse (up-to-date release?) you are using Maven 3 inside Eclipse, but i assume you are using Maven 2 (2.2.1?) on command line...On the other side you are saying that your "Integration test" is running on command line (build an environment etc.) but you would like to run "Unit Test" from within Eclipse...A Unit Test is different from an integration test...and i'm not astonished that you integration test does not work from Eclipse...May be we can say more if we see the POM's which are used and the code?

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