java - Use hibernate query with entity field -
i have simple entity :
@entity public class university implements serializable { /** constant serialversionuid. */ private static final long serialversionuid = 1l; @id @generatedvalue(strategy = generationtype.auto) private int id; @column string name; @column string address; @column student student; }
and entity student :
@entity public class student implements serializable { /** constant serialversionuid. */ private static final long serialversionuid = 1l; @id @generatedvalue(strategy = generationtype.auto) private int id; @column string firstname; @column string lastname; @column studentstatus status; }
can create @joinformula or create query , take students student entity university entity ?
i tried that:
@joinformula("select l student l l.id = 1") student student;
but doesn't work. can create query select students ?
updated : @joinformula never called.
i miss poit, if want reference entity can use @manytoone annotation.
example:
@manytoone public medialibrary getparentlibrary() { return parentlibrary; }
similary, if have list can use @manytomany annotation , specify correct join table:
example:
@manytomany(fetch = fetchtype.eager, cascade = { cascadetype.merge, cascadetype.refresh, }) @jointable(name = "mediadatatag", joincolumns = { @joincolumn(name = "mediadata_id") }, inversejoincolumns = { @joincolumn(name = "tag_id") }) public set<tag> gettags() { return this.tags; }
if provide clear use case, easier provide specific solution.