This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes Object Relational Mapping and the fly likes created hibernate SQL confusing Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "created hibernate SQL confusing" Watch "created hibernate SQL confusing" New topic
Author

created hibernate SQL confusing

Scott Stephens
Greenhorn

Joined: Jun 25, 2011
Posts: 23

When I use the following with an embedded Derby Database:



Hibernate creates the following SQL Statement:

Hibernate:


however, when I use this



Hibernate generates

Hibernate:
select
*
from
PERSOAPP.PERSONAL
where
PERSON_ID =1

Here is my class mapping :

Maybe someone has some tips!
William P O'Sullivan
Ranch Hand

Joined: Mar 28, 2012
Posts: 859

Welcome to ORM land. In your first example, Hibernate "knows" what it wants and generates SQL accordingly.
In the second you are bypassing Hibernate with native SQL so it basically does what you told it.

WP
Scott Stephens
Greenhorn

Joined: Jun 25, 2011
Posts: 23

Thanks. The "?" seems funny. Both snippets, however, return an object!
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: created hibernate SQL confusing