Advertisement
Guest User

Untitled

a guest
Aug 13th, 2017
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.22 KB | None | 0 0
  1. @Component
  2. public class HItemStorage implements Storage {
  3.  
  4. private final HibernateTemplate template;
  5.  
  6. @Autowired
  7. public HItemStorage(HibernateTemplate template) {
  8. this.template = template;
  9. }
  10.  
  11. @Override
  12. public List<Item> getAll() {
  13. return (List<Item>) template.find("from Item");
  14. }
  15. ...
  16. }
  17.  
  18. <?xml version="1.0" encoding="UTF-8" ?>
  19. <beans xmlns="http://www.springframework.org/schema/beans"
  20. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  21. xmlns:context="http://www.springframework.org/schema/context"
  22. xsi:schemaLocation= "http://www.springframework.org/schema/beans
  23. http://www.springframework.org/schema/beans/spring-beans.xsd
  24. http://www.springframework.org/schema/context
  25. http://www.springframework.org/schema/context/spring-context.xsd">
  26.  
  27. <!-- Database properties -->
  28. <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
  29. <property name="driverClassName" value="org.postgresql.Driver" />
  30. <property name="url" value="jdbc:postgresql://127.0.0.1:5432/spring_jdbc" />
  31. <property name="username" value="postgres" />
  32. <property name="password" value="1" />
  33. </bean>
  34.  
  35. <!-- Connecting template -->
  36. <bean id="template" class="org.springframework.orm.hibernate5.LocalSessionFactoryBean">
  37. <property name="dataSource" ref="dataSource" />
  38.  
  39. <property name="mappingResources">
  40. <list>
  41. <value>ru/pravvich/Item.hbm.xml</value>
  42. </list>
  43. </property>
  44.  
  45. <!-- Hibernate properties -->
  46. <property name="hibernateProperties">
  47. <props>
  48. <prop key="hibernate.dialect">org.hibernate.dialect.PostgreSQL94Dialect</prop>
  49. <prop key="hibernate.hbm2ddl.auto">update</prop>
  50. <prop key="hibernate.show_sql">true</prop>
  51. </props>
  52. </property>
  53. </bean>
  54.  
  55. <context:component-scan base-package="ru.pravvich" />
  56.  
  57. </beans>
  58.  
  59. final ClassPathXmlApplicationContext context =
  60. new ClassPathXmlApplicationContext("hibernate-context.xml");
  61.  
  62. HItemStorage storage = context.getBean(HItemStorage.class);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement