1

I have this

DECLARE
  c number;
BEGIN
  c := get_next_unlocked_id();
  DBMS_OUTPUT.put_line('id: ' || c);
END;

This query print function result. But I need return this result in my Spring data JPA repositoru or entitiManager.

I try this:

@Override
    public Long getOld() {
        Long id = (Long) em.createNativeQuery("SELECT get_next_unlocked_id() FROM DUAL").getSingleResult();
        return id;
    } 

but I get error:

2019-01-10 15: 28: 25.768 ERROR 6724 --- [pool-1-thread-2] o.h.engine.jdbc.spi.SqlExceptionHelper: ORA-14551: the DML operation cannot be performed inside the request
ORA-06512: on "MY.GET_NEXT_UNLOCKED_ID", line 8

1 Answer 1

1

The function you are calling in a select (get_next_unlocked_id) attempts to do data modification, which is not allowed the way you tried it.

The problem is that your solution appears to be "querying" while in effect it is modifying data. I assume your function increments some counter or updates something? The ORA errorcode you received is quite descriptive, here is the longer explanation.

The solution either way is to use CallableStatements from Java.

2
  • I'm trying to get a locked row for each thread. This function was suggested to me by SO. Here is a related question, maybe you can also help? stackoverflow.com/q/54125380/4781349
    – ip696
    Jan 10, 2019 at 13:14
  • I am sorry but I would not get involved in that question. This here was straightforward question, but in the other you are asking for help in a solution which I think is not a good direction at all. I do not know how do that because I would not (and have not done) that before. You will need somebody else for that. In your place I would decide where would I place the complexity: app or DB, and keep it there. Mixing it that much is going to bring lots of troubles. Jan 10, 2019 at 13:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.