Hi Rick,
thanks for taking the time to reply.
I am not 100% sure what you mean. My application uses JPA and the Entity
Manager is getting the connection from the container's datasource: I do not
have (direct) access to the java.sql.Statement.
What I (would like to) do is calling the a stored procedure in this way:
getEm().createStoredProcedureQuery(Constants.SP_EXPORT_PIANIFICAZIONE)
.registerStoredProcedureParameter(1, Long.class, ParameterMode.IN)
.registerStoredProcedureParameter(2, String.class, ParameterMode.IN)
.registerStoredProcedureParameter(3, String.class,
ParameterMode.IN).setParameter(1, myPromo)
.setParameter(2, idCompratori).setParameter(3, username)
.setHint("javax.persistence.query.timeout", milliseconds)
.execute();
As far as the JPA API specification (and EclipseLink implementation) goes, the
".setHint("javax.persistence.query.timeout", milliseconds)" should be
equivalent to what you suggest.
The problem is that I cannot make the stored procedure call to throw a
QueryTimeoutException even if my dummy procedure (in derby) waits for 10
seconds and I set the timeout to 1 millisecond.
I am using, in my test environment, Apache Tomee (java 8) , derby client 10.14
and a docker image with a derby network server
(https://github.com/az82/docker-derby/blob/master/Dockerfile
(https://link.getmailspring.com/link/[email protected]/0?redirect=https%3A%2F%2Fgithub.com%2Faz82%2Fdocker-derby%2Fblob%2Fmaster%2FDockerfile&recipient=ZGVyYnktdXNlckBkYi5hcGFjaGUub3Jn))
.
As far as my knowledge goes, and it's not that far, the reasons I am not
getting a timeout are :
I am not correctly using the hint
I am not correctly setting up the datasource
There is no timeout because the stored procedure terminates within the given
timeout.
On point 3: in my (dummy) implementation of the stored procedure i do, before
doing anything else, a TimeUnit.SECONDS.wait(10);
On point 1 : I am lost. I think I am using the hint correctly (at least the API
docs say so)
On point 2: I am setting up the datasource with the minimum configuration
possible :
<Resource id="jdbc/myDatasource" type="DataSource"> JdbcDriver
org.apache.derby.jdbc.ClientDriver JdbcUrl
jdbc:derby://database:1527/dbpromo;create=false UserName DBPROMO Password
dbpromo </Resource>
Could it be that I am failing to activate something on the Derby side ?
Thanks in advance
Marco
On Apr 19 2022, at 4:57 pm, Rick Hillegas <[email protected]> wrote:
> java.sql.Statement.setQueryTimeout(int) should do the trick.
>
> On 4/19/22 3:30 AM, Marco Ferretti wrote:
> > Hi all,
> > I am trying to simulate a query timeout in a stored procedure by simply
> > adding a delay in my (test) jar.
> > I then am launching the stored procedure in my java code via JPA and try to
> > set a timeout hint by adding
> > .setHint("javax.persistence.query.timeout", milliseconds)
> > but I am not able to register a timeout.
> > I am wondering if there is some derby property or jdbc property I should
> > use to activate such behavior. I have tried to google for it but I am
> > having extremely bad results... but according to this
> > (https://docs.oracle.com/cd/E25178_01/apirefs.1111/e13952/pagehelp/J2EEkodojdbcconfdescriptorDerbyDictionaryBeantitle.html)
> > I have to activate it somehow.
> >
> > Does Derby supports query timeout at all? If so, can you please point me to
> > some references ?
> > Thanks in advance for any help,
> > Marco
> >
>