Seasar DI Container with AOP

This document is for S2Hibernate-JPA 1.0.1


S2Hibernate-JPA has the following features.



  • Import project
  • S2Hibernate-JPA requires JDK5 or later.
    Download Seasar2 in advance and import it into workspace as a java project in Eclipse.
    Import the s2hibernate-jpa directory extracted from into workspace as a java project in Eclipse.

  • Required jar file
  • Files necessary to use S2Hibernate-JPA are included in the s2hibernate/lib directory. Also, Seasar2 jar files are required.
    When some connection pooling or cache implementation not included in S2Hibernate3 is required, download it from

  • Classpath
  • To use S2Hibernate-JPA, add to the CLASSPATH *.jar files under the lib directory (except h2-1.0.20070429.jar) and resources(j2ee.dicon, s2hibernate-jpa.dicon,, META-INF/persistence.xml). If S2Hibernate-JPA files are imported to an Eclipse workspace, it is not necessary to add these files to the CLASSPATH.

  • Database
  • H2 Database Engine is included to try out S2Hibernate-JPA. h2-1.0.20070429.jar is necessary to execute H2 Database Engine but is unnecessary in a production environment which does not use H2 Database Engine.

Basic Usage

To apply the S2Hibernate to the project, entity, Dao(.java) and dicon files are required.


Create entities following the Persistence API specifications.

Dao(Data Access Object)

Dao implementation

  1. Define the EntityManager type field.
    private EntityManager entityManager;
  2. Define the setter method or constructor to accept the implementation object.
    public void setEntityManager(EntityManager entityManager) { 
    	this.entityManager = entityManager;
  3. Use the EntityManager in each method.
  4. public Employee getEmployee(int empno) {
        return entityManager.find(Employee.class, 7788);

dicon files

incluede j2ee.dicon and s2hibernate-jpa.dicon.


Create the 'resources/META-INF' in the CLASSPATH directory. In the META-INF directory, place the persistence.xml as follows.

<?xml version="1.0" encoding="UTF-8"?>
	<persistence-unit name="em" transaction-type="JTA">
			<property name="hibernate.dialect" 
			<property name="hibernate.jndi.class" 
			<property name="hibernate.transaction.manager_lookup_class" 
			<property name="hibernate.show_sql" 
			<property name="hibernate.format_sql" 
			<property name="hibernate.use_sql_comments"