• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

hibernate

 
waqas shahwar
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi could anybody tell me
student = (Student) session.createQuery("from Student as s where s.email = :email").setString("email", studentEmail).uniqueResult();
why in this query setString()& uniqueResult() are used
also
could anybody tell in the same code if we use setEntity("",obj);
what would be the effect

thanks in advance
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, first it is called method chaining, in Hibernate any call to a method in the Query, Criteria apis it will return an object of its own type, so you can method chain.

So you createQuery, returns a Query object, then call setString(0 on that Query object, which returns a Query object, then call uniqueResult() on that query object and it returns a Student object.

So if Student's attribute called email was of type say Email, then you would use setEntity but in your case it looks like that attribute is of type String, hence the call to setString.

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