hibernate - JPA ManyToOne in MappedSupperClass -


i trying create basic abstraction jpa entities. have base abstract class abstractmodel has id , version. think have abstract class extends abstractmodel adding auditing columns. have actual entities representing tables. have manytoone mapping in abstractauditmodel class doesn't seem it. is possible accomplish in mappedsuperclass?

my code below.

abstractmodel.java

@mappedsuperclass public abstract class abstractmodel implements serializable {      @transient     protected static final long serialversionuid = 1l;      @id     @generatedvalue(strategy = generationtype.identity)     protected long id;      @version     protected long version;      public long getid() {         return id;     }      public void setid(long id) {         this.id = id;     }      public long getversion() {         return version;     }      public void setversion(long version) {         this.version = version;     }      @override     public abstract int hashcode();      @override     public abstract boolean equals(object obj);      @override     public abstract string tostring(); } 

abstractauditmodel.java

@mappedsuperclass public abstract class abstractauditmodel extends abstractmodel {      @createddate     @column(name = "created_at", nullable = false)     @temporal(temporaltype.timestamp)     protected date createdat;      @lastmodifieddate     @column(name = "last_modified_at", nullable = false)     @temporal(temporaltype.timestamp)     protected date lastmodifiedat;      @createdby     @manytoone(fetch = fetchtype.lazy)     @joincolumn(name = "created_by")     protected user createuser;      @lastmodifiedby     @manytomany(fetch = fetchtype.lazy)     @joincolumn(name = "last_modified_by")     protected user modifyuser;      public date getcreatedat() {         return createdat;     }      public void setcreatedat(date createdat) {         this.createdat = createdat;     }      public date getlastmodifiedat() {         return lastmodifiedat;     }      public void setlastmodifiedat(date lastmodifiedat) {         this.lastmodifiedat = lastmodifiedat;     }      public user getcreateuser() {         return createuser;     }      public void setcreateuser(user createuser) {         this.createuser = createuser;     }      public user getmodifyuser() {         return modifyuser;     }      public void setmodifyuser(user modifyuser) {         this.modifyuser = modifyuser;     }      @override     public abstract int hashcode();      @override     public abstract boolean equals(object obj);      @override     public abstract string tostring(); } 

i using classes this.

@entity @table(name = "item_snapshot", schema = "honda_ots") public class itemsnapshot extends abstractauditmodel {  // code  } 

the relevant stack trace below.

caused by: org.hibernate.annotationexception: illegal attempt map non collection @onetomany, @manytomany or @collectionofelements: com.testapp.model.itemsnapshot.modifyuser     @ org.hibernate.cfg.annotations.collectionbinder.getcollectionbinder(collectionbinder.java:330) ~[hibernate-core-4.3.8.final.jar:4.3.8.final]     @ org.hibernate.cfg.annotationbinder.processelementannotations(annotationbinder.java:1922) ~[hibernate-core-4.3.8.final.jar:4.3.8.final]     @ org.hibernate.cfg.annotationbinder.processidpropertiesifnotalready(annotationbinder.java:963) ~[hibernate-core-4.3.8.final.jar:4.3.8.final]     @ org.hibernate.cfg.annotationbinder.bindclass(annotationbinder.java:796) ~[hibernate-core-4.3.8.final.jar:4.3.8.final]     @ org.hibernate.cfg.configuration$metadatasourcequeue.processannotatedclassesqueue(configuration.java:3845) ~[hibernate-core-4.3.8.final.jar:4.3.8.final]     @ org.hibernate.cfg.configuration$metadatasourcequeue.processmetadata(configuration.java:3799) ~[hibernate-core-4.3.8.final.jar:4.3.8.final]     @ org.hibernate.cfg.configuration.secondpasscompile(configuration.java:1412) ~[hibernate-core-4.3.8.final.jar:4.3.8.final]     @ org.hibernate.cfg.configuration.buildsessionfactory(configuration.java:1846) ~[hibernate-core-4.3.8.final.jar:4.3.8.final]     @ org.hibernate.jpa.boot.internal.entitymanagerfactorybuilderimpl$4.perform(entitymanagerfactorybuilderimpl.java:852) ~[hibernate-entitymanager-4.3.8.final.jar:4.3.8.final]     ... 66 common frames omitted 

if want @manytomany have make list<user> rather user. might need add @jointable in keep relationship. otherwise make many one, suit name last_modified_by


Comments

Popular posts from this blog

google chrome - Developer tools - How to inspect the elements which are added momentarily (by JQuery)? -

angularjs - Showing an empty as first option in select tag -

php - Cloud9 cloud IDE and CakePHP -