Hibernate is a de-facto standard object/relational persistence tool for Java. This partly explains the lack of other tools supported by PicoContainer Persistence.
The Persistence Hibernate module provides support for DI and lifecycle.
Let's walk through a typical use case: how to configure a
Hibernate persister using a given configuration file. We want the
hibernate configuration path to be configurable via a PicoContainer
script - let's say XML for the sake of this example, although of course
anything said for XML will hold for other scripts too. The hibernate.cfg.xml
will look something like
SessionFactory
that will be injected in the persister:
public class MyHibernatePersister { private SessionFactory factory; /** * Creates an MyHibernatePersister with a Hibernate SessionFactory * * @param factory the SessionFactory */ public MyHibernatePersister(SessionFactory factory){ this.factory = factory; } // ... your hibernate code }
MyEntity
@Entity @Table(name = "ENTITY") public class MyEntity { @Id @GeneratedValue(strategy = GenerationType.AUTO) private String id; @Column(name = "NAME", nullable = true) private String name; }
hibernate.cfg.xml
ConstructableAnnotationConfiguration
(and of course define the mapping manually via a hibernate.hbm.xml
file).