Forums Register Login

Three tables query

+Pie Number of slices to send: Send
Hello,

I need to query three tables at the same time. Could anybody help me. User has one-to-many relation with lectures and lectures has one to one with Professor.


How can I query all three in one query an display data on one jsp form. Please help me.

Thanks in advance,
Arul
+Pie Number of slices to send: Send
Just load the user. Then, when you invoke user.getLectures or user.getClassrooms, all of the associated data will automatically be loaded.

That's how ORM works! You don't query the database. You just grab your object. And when you call various Java methods on your object, the underlying database is queried, and you get your data. Just make sure you're Hibernate Session is active while the call to the getter happens, otherwise you'll get a LazyLoading exception.

-Cameron McKenzie
+Pie Number of slices to send: Send
Thanks Cameron for such a quick reply. I really appreciate this.
+Pie Number of slices to send: Send
Cameron,

I need to display User - Lecture - Professor all on one page in the form of report. I can pass only one user.getLectureDetails or User.get ProfessorDetails in the page. How o I pass both and start displaying. I am lost somewhere.

Also, I need to define two methods getLectureDetails an get ProfessorDetails in User ? Remember, User has direct relation with Lecture and not Professor.


Thanks,
Arul
+Pie Number of slices to send: Send
Really, you first need to do some mappings. Check out my signature links for some tutorials on doing one to many mappings and many to many mappings. That's the best place to start! Just get the mappings working, then the display stuff will come easlity.
+Pie Number of slices to send: Send
Follow the steps below

1. Create the necessary hbm.xml file for your table Users, Lecturers and Professor.
2. Ensure that in your table hbm.xml file there is <one-to-many> relationship to the Lecturer table.
Similarly make sure there is one-to-one relationship between Lecturers and Professor

3. Finally, all you need is a method called getUserDetails(). In there all you will need to do is query User

session.createCriteria(Users.class).list();

4. In yous display screen you can get the lecturers details like users.getLecturers() and professor like users.getLecturers().getProfessor()

Hope that this helps to lead you to the correct path
rubbery bacon. rubbery tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 885 times.
Similar Threads
ejb3unit-1.2 SessionBean Test
Table Formating
Using JSP how du I work with jdbc (ms-access)
Hibernate Query taking long time
named queries can be defined only on an entity - problem
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 08:15:08.