首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >带有EntityManager的Oracle12c标识列

带有EntityManager的Oracle12c标识列
EN

Stack Overflow用户
提问于 2016-07-12 11:27:50
回答 1查看 651关注 0票数 0

我在oracle中创建了带有标识列的示例表。

代码语言:javascript
复制
CREATE TABLE "CORE_PROD"."BOOK" 
   (    "ID" NUMBER GENERATED BY DEFAULT AS IDENTITY MINVALUE 1 MAXVALUE 9999999999999999999999999999 INCREMENT BY 1 START WITH 1 CACHE 20 NOORDER  NOCYCLE  NOT NULL ENABLE, 
    "AUTHOR" VARCHAR2(255 BYTE), 
    "GENRE" VARCHAR2(255 BYTE), 
    "ISBN" VARCHAR2(255 BYTE), 
    "PUBLISHED" NUMBER NOT NULL ENABLE, 
    "TITLE" VARCHAR2(255 BYTE), 
     PRIMARY KEY ("ID")
  USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS 
  TABLESPACE "MCA_DATA"  ENABLE
   ) SEGMENT CREATION DEFERRED 

  PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 
 NOCOMPRESS LOGGING
  TABLESPACE "PROD_DATA" ;

我使用下面的配置创建了EntityManagerConfiguration

代码语言:javascript
复制
@Bean
    public DataSource dataSource() {
        DriverManagerDataSource dataSource = new DriverManagerDataSource();
        dataSource.setDriverClassName(environment.getRequiredProperty("oracle.driver.class"));
        dataSource.setUrl(environment.getRequiredProperty("oracle.connection.url"));
        dataSource.setUsername(environment.getRequiredProperty("oracle.db.username"));
        dataSource.setPassword(environment.getRequiredProperty("oracle.db.password"));
        return dataSource;
    }

    @Bean
    public LocalContainerEntityManagerFactoryBean entityManagerFactory() {
        LocalContainerEntityManagerFactoryBean bean = new LocalContainerEntityManagerFactoryBean();
        bean.setPackagesToScan(DomainPackage.class.getPackage().getName());
        bean.setDataSource(dataSource());
        bean.setJpaVendorAdapter(jpaVendorAdapter());
        bean.setJpaProperties(jpaProperties());
        return bean;
    }

    @Bean
    public JpaVendorAdapter jpaVendorAdapter() {
        HibernateJpaVendorAdapter jpaVendorAdapter = new HibernateJpaVendorAdapter();
        jpaVendorAdapter.setShowSql(true);
        jpaVendorAdapter.setGenerateDdl(true);
        return jpaVendorAdapter;
    }

    @Bean
    public PlatformTransactionManager transactionManager(EntityManagerFactory emf) {
        JpaTransactionManager jpaTransactionManager = new JpaTransactionManager();
        jpaTransactionManager.setEntityManagerFactory(emf);
        return jpaTransactionManager;
    }

    @Bean
    public PersistenceExceptionTranslationPostProcessor exceptionTranslation() {
        return new PersistenceExceptionTranslationPostProcessor();
    }


    private Properties jpaProperties() {
        Properties properties = new Properties();
        properties.put("hibernate.hbm2ddl.auto", environment.getRequiredProperty("hbm2ddl.auto"));
        properties.put("hibernate.dialect", environment.getRequiredProperty("hibernate.dialect"));
        properties.put("hibernate.show_sql", environment.getRequiredProperty("hibernate.show_sql"));
        properties.put("hibernate.format_sql", environment.getRequiredProperty("hibernate.format_sql"));
        // Configures the naming strategy that is used when Hibernate creates
        // new database objects and schema elements
        // properties.put("hibernate.ejb.naming_strategy",
        // environment.getRequiredProperty("hibernate.ejb.naming_strategy"));
        properties.put("hibernate.temp.use_jdbc_metadata_defaults",
                environment.getRequiredProperty("use_jdbc_metadata_defaults"));
        return properties;
    }

然后我创建了BookRepository:

代码语言:javascript
复制
public interface BookRepository extends PagingAndSortingRepository<Book, Long> {
}

现在,当我试图将图书持久化到我的数据库时,我就面临着问题。

代码语言:javascript
复制
Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in org.markit.oracle.datasource.config.EntityManagerConfiguration: Invocation of init method failed; nested exception is org.hibernate.AnnotationException: No identifier specified for entity: org.markit.oracle.model.Book

我认为我正面临上述问题,因为身份专栏(甲骨文12c功能)。

有人能建议我需要修复/添加什么才能运行代码吗?

EN

回答 1

Stack Overflow用户

发布于 2016-07-15 08:28:54

似乎您还没有在Book实体中定义主键。尝试将@Id注释添加到实体的主键中。看看这个解决方案的链接:

http://viralpatel.net/blogs/org-hibernate-annotationexception-no-identifier-specified/

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/38327602

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档