Spring ORM - 更新 EclipseLink 项目



现在,更新 AppConfig.java 以使用为 EclipseLink 创建的持久化单元。

AppConfig.java

package com.tutorialspoint.jpa;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.ComponentScans;
import org.springframework.context.annotation.Configuration;
import org.springframework.orm.jpa.JpaTransactionManager;
import org.springframework.orm.jpa.LocalEntityManagerFactoryBean;
import org.springframework.transaction.annotation.EnableTransactionManagement;

@Configuration
@EnableTransactionManagement
@ComponentScans(value = { @ComponentScan("com.tutorialspoint.jpa.dao"),
   @ComponentScan("com.tutorialspoint.jpa.service") })
   public class AppConfig {

   @Bean
   public LocalEntityManagerFactoryBean geEntityManagerFactoryBean() {
      LocalEntityManagerFactoryBean factoryBean = new LocalEntityManagerFactoryBean();
      factoryBean.setPersistenceUnitName("EclipseLink_JPA");
      return factoryBean;
   }
   @Bean
   public JpaTransactionManager geJpaTransactionManager() {
      JpaTransactionManager transactionManager = new JpaTransactionManager();
      transactionManager.setEntityManagerFactory(geEntityManagerFactoryBean().getObject());
      return transactionManager;
   }
}

现在,重置数据库。

mysql> use tutorialspoint
Database changed
mysql> delete from employees;
Query OK, 3 rows affected (0.02 sec)

mysql> drop table employees;
Query OK, 0 rows affected (0.17 sec)

mysql>
广告