From 780300b8b3a4c23e26c46ba678a270d0b08d9069 Mon Sep 17 00:00:00 2001 From: eugenp Date: Sat, 18 May 2013 16:48:11 +0300 Subject: [PATCH] persistence work --- .../baeldung/spring/persistence/config/PersistenceConfig.java | 3 ++- .../spring/persistence/config/PersistenceXmlConfig.java | 3 +-- .../baeldung/spring/persistence/dao/AbstractHibernateDao.java | 4 ++-- .../java/org/baeldung/spring/persistence/dao/IOperations.java | 2 +- .../org/baeldung/spring/persistence/service/FooService.java | 2 ++ 5 files changed, 8 insertions(+), 6 deletions(-) diff --git a/spring-hibernate3/src/main/java/org/baeldung/spring/persistence/config/PersistenceConfig.java b/spring-hibernate3/src/main/java/org/baeldung/spring/persistence/config/PersistenceConfig.java index b59ea8e341..769f3132f5 100644 --- a/spring-hibernate3/src/main/java/org/baeldung/spring/persistence/config/PersistenceConfig.java +++ b/spring-hibernate3/src/main/java/org/baeldung/spring/persistence/config/PersistenceConfig.java @@ -7,6 +7,7 @@ import javax.sql.DataSource; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.PropertySource; import org.springframework.core.env.Environment; import org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor; @@ -17,7 +18,7 @@ import org.springframework.transaction.annotation.EnableTransactionManagement; import com.google.common.base.Preconditions; -// @Configuration +@Configuration @EnableTransactionManagement @PropertySource({ "classpath:persistence-mysql.properties" }) @ComponentScan({ "org.baeldung.spring.persistence.dao", "org.baeldung.spring.persistence.service" }) diff --git a/spring-hibernate3/src/main/java/org/baeldung/spring/persistence/config/PersistenceXmlConfig.java b/spring-hibernate3/src/main/java/org/baeldung/spring/persistence/config/PersistenceXmlConfig.java index d8791b6bcc..e38b57fbca 100644 --- a/spring-hibernate3/src/main/java/org/baeldung/spring/persistence/config/PersistenceXmlConfig.java +++ b/spring-hibernate3/src/main/java/org/baeldung/spring/persistence/config/PersistenceXmlConfig.java @@ -1,11 +1,10 @@ package org.baeldung.spring.persistence.config; import org.springframework.context.annotation.ComponentScan; -import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.ImportResource; import org.springframework.transaction.annotation.EnableTransactionManagement; -@Configuration +// @Configuration @EnableTransactionManagement @ComponentScan({ "org.baeldung.spring.persistence.dao", "org.baeldung.spring.persistence.service" }) @ImportResource({ "classpath:persistenceConfig.xml" }) diff --git a/spring-hibernate3/src/main/java/org/baeldung/spring/persistence/dao/AbstractHibernateDao.java b/spring-hibernate3/src/main/java/org/baeldung/spring/persistence/dao/AbstractHibernateDao.java index 0ff6307147..9a579245d3 100644 --- a/spring-hibernate3/src/main/java/org/baeldung/spring/persistence/dao/AbstractHibernateDao.java +++ b/spring-hibernate3/src/main/java/org/baeldung/spring/persistence/dao/AbstractHibernateDao.java @@ -33,9 +33,9 @@ public abstract class AbstractHibernateDao implements IO } @Override - public final long create(final T entity) { + public final void create(final T entity) { Preconditions.checkNotNull(entity); - return (Long) getCurrentSession().save(entity); + getCurrentSession().persist(entity); } @Override diff --git a/spring-hibernate3/src/main/java/org/baeldung/spring/persistence/dao/IOperations.java b/spring-hibernate3/src/main/java/org/baeldung/spring/persistence/dao/IOperations.java index d2cb0a9cef..51591c57b4 100644 --- a/spring-hibernate3/src/main/java/org/baeldung/spring/persistence/dao/IOperations.java +++ b/spring-hibernate3/src/main/java/org/baeldung/spring/persistence/dao/IOperations.java @@ -9,7 +9,7 @@ public interface IOperations { List findAll(); - long create(final T entity); + void create(final T entity); T update(final T entity); diff --git a/spring-hibernate3/src/main/java/org/baeldung/spring/persistence/service/FooService.java b/spring-hibernate3/src/main/java/org/baeldung/spring/persistence/service/FooService.java index 4983d99915..1d3b5c4a02 100644 --- a/spring-hibernate3/src/main/java/org/baeldung/spring/persistence/service/FooService.java +++ b/spring-hibernate3/src/main/java/org/baeldung/spring/persistence/service/FooService.java @@ -4,8 +4,10 @@ import org.baeldung.spring.persistence.dao.IFooDao; import org.baeldung.spring.persistence.model.Foo; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; @Service +@Transactional public class FooService { @Autowired