0% found this document useful (0 votes)
3 views2 pages

Sql queries for fetch

The document contains SQL queries using Hibernate for different types of relationships in a database. It includes one-to-one queries for Aadhar and user data, one-to-many queries for departments and employees, and many-to-one queries linking employees to departments. Each section specifies the fields to be selected and the conditions for filtering the results.

Uploaded by

unknowndijago
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views2 pages

Sql queries for fetch

The document contains SQL queries using Hibernate for different types of relationships in a database. It includes one-to-one queries for Aadhar and user data, one-to-many queries for departments and employees, and many-to-one queries linking employees to departments. Each section specifies the fields to be selected and the conditions for filtering the results.

Uploaded by

unknowndijago
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

one to one:

-----------
Aadhar and user:

Hibernate:
select
a1_0.aadharID,
a1_0.Address,
a1_0.Dob,
a1_0.aadharnum,
a1_0.name
from
AadharCard a1_0
where
a1_0.aadharID=?

Hibernate:
select
u1_0.userID,
a1_0.aadharID,
a1_0.Address,
a1_0.Dob,
a1_0.aadharnum,
a1_0.name,
u1_0.contact,
u1_0.email,
u1_0.name,
u1_0.password
from
User u1_0
left join
AadharCard a1_0
on a1_0.aadharID=u1_0.a_id_aadharID
where
u1_0.userID=?

--------------------------------------------------------------------------
one to many
--------------------------------------------------------------------------
Hibernate:
select
d1_0.deptID,
d1_0.dname,
d1_0.location
from
Department d1_0
where
d1_0.deptID=?

Hibernate:
select
e1_0.emp_id,
e1_0.Salary,
e1_0.commision,
e1_0.designation,
e1_0.employeeName,
e1_0.hireDate,
e1_0.managerNumber
from
Employee e1_0
where
e1_0.emp_id=?
-----------------------------------------------------------------------------
Many to one
----------------------------------------------------------------------------
select
e1_0.emp_id,
e1_0.Salary,
e1_0.commision,
d1_0.deptID,
d1_0.dname,
d1_0.location,
e1_0.designation,
e1_0.employeeName,
e1_0.hireDate,
e1_0.managerNumber
from
EmployeeMtoO e1_0
left join
DepartmentMtoO d1_0
on d1_0.deptID=e1_0.dept_deptID
where
e1_0.emp_id=?

select
d1_0.deptID,
d1_0.dname,
d1_0.location
from
DepartmentMtoO d1_0
where
d1_0.deptID=?

---------------------------------------------------------------------------

You might also like