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
Post a Comment