Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @Bean
- public DataSource dataSource() {
- BasicDataSource dataSource = new BasicDataSource();
- dataSource.setDriverClassName("com.mysql.jdbc.Driver");
- dataSource.setUrl("jdbc:mysql://localhost:3306/new");
- dataSource.setUsername("root");
- dataSource.setPassword("root");
- return dataSource;
- }
- private final Properties hibernateProperties() {
- Properties hibernateProperties = new Properties();
- //properties hibernateProperties.setProperty()
- return hibernateProperties;
- }
- @Bean
- public LocalSessionFactoryBean sessionFactory() throws ClassNotFoundException {
- LocalSessionFactoryBean sessionFactory = new LocalSessionFactoryBean();
- sessionFactory.setDataSource(dataSource());
- sessionFactory.setPackagesToScan("mypackages");
- sessionFactory.setHibernateProperties(hibernateProperties());
- return sessionFactory;
- }
- @Bean
- public PlatformTransactionManager hibernateTransactionManager() throws ClassNotFoundException {
- HibernateTransactionManager transactionManager
- = new HibernateTransactionManager();
- transactionManager.setSessionFactory(sessionFactory().getObject());
- return transactionManager;
- }
- @Repository
- public class EqualOpsDAOImpl implements EqualOpsDAO {
- @Autowired
- private SessionFactory sessionFactory;
- public List<EqualOps> getEqualOps() {
- //get the current hibernate session
- Session currentSession = sessionFactory.getCurrentSession();
- //create query
- Query<EqualOps> theQuery = currentSession.createQuery("from EqualOps", EqualOps.class);
- //exercuty qry and get result
- List<EqualOps> equalOps = theQuery.getResultList();
- //return result
- return equalOps;
- }
- }
Add Comment
Please, Sign In to add comment