Spring Data Rest & JPA -- not rendering results when entities are annotated by methods (works by field annotations) -


i'm attempting spring data rest work entities. implemented repository , can see list of available ones when requesting localhost:8080.

however, when attempting execute of repository queries via rest interface (e.g. findall() via localhost:8080/users), response empty. traced issue following:

there call org.springframework.data.jpa.mapping.jpapersistententityimpl.getidproperty() (method implemented in base class basicpersistententity) returns null. call made persistententityresourceassembler.getselflinkfor(..). null id property causes null pointer exception further down stack trace, null pointer exception never surfaces app, apart debug log saying "null modelandview".

it turns out reason getidproperty() return null because not using field annotations, rather method annotation. @id annotation applied on getter getuserid() , not on filed userid.

i don't believe correct behaviour. either jpapersistententityimpl.getidproperty() not configured return correct id or persistententityresourceassembler.getselflinkfor(..) should use different method getting id. unless thes system not support entities use method annotations, though valid jpa spec.

anyone have ideas on how resolve issue while maintaining annotated methods approach (rather annotated fields).

also, know how better configure system better exception handling, such erors not degrade quietly?


more inconsistencies between fields , methods:

i discovered setters , getter must implemented fields in order them render in resulting json. fields non-basic, (e.g. managed beans), names fetched field names not properties (as in basic ones).

e.g.:

  @entity   class  user   {      @id     long id;     string firstnamefield;     string lastnamefield;     account accountfield;   //a managed bean      long getid() ...     string getfirstname() ...     string getlastname() ....     account getaccount()  ....  } 

results in following json:

    {         firstname: "..."         lastname: "....."         accountfield:  ".....link..."       } 

not first 2 fields names correspond method name while managed bean field corresponds field name.

(i omitted setters , entity annotations brevity, there , correct)


ok here concrete example:

/** */

@entity @table (name = "users", schema = "cars", catalog = "") public class user {

private int userid; private string firstname; private string lastname; private string password; private string email;  //todo: ugh, odd...spring data rest not seem render links manytomany properties using method annotation...must add field declaration...removing here result in removing property rest response...needs further investigation @manytomany @jointable (name = "user_role",             joincolumns = @joincolumn(updatable = false, insertable = false, name = "user_id", referencedcolumnname = "user_id"),             inversejoincolumns = @joincolumn(updatable = false, insertable = false, name = "role_id", referencedcolumnname = "role_id")) private collection<role> roles;    @id @column (name = "user_id") public int getuserid() {     return userid; }   public void setuserid(int inuserid) {     userid = inuserid; }   @basic @column (name = "first_name") public string getfirstname() {     return firstname; }   public void setfirstname(string infirstname) {     firstname = infirstname; }   @basic @column (name = "last_name") public string getlastname() {     return lastname; }   public void setlastname(string inlastname) {     lastname = inlastname; }   @basic @column (name = "password") public string getpassword() {     return password; }   public void setpassword(string inpassword) {     password = inpassword; }    @override public boolean equals(object o) {     ........... }   @override public int hashcode() {     ...... }   @manytomany @jointable (name = "user_role",            joincolumns = @joincolumn(updatable = false, insertable = false, name = "user_id", referencedcolumnname = "user_id"),            inversejoincolumns = @joincolumn(updatable = false, insertable = false, name = "role_id", referencedcolumnname = "role_id")) private collection<role> getroles() {     return roles; }   private void setroles(collection<role> inroles) {     roles = inroles; } 

@override public boolean equals(object o) { ........... }

@override public int hashcode() {     ...... } 

}

you need implement getters , setters , annotate primary key. there several examples in guides.


Comments

Popular posts from this blog

javascript - how to protect a flash video from refresh? -

android - Associate same looper with different threads -

visual studio 2010 - Connect to informix database windows form application -