Advertisement
Guest User

Untitled

a guest
Aug 11th, 2016
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.62 KB | None | 0 0
  1. août 11, 2016 4:13:51 PM org.springframework.context.support.ClassPathXmlApplicationContext prepareRefresh
  2. INFOS: Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@68de145: startup date [Thu Aug 11 16:13:51 CEST 2016]; root of context hierarchy
  3. août 11, 2016 4:13:51 PM org.springframework.beans.factory.xml.XmlBeanDefinitionReader
  4.  
  5. <?xml version="1.0" encoding="UTF-8"?>
  6. <beans xmlns="http://www.springframework.org/schema/beans"
  7. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  8. xmlns:aop="http://www.springframework.org/schema/aop"
  9. xmlns:tx="http://www.springframework.org/schema/tx"
  10. xmlns:context="http://www.springframework.org/schema/context"
  11. xsi:schemaLocation="
  12. http://www.springframework.org/schema/beans
  13. http://www.springframework.org/schema/beans/spring-beans.xsd
  14. http://www.springframework.org/schema/tx
  15. http://www.springframework.org/schema/tx/spring-tx.xsd
  16. http://www.springframework.org/schema/aop
  17. http://www.springframework.org/schema/aop/spring-aop.xsd
  18. http://www.springframework.org/schema/context
  19. http://www.springframework.org/schema/context/spring-context.xsd">
  20.  
  21.  
  22. <context:component-scan base-package="Dao"></context:component-scan>
  23.  
  24. <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
  25. <property name="driverClassName" value="com.mysql.jdbc.Driver"/>
  26. <property name="url" value="jdbc:mysql://localhost:3306/project?useSSL=false"/>
  27. <property name="username" value="root"/>
  28. <property name="password" value=""/>
  29. </bean>
  30.  
  31. <bean id="factory" class="org.springframework.orm.hibernate5.LocalSessionFactoryBean">
  32. <property name="dataSource" ref="dataSource"/>
  33. <property name="hibernateProperties">
  34. <props>
  35. <prop
  36. key="hibernate.dialect">org.hibernate.dialect.MySQL5Dialect</prop>
  37. <prop key="hibernate.show_sql">true</prop>
  38. </props>
  39. </property>
  40. <property name="annotatedClasses">
  41. <list>
  42. <value>Dao.ActionDao</value>
  43. <value>mapping.Action</value>
  44. </list>
  45. </property>
  46. </bean>
  47.  
  48. <bean id="transactionManager"
  49. class="org.springframework.orm.hibernate5.HibernateTransactionManager">
  50. <property name="sessionFactory" ref="factory"/>
  51. </bean>
  52. <tx:annotation-driven transaction-manager="transactionManager"/>
  53.  
  54. </beans>
  55.  
  56. package Dao;
  57.  
  58. import java.util.List;
  59.  
  60. import org.hibernate.Criteria;
  61. import org.hibernate.Session;
  62. import org.hibernate.SessionFactory;
  63. import org.hibernate.cfg.Configuration;
  64. import org.hibernate.criterion.Restrictions;
  65. import org.springframework.beans.factory.annotation.Autowired;
  66. import org.springframework.stereotype.Repository;
  67. import org.springframework.transaction.annotation.Transactional;
  68.  
  69. import mapping.Action;
  70.  
  71. @Repository
  72. @Transactional
  73. public class ActionDao {
  74.  
  75.  
  76. private SessionFactory factory;
  77.  
  78.  
  79.  
  80. public Action getById(int id)
  81. {Session session=factory.getCurrentSession();
  82.  
  83. return (Action) session.get(Action.class, id);
  84. }
  85.  
  86. @SuppressWarnings("unchecked")
  87. public List<Action> selectAll(){
  88. List<Action> theActions = factory.getCurrentSession().createQuery("from Action").getResultList();
  89. return theActions;
  90. }
  91.  
  92. public void saveorupdate(Action contact)
  93. {
  94. factory.getCurrentSession().saveOrUpdate(contact);
  95. }
  96.  
  97. public void delete(int id)
  98. {
  99. Action c = getById(id);
  100. factory.getCurrentSession().delete(c);
  101. }
  102.  
  103. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement