further config
This commit is contained in:
parent
480edf4a3c
commit
38803691b9
|
@ -29,16 +29,22 @@
|
|||
|
||||
<!-- persistence -->
|
||||
|
||||
<!-- <dependency> -->
|
||||
<!-- <groupId>org.hibernate</groupId> -->
|
||||
<!-- <artifactId>hibernate-entitymanager</artifactId> -->
|
||||
<!-- <version>4.2.1.Final</version> -->
|
||||
<!-- </dependency> -->
|
||||
<dependency>
|
||||
<groupId>org.hibernate</groupId>
|
||||
<artifactId>hibernate-entitymanager</artifactId>
|
||||
<version>4.2.1.Final</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.hibernate</groupId>
|
||||
<artifactId>hibernate-core</artifactId>
|
||||
<version>4.2.1.Final</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>mysql</groupId>
|
||||
<artifactId>mysql-connector-java</artifactId>
|
||||
<version>5.1.25</version>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
|
||||
<!-- utils -->
|
||||
|
||||
|
|
|
@ -8,17 +8,19 @@ 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;
|
||||
import org.springframework.jdbc.datasource.DriverManagerDataSource;
|
||||
import org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean;
|
||||
import org.springframework.orm.hibernate4.HibernateTransactionManager;
|
||||
import org.springframework.orm.hibernate4.LocalSessionFactoryBean;
|
||||
import org.springframework.transaction.annotation.EnableTransactionManagement;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
|
||||
@Configuration
|
||||
@EnableTransactionManagement
|
||||
@PropertySource({ "classpath:persistence-mysql.properties" })
|
||||
@ComponentScan({ "org.baeldung.spring.persistence.dao", "org.baeldung.spring.persistence.service" })
|
||||
public class PersistenceConfig {
|
||||
|
||||
|
@ -30,10 +32,10 @@ public class PersistenceConfig {
|
|||
}
|
||||
|
||||
@Bean
|
||||
public AnnotationSessionFactoryBean alertsSessionFactory() {
|
||||
final AnnotationSessionFactoryBean sessionFactory = new AnnotationSessionFactoryBean();
|
||||
public LocalSessionFactoryBean sessionFactory() {
|
||||
final LocalSessionFactoryBean sessionFactory = new LocalSessionFactoryBean();
|
||||
sessionFactory.setDataSource(restDataSource());
|
||||
sessionFactory.setPackagesToScan(new String[] { "org.rest" });
|
||||
sessionFactory.setPackagesToScan(new String[] { "org.baeldung.spring.persistence.model" });
|
||||
sessionFactory.setHibernateProperties(hibernateProperties());
|
||||
|
||||
return sessionFactory;
|
||||
|
@ -53,7 +55,7 @@ public class PersistenceConfig {
|
|||
@Bean
|
||||
public HibernateTransactionManager transactionManager() {
|
||||
final HibernateTransactionManager txManager = new HibernateTransactionManager();
|
||||
txManager.setSessionFactory(alertsSessionFactory().getObject());
|
||||
txManager.setSessionFactory(sessionFactory().getObject());
|
||||
|
||||
return txManager;
|
||||
}
|
||||
|
|
|
@ -1,8 +1,31 @@
|
|||
package org.baeldung.spring.persistence.model;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.GenerationType;
|
||||
import javax.persistence.Id;
|
||||
|
||||
@Entity
|
||||
public class Foo {
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.AUTO)
|
||||
private long id;
|
||||
|
||||
public Foo() {
|
||||
super();
|
||||
}
|
||||
|
||||
// API
|
||||
|
||||
public long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(final long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue