跳至主要内容

博文

目前显示的是 十一月, 2013的博文

Modeling with Doctrine

Modeling with Doctrine In this post, we try to use   Doctrine   to make the models richer, and make it more like a real world application. Overview Imagine there are several models in this application,   Album ,   Artist ,   Song ,   Person . An   Artist   could compose many   Album s. An   Album   could be accomplished by more than one   Artist . An   Album   includes several   Song s. An   Artist   is a generalized   Person . In Doctrine ORM, it is easy to describe the relation between models. Album   and   Artist   is a   ManyToMany   relation. Album   and   Song   is a   OneToMany   relation. Artist   is inherited from   Person . Codes of Models The code of   Album   class. /** * @ORM\Entity */ class Album { /** * @ORM\Id * @ORM\GeneratedValue(strategy="AUTO") * @ORM\Column(type="integer") */ private $id; /** @ORM\Column(type="string") */ private $title; /** * @ORM\ManyToMa

Auditing with Hibernate Envers

Auditing with Hibernate Envers The approaches provided in JPA lifecyle hook and Spring Data auditing only track the creation and last modification info of an Entity, but all the modification history are not tracked. Hibernate Envers fills the blank table. Since Hibernate 3.5, Envers is part of Hibernate core project. Configuration Configure Hibernate Envers in your project is very simple, just need to add   hibernate-envers   as project dependency. <dependency> <groupId>org.hibernate</groupId> <artifactId>hibernate-envers</artifactId> </dependency> Done. No need extra Event listeners configuration as the early version. Basic Usage Hibernate Envers provides a simple   @Audited   annotation, you can place it on an Entity class or property of an Entity. @Audited private String description; If   @Audited   annotation is placed on a property, this property can be tracked. @Entity @Audited public class Signup implements Serializa