缺少序列或表:hibernate_sequence,我不需要它

时间:2016-01-26 14:45:24

标签: java spring hibernate jpa spring-data

我正在使用hibernate 4.2.7,Oracle 12c和每个表的序列,我的应用程序仍然会问我这个序列。

每个表使用自己的序列如下:

@Entity
@Table(name = "foo")
@SequenceGenerator(name = "foo_seq", sequenceName = "foo_seq", initialValue = 1)
public class Foo implements Serializable {

    private static final long serialVersionUID = 1L;

    @Id
    @GeneratedValue(generator = "foo_seq", strategy = GenerationType.SEQUENCE)
    private Long id;

    ...
}

我的配置:

@Configuration
@EnableAspectJAutoProxy
@EnableSpringDataWebSupport
@EnableTransactionManagement
@EnableJpaRepositories(basePackageClasses = Application.class)
@EnableJpaAuditing
@ComponentScan(basePackageClasses = Application.class, excludeFilters = @Filter({Controller.class}))
@PropertySource(value = {"classpath:foo.properties"})
public class Application {

    @Inject
    private Environment env;

    @Bean
    public DataSource dataSource() {

        DataSource dataSource = new BasicDataSource();
            ((BasicDataSource) dataSource).setDriverClassName(env.getProperty("jdbc.driverClassName"));
            ((BasicDataSource) dataSource).setUrl(env.getProperty("jdbc.url"));
            ((BasicDataSource) dataSource).setUsername(env.getProperty("jdbc.user"));
            ((BasicDataSource) dataSource).setPassword(env.getProperty("jdbc.pass"));
        return dataSource;
    }


    @Bean
    public LocalContainerEntityManagerFactoryBean entityManagerFactory() {
        LocalContainerEntityManagerFactoryBean factory = new LocalContainerEntityManagerFactoryBean();
        HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
        vendorAdapter.setGenerateDdl(Boolean.TRUE);
        vendorAdapter.setShowSql(Boolean.TRUE);
        factory.setDataSource(dataSource());
        factory.setJpaVendorAdapter(vendorAdapter);
        factory.setPackagesToScan(Application.class.getPackage().getName() + ".domain");
        Properties jpaProperties = new Properties();
        jpaProperties.put("hibernate.hbm2ddl.auto", env.getProperty("hibernate.hbm2ddl.auto"););
        jpaProperties.put("hibernate.dialect", env.getProperty("hibernate.dialect"));
        factory.setJpaProperties(jpaProperties);
        factory.afterPropertiesSet();
        factory.setLoadTimeWeaver(new InstrumentationLoadTimeWeaver());
        return factory;
    }

    ...
}

我收到以下错误:

  

引起:org.hibernate.HibernateException:缺少序列或   table:hibernate_sequence at   org.hibernate.cfg.Configuration.validateSchema(Configuration.java:1316)   [hibernate-core-4.2.7.Final.jar:4.2.7.Final] at   org.hibernate.tool.hbm2ddl.SchemaValidator.validate(SchemaValidator.java:155)   [hibernate-core-4.2.7.Final.jar:4.2.7.Final] at   org.hibernate.internal.SessionFactoryImpl。(SessionFactoryImpl.java:509)   [hibernate-core-4.2.7.Final.jar:4.2.7.Final] at   org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1794)   [hibernate-core-4.2.7.Final.jar:4.2.7.Final] at   org.hibernate.ejb.EntityManagerFactoryImpl。(EntityManagerFactoryImpl.java:96)   [hibernate-entitymanager-4.2.7.Final.jar:4.2.7.Final] at   org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:914)   [hibernate-entitymanager-4.2.7.Final.jar:4.2.7.Final] ... 107更多

我使用jboss 6.2。如果我不在任何地方使用,为什么这个序列会问我?

1 个答案:

答案 0 :(得分:-1)

我发现了我的问题。我有一个扩展AbstractPersistable的自定义类。