JPA. How to do a join with legacy table -


i have following entity class

public class reportrequest {  @id @generatedvalue (strategy=generationtype.identity) private long id; private string requestorusername;     ... } 

which maps table, reportrequest, , have legacy table, user, following fields (id, username, fullname), requestorusername in reportrequest table maps username in user table.

what's best way retrieve reportrequest object requestor's full name? have create user entity object? how jpql, native sql?

as jb nizet suggested, mapped table entity, myuser. note can map entity database view instead of table.

public class reportrequest {  @id @generatedvalue (strategy=generationtype.identity) private long id;  @onetoone(targetentity=myuser.class) @joincolumn(name="requestor") private myuser requestor;      ... } 

and entity class like

@entity @table(name="user", catalog="somecatelog", schema="myschema") public class myuser {  @id @column(name="userid") private string userid;      //don't want modify data @column(name="first_name", insertable=false, updatable=false) private string firstname;  @column(name="last_name", insertable=false, updatable=false) private string lastname;  } 

Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -