Search code examples
javahibernatejpaeclipselinkprocedure

JPA: Use several @NamedStoredProcedureQuery at one entity


I am using Stored Procedures in JPA (using EclipseLink). I annotate them at an entity class with

@Entity
@NamedStoredProcedureQuery(
    name = "myproc", 
    procedureName = "SP_myproc", 
    parameters = { 
        @StoredProcedureParameter(mode = ParameterMode.IN, type = Integer.class, name = "testparam"),
    },
        resultClasses = Integer.class
)
public class MyEntity implements Serializable,Comparable<MyEntity> {

I used this tutorial: https://www.thoughts-on-java.org/call-stored-procedures-jpa/

But I would like to define more than one procedure for that entity.

I could annotate the other procedure at another class, but the procedure belongs to this one -- and how would I do if I needed more Stored Procedures than Entity Classes? (This is not the case, but I do not think it is good to define the procedure at an entity that has no relation to the original one ...)

Thank you for help,

eisenbahnfan


Solution

  • Use @NamedStoredProcedureQueries http://www.eclipse.org/eclipselink/documentation/2.4/jpa/extensions/a_namedstoredproc_queries.htm

    To define multiple @NamedStoredProcedureQuery elements.