Results 1 to 5 of 5
  1. #1
    madhupara is offline Member
    Join Date
    May 2010
    Posts
    2
    Rep Power
    0

    Default Hibernate queries in jsp page

    I have a jsp page something like this,
    Java Code:
    <%@ taglib uri="http://java.sun.com/jsp/jstl/sql" prefix="sql" %>
    
    <sql:query var="TypeMaster" scope="request">
        SELECT c_org_id,c_org_name FROM t_gb_organization_master order by c_org_name;
    </sql:query>
    I need to convert this query using hibernate.which taglib can i use to write hql query.

    Can anybody help me?

  2. #2
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    8

    Default

    You should consider those sql tags as taboo and only ever use them for quick tests.
    They should never find their way to production. Even the sun tutorial says they are "designed for quick prototyping and simple applications. For production applications, database operations are normally encapsulated in JavaBeans components".

  3. #3
    madhupara is offline Member
    Join Date
    May 2010
    Posts
    2
    Rep Power
    0

    Default Hibernate queries in jsp

    Actually, I have a webapplication which is using struts1.x with mysql connection .I am trying to change the web application using hibernate with struts1.x.
    In my action class i can write hibernate query like this
    Java Code:
     ServletContext context = request.getSession().getServletContext();
            /*Retrieve Session Factory */
            SessionFactory _factory = (SessionFactory) context.getAttribute(HibernatePlugIn.SESSION_FACTORY_KEY);
            /*Open Hibernate Session */
            Session session = _factory.openSession();
             String HQL_QUERY = "select NNoOfAttempt,CStatus,CLastAccessedTime,CBranchId,"
                    + "CGroupId, COrgId,CStateId,CRegionId,CUserName from TGbUserMaster"
                    + " where CUserName='" + userId + "' and CPassword='" + encryptPass + "'";
    
            Query query = session.createQuery(HQL_QUERY);
    In my previous webapplication i have some SQLqueries(
    Java Code:
    <sql:query   var="TypeMaster" scope="request">
        SELECT c_org_id,c_org_name FROM t_gb_organization_master order by c_org_name;
    </sql:query>
    ) written in jsp page, Now i need some way to convert this sql queries in jsp page to hql queries
    But am really not understanding how to write queries in jsp.Can you please help me?

  4. #4
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    8

    Default

    You simply don't write queries in JSPs. That is what my post is about and what that quote from the sun tutorial is also saying.

  5. #5
    Aseem is offline Senior Member
    Join Date
    Mar 2009
    Location
    USA
    Posts
    127
    Rep Power
    0

    Default

    yeah...u dont write queries in JSP. Infact in real time, there is hardly any code in JSPs. JSPs are used only for presentation logic not for business logics.

Similar Threads

  1. Hibernate Queries
    By rummy in forum Advanced Java
    Replies: 3
    Last Post: 01-08-2010, 02:11 PM
  2. Replies: 2
    Last Post: 06-30-2007, 04:01 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •