please consider following class:
class a{ @column(name="id") int id; @column(name="code") string code; @column(name="name") string name; @column(name="id2") int id2; @transient @manytoone(fetch = fetchtype.lazy, optional = true) @joincolumns({ @joincolumn(name = "code"), @joincolumn(name = "id2") }) @where(clause="parent.name null") parent; public getparent(){ this.parent; } }
i need retrieve parent of object based on conditions: above code not work , please me out solve it.
p.s: parent sql query alike:
select b.* a inner join b on a.code = b.code , a.id2 = b.id2 b.name null;
you can use @joinformula instead
@joinformula , @onetomany definition - poor documentation
or if want parent/child relationship in 1 table
hibernate: parent/child relationship in single-table
http://viralpatel.net/blogs/hibernate-self-join-annotations-one-to-many-mapping/