1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
|
CREATE TABLE `compEval`.`Domaine` (
`idDomaine` INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,
`libelleDomaine` VARCHAR(254),
`description` VARCHAR(254),
PRIMARY KEY (`idDomaine`)
)
ENGINE = InnoDB;
Voici le fichier de mapping :
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="com.toto.compEval.CompEval.Model">
<class name="Domaine" table="Domaine" catalog="compEval">
<id name="idDomaine" type="java.lang.Integer">
<column name="idDomaine" />
<generator class="identity" />
</id>
<property name="libelleDomaine" type="string">
<column name="libelleDomaine" length="254" />
</property>
<property name="description" type="string">
<column name="description" length="254" />
</property>
</class>
</hibernate-mapping>
Voici la méthode du DAO :
public class DomaineDao extends AbstractDAO implements IDomaineDao {
private static final Log log = LogFactory.getLog(DomaineDao.class);
private final SessionFactory sessionFactory = getSessionFactory();
public void persist(Domaine transientInstance) {
log.debug("persisting Domaine instance");
try {
getHibernateTemplate().save(transientInstance);
log.debug("persist successful");
} catch (RuntimeException re) {
log.error("persist failed", re);
throw re;
}
}
Voici la méthode lappelant dans la couche service :
public void saveDomaine(Domaine monDomaine)throws BusinessException{
try{
getDaoFactory().getDomaineDAO().persist(monDomaine);
}
catch (DAOException e) {
throw new BusinessException(e.getMessage());
}
}
Finalement, voici le fichier de la gestion des transactions :
<!-- - - - - - - - - - - Transaction manager - - - - - - - - - -->
<bean id="transactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
</bean>
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="get*" read-only="true"/>
<tx:method name="save*" rollback-for="Exception"
propagation="REQUIRED" />
<tx:method name="update*" rollback-for="Exception"
propagation="REQUIRED" />
</tx:attributes>
</tx:advice>
<aop:config proxy-target-class="true">
<aop:pointcut id="compEvalServiceMethods"
expression="within(*com.toto.compEval.CompEval.Services.*Service.*)" />
<aop:advisor advice-ref="txAdvice"
pointcut-ref="compEvalServiceMethods" />
</aop:config>
</beans> |
Partager