En este post vamos a crear un proyecto que nos permita traernos de una base de datos mySql un listado de coches. Las tecnologías que vamos a utilizar son Maven para la gestión de dependencias del proyecto, JPA para interactuar con la base de datos, Spring para definir el contexto de nuestra aplicación además de unir todo, y finalmente JUnit para realizar un test de nuestra aplicación.
Read the rest of this entry »
Me gusta:
Me gusta Cargando...
Etiquetas: EntityManager, Hibernate, JPA, Junit, Maven, Spring, STS
Para este post he seguido el artículo Don’t repeat the DAO de Per Mellqvist.
El patrón DAO indica que por cada clase de dominio (entidad) que tengamos necesitamos crear un DAO (Data Access Object) que se encargue de persistir o buscar en base de datos la información. ¿Cuál es el inconveniente?. Pues que para todas las entidades van a existir una serie de operaciones básicas (CRUDs) y operaciones de búsqueda que van a ser comunes para cualquier entidad. En Hibernate podemos solucionar esto en parte utilizando las operaciones de sesión CRUD. El problema de ésto es que perdemos la seguridad de tipos en las operaciones por lo que tendremos que estar continuamente haciendo casting a dichas operaciones.
Read the rest of this entry »
Me gusta:
Me gusta Cargando...
Etiquetas: Dao, Hibernate, J2EE, Junit, Spring
This is the third way we mentioned in this parent post of creating java domain objects, or data access objects, mapping files.
We need to create an Ant task within our build.xml file in order to generate our domain objects, daos or xml mapping files.
Once this is done, we have to execute ant hbm (our task name) and our files will be generated. Notice that you need to include a reference to every library we are going to use (hibernate-tools, freemarker, log libraries, …).
Read the rest of this entry »
Me gusta:
Me gusta Cargando...
Etiquetas: ant, Hibernate, hibernate tools, Java
This is the second way we mentioned in this parent post of creating java domain objects, or data access objects, mapping files. The Hibernate 3 Maven plugin webpage show us which goals are available for this plugin. In this post we are going to use the following four ones:
- hibernate3:hbm2cfgxml: Generates hibernate.cfg.xml.
- hibernate3:hbm2hbmxml: Generates a set of hbm.xml files.
- hibernate3:hbm2java: Generates Java domain objects.
- hibernate3:hbm2dao: Generates data access objects.
Read the rest of this entry »
Me gusta:
Me gusta Cargando...
Etiquetas: Hibernate, hibernate tools, Java, Maven, STS
Hibernate Tools is a toolset for Hibernate3 implemented as an integrated suite of Eclipse plugins, together with a unified Ant task for integration into the build cycle. Hibernate Tools is a core component of JBoss Tools and hence also part of JBoss Developer Studio.
The previous paragraph is the definition of Hibernate tools that you can find in the Hibernate official webpage. This post is going to show you how to generate your domain Java classes from the database schema using 3 different perspectives:
Read the rest of this entry »
Me gusta:
Me gusta Cargando...
Etiquetas: ant, freemarker, Hibernate, hibernate tools, Java, Maven, mysql