• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Sorry, but what does this select mean ?

 
Hussein Baghdadi
clojure forum advocate
Bartender
Posts: 3479
Clojure Mac Objective C
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi.
The following line is from Hibernate documenation, but -shamefully- I didn't understand what it mean !
List mates = sess.find(
"select mate from Cat as cat join cat.mate as mate " +
"where cat.name = ?",
name,
Hibernate.STRING
);
What is the kind of this join ?
 
Sebastian Hennebrueder
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is normal to not understand the Hibernate Reference when you are learning Hibernate. But once you get better it will be very useful to you.

It means
table cat(
id
mate_id refenceres (id) from table cat (self reference)
)
So, search from the table cat every cat with name =? and return the mate of this cat.

List mates = sess.find(
"select mate from Cat as cat join cat.mate as mate " +
"where cat.name = ?",
name,
Hibernate.STRING
);
Regards Sebastian
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is a normal INNER JOIN between the CAT and MATE Tables

the "as cat" and "as mate" are just aliases. You can do the same with regular SQL so that you don't have to type the entire table name in your select part or where part. But in the case above it really doesn't give you much.

The Name and hibernate.String, is for the parameter to the query. the parameter is called name and it is of type String.

HTH

Mark
 
Hussein Baghdadi
clojure forum advocate
Bartender
Posts: 3479
Clojure Mac Objective C
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why not just to write :
select mate from Cat as cat where cat.name = :name
?
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by John Todd:
Why not just to write :
select mate from Cat as cat where cat.name = :name
?



Well because, it sounds like the mate field is in the Mate class/table and not in the Cat class/table. The Cat class would just have the Foreign Key to teh Mate table and not the actual Mate name or mate field.

Mark
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic