views:

724

answers:

1
@Entity
@Table(name = "BOOKTEST")
@NamedQueries({@NamedQuery(name = "Booktest.findAll", query = "SELECT b FROM Booktest b"), @NamedQuery(name = "Booktest.findById", query = "SELECT b FROM Booktest b WHERE b.id = :id"), @NamedQuery(name = "Booktest.findByBookName", query = "SELECT b FROM Booktest b WHERE b.bookName = :bookName")})
public class Booktest implements Serializable {
 @ManyToOne
    private Topictest topictestId;   //foreign key
    @JoinColumn(name = "USERTEST_ID", referencedColumnName = "ID")
    @ManyToOne
    private Usertest usertestId;  //foreign key
}

when i execute

session.createCriteria(Booktest.class).createAlias("usertestId", "usertestId",Criteria.LEFT_JOIN) .list();

the sql_log still showing select * from booktest,usertest rather than select * from booktest left join usertest how to do left join?

tried non sequitor both cases and i still getting below without "left join"

Hibernate: select this_.ID as ID13_2_, this_.BOOK_NAME as BOOK2_13_2_, this_.TOP
ICTEST_ID as TOPICTEST4_13_2_, this_.USERTEST_ID as USERTEST3_13_2_, usertestid1
_.ID as ID14_0_, usertestid1_.TOPIC_NAME as TOPIC2_14_0_, usertest4_.ID as ID15_
1_, usertest4_.USER_NAME as USER2_15_1_ from BOOKTEST this_, TOPICTEST usertesti
d1_, USERTEST usertest4_ where this_.TOPICTEST_ID=usertestid1_.ID and this_.USER
TEST_ID=usertest4_.ID(+)
+1  A: 

Try this

session.createCriteria(BookTest.class)
           .createAlias("topictestId", "usertestId")
           .setFetchMode("topictestId",FetchMode.EAGER)
           .list();

In theory this should work, if not try it without the aliasing.

non sequitor
non sequitor, please have a look my result above, still no "left join"
cometta
the `(+)` makes it a `left join` see http://www.dba-oracle.com/tips_oracle_left_outer_join.htm you must be using Oracle 8i
non sequitor
its because of hibernate diaclet i using ws oracledialect. i changed to oracle9dialect. ok now.
cometta