• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Database search using hibernate

 
S.R.K.Vivek Raju
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all

I am using hibernate and i want to execute a query which would search the database and return all the entries which match to the 'where' clause in the query.

I have tried the follwing query and it gives an exception, i think the query is not proper.

The query which i have used is "select UserDataBO.Login from UserDataBO as Login where Login='username'"

If the query is incorrect please correct me or if there is another method please advice me.

Thanks in advance

With Regards,
S.R.K.Vivek Raju.
 
Damanjit Kaur
Ranch Hand
Posts: 346
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"select UserDataBO.Login from UserDataBO as Login where Login='username'"


instead like this:

select Object.columname from tablename as Object where Object.columnname='username'"

In my Hibernate application I used it like this :

session.find("from tablename as Object where Object.coulmname= ?",new Object[]{variablename},new Type[]{Hibernate.STRING});

where Object[] defines all variablenames for all ? in where clause
and Type[] defines the type of all variables
 
miguel lisboa
Ranch Hand
Posts: 1281
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
another way is:
 
Stan Sokolov
Ranch Hand
Posts: 120
Hibernate IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why don't use a plain SQL ? Today you have a Hibernate persistante layer, tomorrow another one. Arent you going to write all your quiries again and again. Don't do it man. Just define a mapping between your SQL output and persistent classes and you are full set:
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic