Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @Component
- public class HItemStorage implements Storage {
- private final HibernateTemplate template;
- @Autowired
- public HItemStorage(HibernateTemplate template) {
- this.template = template;
- }
- @Override
- public List<Item> getAll() {
- return (List<Item>) template.find("from Item");
- }
- ...
- }
- <?xml version="1.0" encoding="UTF-8" ?>
- <beans xmlns="http://www.springframework.org/schema/beans"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xmlns:context="http://www.springframework.org/schema/context"
- xsi:schemaLocation= "http://www.springframework.org/schema/beans
- http://www.springframework.org/schema/beans/spring-beans.xsd
- http://www.springframework.org/schema/context
- http://www.springframework.org/schema/context/spring-context.xsd">
- <!-- Database properties -->
- <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
- <property name="driverClassName" value="org.postgresql.Driver" />
- <property name="url" value="jdbc:postgresql://127.0.0.1:5432/spring_jdbc" />
- <property name="username" value="postgres" />
- <property name="password" value="1" />
- </bean>
- <!-- Connecting template -->
- <bean id="template" class="org.springframework.orm.hibernate5.LocalSessionFactoryBean">
- <property name="dataSource" ref="dataSource" />
- <property name="mappingResources">
- <list>
- <value>ru/pravvich/Item.hbm.xml</value>
- </list>
- </property>
- <!-- Hibernate properties -->
- <property name="hibernateProperties">
- <props>
- <prop key="hibernate.dialect">org.hibernate.dialect.PostgreSQL94Dialect</prop>
- <prop key="hibernate.hbm2ddl.auto">update</prop>
- <prop key="hibernate.show_sql">true</prop>
- </props>
- </property>
- </bean>
- <context:component-scan base-package="ru.pravvich" />
- </beans>
- final ClassPathXmlApplicationContext context =
- new ClassPathXmlApplicationContext("hibernate-context.xml");
- HItemStorage storage = context.getBean(HItemStorage.class);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement