0

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 is NULL")
   A parent;

   public A getParent(){
      this.parent;
   }
}

I need to retrieve the parent of object based on those conditions: above code does not work and would you please help me out to solve it.

P.S: Parent sql query alike:

select b.* from A a inner join A b 
on a.code = b.code
and a.id2 = b.id2
where b.name is null;
user3375740
  • 245
  • 1
  • 3
  • 11

1 Answers1

0

you can use @JoinFormula instead

@JoinFormula and @OneToMany definition - poor documentation

or if you want to do parent/child relationship in one table

Hibernate: Parent/Child relationship in a single-table

http://viralpatel.net/blogs/hibernate-self-join-annotations-one-to-many-mapping/

Community
  • 1
  • 1
vexan
  • 88
  • 4