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.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" })
|
||||
|
|
|
@ -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" })
|
||||
|
|
|
@ -33,9 +33,9 @@ public abstract class AbstractHibernateDao<T extends Serializable> 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
|
||||
|
|
|
@ -9,7 +9,7 @@ public interface IOperations<T extends Serializable> {
|
|||
|
||||
List<T> findAll();
|
||||
|
||||
long create(final T entity);
|
||||
void create(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.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
@Service
|
||||
@Transactional
|
||||
public class FooService {
|
||||
|
||||
@Autowired
|
||||
|
|
Loading…
Reference in New Issue