title: How to call stored procedures Mysql in SPRING DATA JPA
body: <p>I read How to call  mysql stored procedures in JPA </p>
  
  <p><a href="http://www.thoughts-on-java.org/call-stored-procedures-jpa/" rel="nofollow noreferrer">call-stored-procedures-jpa</a></p>
  
  <p>but my procedure api no out put parament ! </p>
  
  <p>How to call it  and return result in spring data jpa</p>
  
  <pre><code>CREATE DEFINER=`tester`@`%` PROCEDURE `GET_TERMINAL_TRANSACTION_KEY` (in a_id_term integer unsigned)
  BEGIN
  declare v_trn_key bigint unsigned;
      set v_trn_key = null;
      start transaction;
      select seq from TERMINAL_TRANSACTION_KEY where id_term = a_id_term into v_trn_key for update;
      if v_trn_key is null then
          set v_trn_key = 1;
          insert into TERMINAL_TRANSACTION_KEY(id_term,seq) values(a_id_term,v_trn_key);
      else
          set v_trn_key = v_trn_key + 1;
          update TERMINAL_TRANSACTION_KEY set seq = v_trn_key where id_term = a_id_term;
      end if;
      commit;
      select v_trn_key;
  END$$
  </code></pre>
  
  <p>Java Entity</p>
  
  <pre><code>@Entity
  @Table(name = "TERMINAL_TRANSACTION_KEY")
  @XmlRootElement
  @NamedStoredProcedureQueries({
     @NamedStoredProcedureQuery(name = "getNextTransactionKeyByTerminalId", 
                                procedureName = "GET_TERMINAL_TRANSACTION_KEY",
  //                              resultClasses = {Object.class},
                                parameters = {
                                   @StoredProcedureParameter(mode = ParameterMode.IN, name = "a_id_term", type = Long.class)
                                })
  })
  
  public class TerminalTransactionKey implements Serializable {
      private static final long serialVersionUID = 1L;
      @Id
      @GeneratedValue(strategy = GenerationType.IDENTITY)
      @Basic(optional = false)
      @Column(name = "id")
      private Long id;
      @Basic(optional = false)
      @NotNull
      @Column(name = "id_term" ,unique=true, nullable=false)
      private int idTerm;
      @Column(name = "seq")
      private BigInteger seq;
  
      public TerminalTransactionKey() {
      }
  
      public TerminalTransactionKey(Long id) {
          this.id = id;
      }
  </code></pre>
  
  <p>my repo </p>
  
  <pre><code>import org.springframework.data.jpa.repository.Query;
  import org.springframework.data.jpa.repository.query.Procedure;
  import org.springframework.data.repository.query.Param;
  
  
  
  public interface TerminalTransactionKeyRepository extends  CrudRepository&lt;TerminalTransactionKey, Long&gt;{
  
  
      @Procedure(name = "getNextTransactionKeyByTerminalId")
      Long nextIdByTerminalId(@Param("a_id_term") Long terminalId);
  
      @Query("UPDATE TerminalTransactionKey SET seq=:nextExtTrnId WHERE idTerm=:terminalId")
      int updateSequence(@Param("nextExtTrnId")Long nextExtTrnId, @Param("terminalId") Long terminalId);
  
  }
  </code></pre>
  
  <p>and my test</p>
  
  <pre><code>@Test
  public void testNextId() {
      log.info(repository.nextIdByTerminalId(1L));
  
  }
  </code></pre>
  
  <p>out p6spy call is ok! but in log </p>
  
  <blockquote>
    <p>16:26:30 [INFO ] [main] [] []
    LocalContainerEntityManagerFactoryBean:Initialized JPA
    EntityManagerFactory for persistence unit 'PersistanceUnitTest'
    16:26:31 [INFO ] [main] [] [] p6spy:1490189191865|connectionId
    2|elapsed 118|category statement
        {call GET_TERMINAL_TRANSACTION_KEY(1)} Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 5.18 sec &lt;&lt;&lt; FAILURE! - in
    ru.service.TerminalTransactionKeyServiceImplTest
    testNextId(ru.service.TerminalTransactionKeyServiceImplTest)
    Time elapsed: 0.47 sec  &lt;&lt;&lt; ERROR!
    o<strong>rg.springframework.dao.InvalidDataAccessApiUsageException: Invalid
    mix of named and positional parameters; nested exception is
    java.lang.IllegalArgumentException: Invalid mix of named and
    positional parameters</strong></p>
  </blockquote>