oracle12c - Oracle 12C Identity Column with EntityManager -
i have created sample table identity column in oracle.
create table "core_prod"."book" ( "id" number generated default identity minvalue 1 maxvalue 9999999999999999999999999999 increment 1 start 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" ;
i have created entitymanagerconfiguration using below configuration
@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 naming strategy used when hibernate creates // new database objects , 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; }
then have created bookrepository:
public interface bookrepository extends pagingandsortingrepository<book, long> { }
now when trying persist book database facing issue.
exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.beancreationexception: error creating bean name 'entitymanagerfactory' defined in org.markit.oracle.datasource.config.entitymanagerconfiguration: invocation of init method failed; nested exception org.hibernate.annotationexception: no identifier specified entity: org.markit.oracle.model.book
i think facing above issue because of identity column(oracle 12c feature).
can suggest need fix/add run code?
it seems have not defined primary key in book entity. try add @id annotation primary key of entity. take @ link solution:
http://viralpatel.net/blogs/org-hibernate-annotationexception-no-identifier-specified/
Comments
Post a Comment