java - JPA entity mapping - linking the same entity -


i faced problem mapping same entity. entity represents tree node , assumes parent , child defined same entity:

id-class

@mappedsuperclass public class parentid {     @id     @generatedvalue(strategy = generationtype.auto)     @column(name = "id")     private long id;      public void setid(long id) {         this.id = id;     }     public long getid() {         return id;     } } 

entity-class

@entity @table(name = "navigation_tree_node") public class navigationtreenode extends parentid {      @column(name = "node_name")     private string nodename;      @column(name = "node_type")     @enumerated(enumtype.ordinal)     private nodetype nodetype;      @manytoone(fetch = fetchtype.eager)     @joincolumn(name = "entity_id")     private navigationtreenode parent;      @onetomany(mappedby = "parent")     private list<navigationtreenode> children;      public string getnodename() {         return nodename;     }      public void setnodename(string nodename) {         this.nodename = nodename;     }      public nodetype getnodetype() {         return nodetype;     }      public void setnodetype(nodetype nodetype) {         this.nodetype = nodetype;     }      public void setparent(navigationtreenode parent) {         this.parent = parent;     }      public navigationtreenode getparent() {         return parent;     }      public void setchildren(list<navigationtreenode> children) {         this.children = children;     }      public list<navigationtreenode> getchildren() {         return children;     }      public enum nodetype {         root,         node,         leaf;          public string getname() {             return this.name();         }     } } 

sql

create table "dev1"."navigation_tree_node"     (    "id" number not null enable,      "node_name" varchar2(30 byte),      "node_type" varchar2(20 byte),      "parent_id" number,      "entity_id" number,       primary key ("entity_id")   using index pctfree 10 initrans 2 maxtrans 255 compute statistics    storage(initial 65536 next 1048576 minextents 1 maxextents 2147483645   pctincrease 0 freelists 1 freelist groups 1 buffer_pool default flash_cache default cell_flash_cache default)   tablespace "system"  enable,       foreign key ("parent_id")       references "dev1"."navigation_tree_node" ("entity_id") enable    ) segment creation immediate    pctfree 10 pctused 40 initrans 1 maxtrans 255 nocompress logging   storage(initial 65536 next 1048576 minextents 1 maxextents 2147483645   pctincrease 0 freelists 1 freelist groups 1 buffer_pool default flash_cache default cell_flash_cache default)   tablespace "system" ;    create or replace trigger "dev1"."navigation_tree_node_trigger"    before insert on navigation_tree_node   each row begin   select dev1_seq.nextval   :new.id   dual; end; 

when try compile following exception thrown:

caused by: java.sql.sqlexception: ora-17059 fail convert internal representation     @ oracle.jdbc.driver.charcommonaccessor.getint(charcommonaccessor.java:147)     @ oracle.jdbc.driver.t4cvarcharaccessor.getint(t4cvarcharaccessor.java:830)     @ oracle.jdbc.driver.oracleresultsetimpl.getint(oracleresultsetimpl.java:942)     @ oracle.jdbc.driver.oracleresultset.getint(oracleresultset.java:438)     @ org.hibernate.type.enumtype$ordinalenumvaluemapper.getvalue(enumtype.java:372)     @ org.hibernate.type.enumtype.nullsafeget(enumtype.java:107)     @ org.hibernate.type.customtype.nullsafeget(customtype.java:127)     @ org.hibernate.type.abstracttype.hydrate(abstracttype.java:106)     @ org.hibernate.persister.entity.abstractentitypersister.hydrate(abstractentitypersister.java:2969)     @ org.hibernate.loader.loader.loadfromresultset(loader.java:1696)     @ org.hibernate.loader.loader.instancenotyetloaded(loader.java:1628)     @ org.hibernate.loader.loader.getrow(loader.java:1515)     @ org.hibernate.loader.loader.getrowfromresultset(loader.java:726)     @ org.hibernate.loader.loader.processresultset(loader.java:953)     @ org.hibernate.loader.loader.doquery(loader.java:921)     @ org.hibernate.loader.loader.doqueryandinitializenonlazycollections(loader.java:355)     @ org.hibernate.loader.loader.dolist(loader.java:2554)     ... 35 more 

could please how correct code? thanks.

you have

@column(name = "node_type") @enumerated(enumtype.ordinal) // <-- number private nodetype nodetype; 

but in sql it's

"node_type" varchar2(20 byte). 

Comments

Popular posts from this blog

javascript - Slick Slider width recalculation -

jsf - PrimeFaces Datatable - What is f:facet actually doing? -

angular2 services - Angular 2 RC 4 Http post not firing -