hibernate - Retrieve an object which has a POJO as a primary key with Spring JPA -


i have following classes: departmentmember , account, mapped onetoone relationship.

this departmentmember class:

@entity(name="departmentmember") @table(name="departmentmember") @embeddable public class departmentmember {     @id    @generatedvalue(strategy = generationtype.identity)    private int id;     @column(name="name", nullable=false)    private string nume;     @column(name="lastname", nullable=false)    private string prenume;     @onetoone(mappedby="departmentmember",cascade=cascadetype.all,fetch=fetchtype.lazy, optional=false)    @jsonignore    private account account;     public departmentmember() {}     public departmentmember(string nume, string prenume, string cnp, string email) {        super();        this.nume = nume;        this.prenume = prenume;       }    //getters , setters  } 

and account class :

@entity(name="users") @table(name="users") public class account {      @id     private int id;      @column(name="username", unique=true, nullable=false)     private string username;      @column(name="password", nullable = false)     private string password;      @column(name="authorities", nullable=false)     private string authorities;      @onetoone(fetch=fetchtype.eager)     @mapsid     @embedded     private departmentmember departmentmember;      public account() {}       public account(string username, string password, string authorities) {     super();     this.username = username;     this.password = password;     this.authorities = authorities; }  //getters , setters } 

i have defined interface accountrepository extends crudrepository interface provided spring jpa. want define query, takes parameter departmentmember id , retrieves associated account member. how account object looks like:

{ "username": "maria_popescu", "password": "4ec38c6e-2463-4562-99ba-9f6c2b4528c4", "authorities": "role_user", "departamentmember": {   "id": 2,   "nume": "popescu",   "prenume": "maria", } 

i tried using findone(int id) method, didn't work, correct approach solve this?

edit: in accountrepository have defined following method :

account findbydepartmentmemberid(int id) , still not found error.

there problem in controller. managed working adding

account findbydepartmentmemberid(@param("id")int id); 

in accountrepository


Comments

Popular posts from this blog

jsf - "PropertyNotWritableException: Illegal Syntax for Set Operation" error when setting value in bean -

arrays - Algorithm to find ideal starting spot in a circle -

php - Autoloader issue not returning Class -