How to call oracle function using Hibernate criteria?

I am new to Hibernate. I am creating a login portal. We used the DB function to encrypt the user's password. It looks like using hibernate for complex queries / functions / procedures in existing databases is difficult. Is it possible to write below queries using Hibernate criteria? SQL Query 1:

SELECT first_name
FROM user.emp_group
WHERE username = 'XXX'
    AND user.decrypt(password, 2) = 'YYYY';

      

SQL Query 2:

SELECT a.DESC
    ,b.total
FROM user.STATUS a
    ,(
        SELECT STATUS
            ,count(*) total
        FROM user.emp
        GROUP BY STATUS
        ) b
WHERE a.TYPE = b.STATUS (+)

      

User

- schema name and decryption is the name of the function.

I also ran into the problem of getting data from views, which was solved by this Stackoverflow post. How does hibernate retrieve data from an existing database view? Thanks for this.

+3


source to share


1 answer


You can use native SQL with hibernate.

How it looks like (for example):



String sql = "SELECT first_name, salary FROM EMPLOYEE";
SQLQuery query = session.createSQLQuery(sql);
List data = query.list();

     for(Object object : data)
     {
        Map row = (Map)object;
        System.out.print("First Name: " + row.get("first_name")); 
        System.out.println(", Salary: " + row.get("salary")); 
     }

      

+1


source







All Articles