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
|
public static void main(String[] args) {
try {
// Fichiers de config
String[] config = { "/WebContent/WEB-INF/applicationContext.xml", "/WebContent/WEB-INF/applicationContext-hibernate.xml", "/WebContent/WEB-INF/applicationContext-security.xml" };
ApplicationContext context = new FileSystemXmlApplicationContext(config);
SessionFactory sessionFactory = (SessionFactory) context.getBean("sessionFactory");
Session session = SessionFactoryUtils.getSession(sessionFactory, true);
SessionHolder holder = new SessionHolder(session);
TransactionSynchronizationManager.bindResource(sessionFactory,holder);
PersonneManager personneManager = (PersonneManager) (context.getBean("personneManager"));
Personne pers = personneManager.getPersonneById(12);
System.out.println(pers.getNom());
Adresse adr =pers.getAdresse();
System.out.println(adr.getNomRue());
session.flush();
TransactionSynchronizationManager.unbindResource(sessionFactory);
SessionFactoryUtils.releaseSession(session, sessionFactory);
} catch (BeansException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} |
Partager