persistence work
This commit is contained in:
parent
ecaeb5e871
commit
780300b8b3
@ -7,6 +7,7 @@ import javax.sql.DataSource;
|
|||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.ComponentScan;
|
import org.springframework.context.annotation.ComponentScan;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
import org.springframework.context.annotation.PropertySource;
|
import org.springframework.context.annotation.PropertySource;
|
||||||
import org.springframework.core.env.Environment;
|
import org.springframework.core.env.Environment;
|
||||||
import org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor;
|
import org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor;
|
||||||
@ -17,7 +18,7 @@ import org.springframework.transaction.annotation.EnableTransactionManagement;
|
|||||||
|
|
||||||
import com.google.common.base.Preconditions;
|
import com.google.common.base.Preconditions;
|
||||||
|
|
||||||
// @Configuration
|
@Configuration
|
||||||
@EnableTransactionManagement
|
@EnableTransactionManagement
|
||||||
@PropertySource({ "classpath:persistence-mysql.properties" })
|
@PropertySource({ "classpath:persistence-mysql.properties" })
|
||||||
@ComponentScan({ "org.baeldung.spring.persistence.dao", "org.baeldung.spring.persistence.service" })
|
@ComponentScan({ "org.baeldung.spring.persistence.dao", "org.baeldung.spring.persistence.service" })
|
||||||
|
@ -1,11 +1,10 @@
|
|||||||
package org.baeldung.spring.persistence.config;
|
package org.baeldung.spring.persistence.config;
|
||||||
|
|
||||||
import org.springframework.context.annotation.ComponentScan;
|
import org.springframework.context.annotation.ComponentScan;
|
||||||
import org.springframework.context.annotation.Configuration;
|
|
||||||
import org.springframework.context.annotation.ImportResource;
|
import org.springframework.context.annotation.ImportResource;
|
||||||
import org.springframework.transaction.annotation.EnableTransactionManagement;
|
import org.springframework.transaction.annotation.EnableTransactionManagement;
|
||||||
|
|
||||||
@Configuration
|
// @Configuration
|
||||||
@EnableTransactionManagement
|
@EnableTransactionManagement
|
||||||
@ComponentScan({ "org.baeldung.spring.persistence.dao", "org.baeldung.spring.persistence.service" })
|
@ComponentScan({ "org.baeldung.spring.persistence.dao", "org.baeldung.spring.persistence.service" })
|
||||||
@ImportResource({ "classpath:persistenceConfig.xml" })
|
@ImportResource({ "classpath:persistenceConfig.xml" })
|
||||||
|
@ -33,9 +33,9 @@ public abstract class AbstractHibernateDao<T extends Serializable> implements IO
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final long create(final T entity) {
|
public final void create(final T entity) {
|
||||||
Preconditions.checkNotNull(entity);
|
Preconditions.checkNotNull(entity);
|
||||||
return (Long) getCurrentSession().save(entity);
|
getCurrentSession().persist(entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -9,7 +9,7 @@ public interface IOperations<T extends Serializable> {
|
|||||||
|
|
||||||
List<T> findAll();
|
List<T> findAll();
|
||||||
|
|
||||||
long create(final T entity);
|
void create(final T entity);
|
||||||
|
|
||||||
T update(final T entity);
|
T update(final T entity);
|
||||||
|
|
||||||
|
@ -4,8 +4,10 @@ import org.baeldung.spring.persistence.dao.IFooDao;
|
|||||||
import org.baeldung.spring.persistence.model.Foo;
|
import org.baeldung.spring.persistence.model.Foo;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
|
@Transactional
|
||||||
public class FooService {
|
public class FooService {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
|
Loading…
x
Reference in New Issue
Block a user