I’m using JPA 2.0 with Hibernate 4.1.0.Final. I have a couple of classes, Groups and GroupMembers. Each GroupMember is tied to a user object
@Entity
@Table
How about creating a procedure in SQL and calling the same using JPA? I created the following for calling login procedure I created.
@Query(nativeQuery = true,value = "{call Login_User(:username,:pass)}") // call stored procedure
int loginUser(@Param("username")String username,@Param("pass")String pass);
And the SQL Procedure I had created was as following:
DELIMITER //
CREATE PROCEDURE Login_User(IN username CHAR(12), IN pass text(255))
BEGIN
DECLARE password text(18);
SELECT User_Password INTO password FROM user WHERE User_ID = username;
select if(STRCMP(pass,password)= 0,1,0) as str_compare;
END//
DELIMITER ;
Hope this helps. Cheers! I'm open to know more about the same. I know mine is more like a workaround rather than the solution :)