-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Query timeout in persistence.xml doesn't work
PostPosted: Wed Jan 02, 2013 9:14 pm 
Newbie

Joined: Wed Jan 02, 2013 8:46 pm
Posts: 2
Hello everyone

I am using Hibernate 4.1.6 as JPA provider. I am trying to use the javax.persistence.query.timeout setting in persistence.xml, but it turns out it doesn't work.
For example, I add this into persistence.xml to set the query timeout as 5 seconds:
Code:
<property name="javax.persistence.query.timeout" value="5000"/>

I use SQL Server as database. Begin a transaction, and update one row, not commit it. So the row has been locked. Then I use JPA to load the entity or run some queries, and these operations should be blocked because of the exclusive lock. The query timeout is supposed to work in this case. However the program was waiting like forever.

It will be fine if I use Query Hint, but it's not acceptable because it's needed for every places and it seems doesn't work for EntityManager.find().
I've also tested other JPA provider such as EclipseLink. The query timeout setting works.

Is this a bug? This setting is stated in documentation:
http://docs.jboss.org/hibernate/core/4.0/hem/en-US/html/configuration.html#setup-configuration-packaging

Here's my testing program:
MyUser.java
Code:
@RooJavaBean
@RooToString
@RooJpaActiveRecord
public class MyUser {

    @NotNull
    @Size(min = 2)
    private String firstName;

    @NotNull
    @Size(min = 2)
    private String lastName;

    private int age;
}


MyUserIntegrationTest
Code:
  @Transactional(propagation = Propagation.REQUIRES_NEW)
  private void runQuery(MyUser myUser) {
    // 1. test get one
    em.find(MyUser.class, myUser.getId());

    // 2. test query
    Query query = em.createQuery("select o from MyUser o where o.age = " + myUser.getAge());
//    query.setHint("javax.persistence.query.timeout", 5000);
    try {
      query.getResultList();
    } catch (Exception ex) {
      System.out.println(ex.getMessage());
    }

    // 3. test typed query
    TypedQuery<MyUser> typedQuery = em.createQuery(
        "select o from MyUser o where o.age = " + myUser.getAge(), MyUser.class);
//    typedQuery.setHint("javax.persistence.query.timeout", 5000);
    try {
      typedQuery.getResultList();
    } catch (Exception ex) {
      System.out.println(ex.getMessage());
    }
  }

It works for the #2 case, but doesn't work for the #1 and #3 cases.


Last edited by jhuang8285 on Sun Jan 06, 2013 8:42 pm, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: Query timeout in persistence.xml doesn't work
PostPosted: Sun Jan 06, 2013 7:42 pm 
Newbie

Joined: Wed Jan 02, 2013 8:46 pm
Posts: 2
Is there anyone knows this problem? The property is documented but actually it doesn't work.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.