wood burning stoves 2.0*
The moose likes Object Relational Mapping and the fly likes HQL for unary table Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "HQL for unary table" Watch "HQL for unary table" New topic
Author

HQL for unary table

Sumer Selvaraj
Greenhorn

Joined: May 02, 2013
Posts: 15
Hi,

I'm new to the Hibernate I have the following database design,

user_info(user_id,user_name,.....,supervisor)

The supervisor is referred the own table's user_id column

I have created the hibernate mapping files and pojo using the automated feature of Netbean. The Codes are here

UserInfo.java


I don't see any option to get the supervisor's as I want to do get the supervisor's name by joining. I know how to get it done using the SQL . This is the SQL code I wish to execute. But I don't know how to write it in HQL.

Can anyone help me out of this?
Volodymyr Levytskyi
Ranch Hand

Joined: Mar 29, 2012
Posts: 505
    
    1

Hello!

HQL is very similar to sql. The difference is that in HQL you use entity names instead of table names and entity properties names instead of columns names.

True person is moral, false is right!
Sumer Selvaraj
Greenhorn

Joined: May 02, 2013
Posts: 15
Volodymyr Levytskyi wrote:Hello!

HQL is very similar to sql. The difference is that in HQL you use entity names instead of table names and entity properties names instead of columns names.


Hi,

The problem is, how can able to write the condition as there is no method about the supervisor in the UserInfo class
Volodymyr Levytskyi
Ranch Hand

Joined: Mar 29, 2012
Posts: 505
    
    1

Every column should be mapped to entity property.

You can't write hql that uses non-existent properties or nonexistent corresponding columns in database
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: HQL for unary table
 
Similar Threads
JPA 2.0:Columns inserted as nulls while the table have multiple foreign keys
java.lang.NullPointerException at org.hibernate.tuple.entity.AbstractEntityTuplizer.getPropertyValue
Not able to Insert data in SQLite
Transaction management in Spring
Hibernate mapping