app中的两个不同架构

时间:2016-06-07 11:47:43

标签: java mysql spring spring-mvc spring-data

我在网络应用程序中使用了两种不同的模式。我的应用程序工作,但我在编译期间有一些错误。如何配置我的应用程序以使用多个模式?

我的豆子:

@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

1 个答案:

答案 0 :(得分:0)

您的sc2.Docs(id)id列不是主键或唯一键。