1

Hi i'm New to write HQL Query please help me..... my Hibernate have three ValueObjects ie.

@Entity
@Table(name="user")
public class UserVO {

    @Id
    @Column(name="S_ID")
    private String s_id;

    @Column(name="FIRSTNAME")
    private String firstName;
    private String email;
}

CourseVO class

    @Entity
@Table(name="course")
public class CourseVO
{
    @Id
    @Column(name="S_ID")
    public String s_id;

    @Column(name="NAME")
    public String name;
}

Skillset VO

@Entity
@Table(name="skillset")
public class SkillsetVO 
{
    @Id
    @Column(name="S_ID")
    public String s_id;

    @Column(name="COURSE_ID")//Foreign Key "USER"
    public String course_id;

    @Column(name="USER_ID")//Foreign key "COURSE"
    public String user_id;

    @Column(name="TEACH_EXP")
    public String teach_Exp;
}

Now How to get Values of FirstName,NAME,TEACH_EXP values using EMAIL of USER table using HQL query

1 Answer 1

1

If you want to use join syntax in HQL you must work out your mapping accordingly as joins are enabled by mapping.

@Entity class A { @OneToMany private List<B> bs; }
@Entity class B { @Basic int n; }

Enables

select b from A a inner join a.b where a = :id

But with your mapping this is not possible. Also bear in mind that in terms of efficiency most of the RDBMs will perform an inner join on a where a.id = b.id.

select u.firstName, c.name, s.teach_Exp
from UserVO u, CourseVO c, SkillsetVO s 
where
    u.s_id = s.user_id 
    and c.s_id = s.course_id 
    and u.email = :email

But I think that you must review you association. Since looks to me that SkillsetVO.user_id should be SkillsetVO.User (an association to a UserVO entity and same for CourseVO).

Sign up to request clarification or add additional context in comments.

1 Comment

Thankyou..Correct, i'm using one to many association CourseVO and UserVO class.but your query have no join why HQL not support joins?or using 'and' operator is easy and correct way?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.