@@ -0,0 +1,2239 @@
+package com.vladmihalcea.book.hpjp.hibernate.query.timeout;%0A%0Aimport com.vladmihalcea.book.hpjp.util.AbstractTest;%0Aimport com.vladmihalcea.book.hpjp.util.exception.ExceptionUtil;%0Aimport com.vladmihalcea.book.hpjp.util.providers.Database;%0Aimport org.hibernate.jpa.QueryHints;%0Aimport org.junit.Test;%0Aimport org.postgresql.util.PSQLException;%0A%0Aimport javax.persistence.Entity;%0Aimport javax.persistence.GeneratedValue;%0Aimport javax.persistence.Id;%0Aimport javax.persistence.Table;%0Aimport java.util.List;%0Aimport java.util.Properties;%0A%0Aimport static org.junit.Assert.assertTrue;%0Aimport static org.junit.Assert.fail;%0A%0A/**%0A * @author Vlad Mihalcea%0A */%0Apublic class SessionQueryTimeoutTest extends AbstractTest %7B%0A%0A    @Override%0A    protected Class%3C?%3E%5B%5D entities() %7B%0A        return new Class%3C?%3E%5B%5D%7B%0A            Post.class%0A        %7D;%0A    %7D%0A%0A    @Override%0A    protected Database database() %7B%0A        return Database.POSTGRESQL;%0A    %7D%0A%0A    @Override%0A    protected void additionalProperties(Properties properties) %7B%0A        properties.setProperty(%0A            QueryHints.SPEC_HINT_TIMEOUT, String.valueOf(1000)%0A        );%0A    %7D%0A%0A    @Test%0A    public void testJPATimeout() %7B%0A        doInJPA(entityManager -%3E %7B%0A            try %7B%0A                List%3CPost%3E posts = entityManager%0A                .createQuery(%0A                    %22select p %22 +%0A                    %22from Post p %22 +%0A                    %22where function('1 %3E= ALL ( SELECT 1 FROM pg_locks, pg_sleep(2) ) --',) is ''%22, Post.class)%0A                .getResultList();%0A%0A                fail(%22Timeout failure expected%22);%0A            %7D catch (Exception e) %7B%0A                PSQLException rootCause = ExceptionUtil.rootCause(e);%0A                assertTrue(rootCause.getMessage().contains(%22canceling statement due to user request%22));            %7D%0A        %7D);%0A    %7D%0A%0A    @Entity(name = %22Post%22)%0A    @Table(name = %22post%22)%0A    public static class Post %7B%0A%0A        @Id%0A        @GeneratedValue%0A        private Integer id;%0A%0A        private String title;%0A%0A        public Integer getId() %7B%0A            return id;%0A        %7D%0A%0A        public String getTitle() %7B%0A            return title;%0A        %7D%0A%0A        public Post setTitle(String title) %7B%0A            this.title = title;%0A            return this;%0A        %7D%0A    %7D%0A%7D%0A

Add tests