java - Issue with JPA @MappedSuperclass in a separate jar with Hibernate -


my problems come fact trying reuse mapped superclass contains basic fields such long id. mapped superclass looks this:

@mappedsuperclass public abstract class abstractbaseentity {      protected integer id;      @id     @generatedvalue(strategy = generationtype.identity)     @column(name = "id", nullable = false, unique = true, columndefinition = "int")     public integer getid() {         return id;     }      public void setid(integer id) {         this.id = id;     } } 

it sits in jar can reuse easily. apparently, works except when entities extend have relationships between them , try data using queries based on relationships. example: have entity organization has 1 or more user (s):

@entity @table(name = "organizations") public class organization extends abstractbaseentity {      private set<user> users;      @onetomany(mappedby = "organization", fetch = fetchtype.lazy)     public set<user> getusers() {         return users;     }      public void setusers(set<user> users) {         this.users = users;     } }  @entity @table(name = "users") public class user extends abstractbaseentity {      private organization organization;      @manytoone     @joincolumn(name = "organization_id", nullable = false)     public organization getorganization() {         return organization;     }      public void setorganization(organization organization) {         this.organization = organization;     } } 

now here's problem: if use detached organization object parameter query this:

select u user u u.organization = ?1 

then hibernate throws following exception:

 org.hibernate.transientobjectexception: object references unsaved transient instance - save transient instance before flushing: com.example.organization 

this doesn't make sense me, shouldn't require attached entity kind of query since needs id.

if, however, take out abstractbaseentity jar , put in same project organization , user, works perfectly, detached organizations , all...

this looks bug me. clues on how work around it?

ps. i've tried explicitly specifying abstractbaseentity class in persistence.xml specified here - jpa @mappedsuperclass in separate jar in eclipse (weird worth try) ...doesn't work

sorry say, assume can not "pull" mappedsuperclass different compilation unit. because jpa provider maybe uses code instrumentation access entity fields.

have tried create clone class in own workarea?

regards germany, thomas


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -