【发布时间】:2016-10-07 07:23:53
【问题描述】:
我在我的网络应用程序中使用了两种不同的架构。我的应用程序有效,但在编译过程中出现了一些错误。如何配置我的应用程序以使用多个模式?
我的豆子:
@Bean
public LocalContainerEntityManagerFactoryBean entityManagerFactory
(DataSource dataSource, JpaVendorAdapter jpaVendorAdapter) {
LocalContainerEntityManagerFactoryBean entityManagerFactory = new LocalContainerEntityManagerFactoryBean();
entityManagerFactory.setDataSource(dataSource);
entityManagerFactory.setJpaVendorAdapter(jpaVendorAdapter);
entityManagerFactory.setPackagesToScan("base");
return entityManagerFactory;
}
@Bean
public PlatformTransactionManager transactionManager(EntityManagerFactory emf) {
return new JpaTransactionManager(emf);
}
@Bean
public JpaVendorAdapter jpaVendorAdapter() {
HibernateJpaVendorAdapter adapter = new HibernateJpaVendorAdapter();
adapter.setShowSql(false);
adapter.setGenerateDdl(true);
adapter.setDatabasePlatform("org.hibernate.dialect.MySQLDialect");
return adapter;
}
@Bean
public DataSource dataSource() {
DriverManagerDataSource ds = new DriverManagerDataSource();
ds.setDriverClassName("com.mysql.jdbc.Driver");
ds.setUrl("jdbc:mysql://localhost:3306/sc1?characterEncoding=UTF-8"); //?characterEncoding=UTF-8
ds.setUsername("*****");
ds.setPassword("******");
return ds;
}
我的实体:
@Entity
@Table(name = "agents",schema="sc1")
public class Agent {}
@Entity
@Table(name = "agents",schema="sc2")
public class Agent2 {}
错误信息:
ERROR SchemaUpdate:261 - HHH000388: Unsuccessful: alter table sc2.agents constraint FK_dhh7a26whpx1a7cqnh646turg foreign key (doc_id) references sc2.Docs (id)
ERROR SchemaUpdate:261 - HHH000388: Unsuccessful: create table sc2.agents (id bigint not null auto_increment)
2016-06-07 14:38:33 ERROR SchemaUpdate:262 - Table 'sc2.agents' already exists
等等
【问题讨论】:
-
My application works, but I have some error during the compile不能为真。如果您有error during compile,应用程序将无法编译,未编译的应用程序将无法工作。显示的错误消息不是编译错误,而是启动应用程序时引发的运行时错误。它们表明 Hibernate 无法对模式进行某些更改,因为这些更改已经存在于数据库中。由于setGenerateDdl(true);,Hibernate 正在尝试进行这些更改。您可以忽略这些消息,因为更改已经存在或使用setGenerateDdl(false)。
标签: java mysql spring spring-mvc spring-data