1.

What are the steps of calling a stored procedure in hibernate?

Answer»

Write the FOLLOWING queries-

1. Use CreateNativeSQL Method for calling a PROCEDURE

  • Query query = session.createSQLQuery (“CALL GetAllFoos ()”).addEntity;
  • LIST allFoos= query.list();

2. Use @NamedNativeQueries to call a STORED procedure

3. Use @NamedStoreProcedureQuery to call a stored procedure

Example

Use @NamedNativeQueries to call a stored procedure

@NamedNativeQueries({

          @NamedNativeQuery(

   name = "callGetAllFoos",

   query = "CALL GetAllFoos()",

      resultClass = Foo.class)

                         })

@Entity

public class Foo implements Serializable {

         // Model definition

}

Use @NamedStoreProcedureQuery to call a stored procedure

@NamedStoredProcedureQuery(

     name="GetAllFoos",

     procedureName="GetAllFoos",

     resultClasses = { Foo.class }

  )

@Entity

public class Foo implements Serializable {

 // Model Definition

}



Discussion

No Comment Found