Spring ORM - 更新项目 EclipseLink


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

应用程序配置.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>