java - Mixing Native SQL with Default Hibernate Behavior in an Entity Object? -
i'm trying work native sql query existing entity object while retaining default hibernate behavior object whole.
the majority of fields on object mapped so:
@column(name = "first_name", nullable = false) public string getfirstname() { return firstname; } @column(name = "middle_name", nullable = true) public string getmiddlename() { return middlename; } @column(name = "last_name", nullable = false) public string getlastname() { return lastname; } @column(name = "primary_email_addr", nullable = false) public string getprimaryemailaddress() { return primaryemailaddress; }
i want retain functionality, add single field need mapping custom (preferably native) sql query. envisioned like...
private string foo; @nativesqlquery("select info foo") public string getfooinfo{return foo}
..but if there way that, i'm missing it.
i've investigated sqlresultsetmapping
, several similar native , named query annotations, can find seems presume 1 operating @ class level - entire entity mapped in custom, native fashion, not 1 field. how can go keeping normal functionality, adding custom mapping 1 field? i've done before using hbm files, think, quite time ago, current project annotation-based. @ moment, best can come mark getter @transient
, not map @ all, use execute query, i'd rather not that, because seems total hack.
try using @formula("select info foo")
, should works
Comments
Post a Comment