-->
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.  [ 4 posts ] 
Author Message
 Post subject: [Bug] JPA + Hibernate Filter + Create Query
PostPosted: Thu Jul 22, 2010 3:11 am 
Regular
Regular

Joined: Fri Feb 09, 2007 3:47 pm
Posts: 56
Hi

I'm using JPA 2.0 with hibernate 3.5.3 and using hibernate filters to filter a formula query. When i use
Code:
em.find(TestEntity.class, 1L)

the filter is applied correctly but when i use
Code:
entityManager.createQuery("from TestEntity").getSingleResult()
filter parameters are not applied to the query and i get an error because generated native sql query expects two parameters(limit parameter to obtain one value and filter parameter) and hibernate only defines one.

I'm using log4jdbc to debug the queries that are being generated and i can confirm these problems.

Entity code:
Code:
@Entity
@FilterDef(name = "test", parameters = @ParamDef(name = "param", type = "java.lang.String"))
public class TestEntity {
   @Id
   private Long id;
   @Formula("select id from TestEntity where :test.param like 'es'")
   private Long value;
}


Test code:
Code:
public class MainTest {
   @Test
   public void testFail() {
      final EntityManagerFactory entityManagerFactory = Persistence.createEntityManagerFactory("SamplePU");
      final EntityManager entityManager = entityManagerFactory.createEntityManager();

      ((Session) entityManager.getDelegate()).enableFilter("test").setParameter("param", "param1");

      entityManager.createQuery("from TestEntity").getSingleResult();

//      entityManager.find(TestEntity.class, 1L);
   }
}


persistence.xml
Code:
   <persistence-unit name="SamplePU" transaction-type="RESOURCE_LOCAL">
      <provider>org.hibernate.ejb.HibernatePersistence</provider>
      <properties>
         <property name="hibernate.connection.driver_class" value="net.sf.log4jdbc.DriverSpy"/>
         <property name="hibernate.dialect" value="org.hibernate.dialect.H2Dialect"/>
         <property name="hibernate.connection.username" value="sa"/>
         <property name="hibernate.connection.password" value=""/>
         <!--<property name="hibernate.connection.url" value="jdbc:hsqldb:mem:memdb"/>-->
         <property name="hibernate.connection.url" value="jdbc:log4jdbc:h2:mem:memdb;DB_CLOSE_DELAY=-1"/>         
         <property name="hibernate.hbm2ddl.auto" value="update"/>         
      </properties>
   </persistence-unit>


This is what log4jdbc prints:
Code:
22-jul-2010 9:06:58 net.sf.log4jdbc.Slf4jSpyLogDelegator methodReturned
INFO: 1. Connection.prepareStatement(select testentity0_.id as id0_, select testentity0_.id from TestEntity where ? like 'es' as formula0_ from TestEntity testentity0_ limit ?) returned net.sf.log4jdbc.PreparedStatementSpy@1d9e2c7
22-jul-2010 9:06:58 net.sf.log4jdbc.Slf4jSpyLogDelegator methodReturned
INFO: 1. PreparedStatement.setInt(1, 2) returned
22-jul-2010 9:06:58 net.sf.log4jdbc.Slf4jSpyLogDelegator sqlOccured
INFO: select testentity0_.id as id0_, select testentity0_.id from TestEntity where 2 like 'es' as
formula0_ from TestEntity testentity0_ limit ?
22-jul-2010 9:06:58 net.sf.log4jdbc.Slf4jSpyLogDelegator exceptionOccured
GRAVE: 1. PreparedStatement.executeQuery() select testentity0_.id as id0_, select testentity0_.id from TestEntity where 2 like 'es' as formula0_ from TestEntity testentity0_ limit ?
org.h2.jdbc.JdbcSQLException: Parametro "#2" no está fijado
Parameter "#2" is not set; SQL statement:


Top
 Profile  
 
 Post subject: Re: [Bug] JPA + Hibernate Filter + Create Query
PostPosted: Thu Aug 12, 2010 8:41 am 
Regular
Regular

Joined: Fri Feb 09, 2007 3:47 pm
Posts: 56
up.
Is someone else having these issues with filters and jpa?


Top
 Profile  
 
 Post subject: Re: [Bug] JPA + Hibernate Filter + Create Query
PostPosted: Wed Dec 22, 2010 3:37 pm 
Regular
Regular

Joined: Tue Nov 30, 2004 4:23 pm
Posts: 62
Where you able to resolve this because I do have scenarios where I am trying to do the same thing as you showed with Filters:

entityManager.createQuery("from TestEntity").getSingleResult()

Thanks.

jay


Top
 Profile  
 
 Post subject: Re: [Bug] JPA + Hibernate Filter + Create Query
PostPosted: Thu Dec 23, 2010 8:10 am 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
Could you please
1) verify it's still an issue in Hibernate 3.6.0.Final
2) create an issue on JIRA, that's where we track bugs and requests for change http://opensource.atlassian.com/projects/hibernate/browse/HHH
3) attach a unit test to the JIRA issue, that's very appreciated and helps a lot
thanks

_________________
Sanne
http://in.relation.to/


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.