Tuesday, January 6, 2009

Brazilian Waxing In Ottawa And Hard Wax Reviews

Spring + Hibernate - migration from XML to annotations

eating lots of time has passed since my last post (prosaic reason - I was free :) plans for December were huge - the development of the blog, refine framework on which I work, etc., etc. .. As you can see in December did not show up, not a single post, so those glorious plans lay in ruins. Succeeded But I settle a few other useful things. It turns out that you can save more time conducting regular life (work, etc.). I hope that now I can write more about my struggle with Java;)

For things so - today, we modify the project written with Spring and Hibernate. The modification will be to phase out the files. HBM and introducing in their place annotations. I will not describe the way adnotowania entity, because I recognize that there is nothing particularly difficult (maybe with the exception of some specific elements XML'owego description of the mapping). This is what I want to describe the configuration steps that will allow the operation of annotations in the project.

Step 1 - add the required libraries
to the project, add the following JAR file:
  • - hibernate-annotations.jar
  • - hibernate-commons-annotations.jar
  • - slf4j-api-1.5.6jar
  • - slf4j-1.5.6.jar-log4j12
  • - ejb3-persistence.jar
important that both SPRING slf4j were in the same version - otherwise we can expect interesting bugs:)

Step 2 - The modification in the context of Spring
1) Change the class SessionFactory
 \u0026lt;bean id="sessionFactory" 
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">

the
 \u0026lt;bean id = "SessionFactory" 
class = "org. springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean ">


2) Add the following entry:
 \u0026lt;property name="configurationClass"> 
\u0026lt;value> org.hibernate.cfg.AnnotationConfiguration \u0026lt;/ value>
\u0026lt;/ property>


3) we list the class described by phrases:
 \u0026lt;property name="annotatedClasses"> 
\u0026lt;list>
\u0026lt;value> pl.kadamczyk.model.User \u0026lt;/ value>
\u0026lt;/ list>
\u0026lt;/ property>


What is important some classes in the project can be described with annotations, and the remainder XMLem since, in addition annotatedClasses properties can also include property such as mappingDirectoryLocations allowing a directory containing the files.