尝试在Sybase上执行JPA查询时Hibernate停止

时间:2012-07-13 22:00:11

标签: eclipse hibernate jpa

我想使用JPA执行以下选择:

select * from permissions_table where permissions.role in ("Role1", "Role2")

到目前为止我的样子是这样的:

     protected Set<String> getPermissions(Connection conn, String username, Collection<String> roleNames) throws SQLException {
            PreparedStatement ps = null;
            Set<String> permissions = new LinkedHashSet<String>();
            try {                                                                        

                 EntityManager em = entityManagerFactory.createEntityManager();                                
                 CriteriaBuilder builder = em.getCriteriaBuilder();
                 CriteriaQuery<HierarchicalPermission> criteria = builder.createQuery( HierarchicalPermission.class );
                 Root<HierarchicalPermission> permission = criteria.from(HierarchicalPermission.class);
                 criteria.select(permission).where(permission.get("Role").in(roleNames));
                 List<HierarchicalPermission> hPermissions = em.createQuery(criteria).getResultList();
                 for ( HierarchicalPermission p : hPermissions ) {
                     System.out.println( "Permission (" + p.getRole() +")");
                 }

 }
        catch(Exception ex)
        {
            System.out.println( ex.getMessage());
        }
        finally {
            JdbcUtils.closeStatement(ps);
        }

        return permissions;
    }

当我跨过这一行时:

List<HierarchicalPermission> hPermissions = em.createQuery(criteria).getResultList();

我在Eclipse输出窗口中看到以下内容:

Hibernate: select hierarchic0_.iIdentity as iIdentity0_, hierarchic0_.timestamp as timestamp0_, hierarchic0_.szRole as szRole0_, hierarchic0_.szDescription as szDescri4_0_, hierarchic0_.iResource as iResource0_ from occ.ROLE_PERMISSIONS hierarchic0_ where hierarchic0_.szRole in (?)

并且Eclipse调试器似乎停滞不前。此时,我只能暂停或停止执行,如此屏幕截图所示。

enter image description here

这是什么意思?这不是上述查询的有效表示吗?

1 个答案:

答案 0 :(得分:0)

Sybase Interactive SQL在另一台机器上锁定了数据库,因此Hibernate在尝试执行查询时停滞不前。有人会认为Hibernate会抛出某种异常,而不是在遇到资源争用时暂停,但我想情况并非如此。