-->
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.  [ 3 posts ] 
Author Message
 Post subject: Hibernate 5.2 query param validation issue
PostPosted: Fri Jan 13, 2017 10:08 am 
Newbie

Joined: Fri Jan 13, 2017 9:35 am
Posts: 2
Hi all,

I am new to hibernate forum (but not to hibernate, I am using it since last 5 years).

Recently, we are trying to migrate our code from hibernate 4.x to hibernate 5.2. After adjusting to new naming strategy changes in 5.x, and few JPQL specific changes, migration went smooth.

However, one issue is troubling us a lot. The code where it happens is complex but let me explain it with a simple example.

We have following entity:

Code:
@Entity
public class Company {
  @Id
  @GeneratedValue(strategy = GenerationType.AUTO)
  private Long id;

  // getter/setter and other fields
}

In one of our generic service, we have following code (this service works with all entities, but here I am showing it for Company entity only).

Code:
Object param = 1;  // as it's generic service, we can pass any param type
Query query = em.createQuery("SELECT c FROM Company c WHERE c.id = :id");
try {
    query.setParameter("id", param); // we try to pass INTEGER here, while "id" field is of type "Long"
} catch (IllegalArgumentException e) {
    // in hibernate 4.x, we get here because of type mismatch
    // and we adjust the type from parameter type info
    query.setParameter("id", Long.parseLong(param.toString()));
}

However, with hibernate 5.2, it's not the case. The Query#setParameter is not throwing IllegalArgumentException if parameter type mismatch. According to JPA spec, it should throw IllegalArgumentException.

Hibernate 5.2 throws IllegalArgumentException only when we execute the query. I think this is a bug in hibernate 5.2 and should be fixed. Or may be I am missing something. Is there any way in hibernate 5.2 to force query param validation at the time of setting it?


Top
 Profile  
 
 Post subject: Re: Hibernate 5.2 query param validation issue
PostPosted: Fri Jan 13, 2017 2:10 pm 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1628
Location: Romania
Please provide a replicating test case and open a new Jira issue. Thanks.


Top
 Profile  
 
 Post subject: Re: Hibernate 5.2 query param validation issue
PostPosted: Sat Jan 14, 2017 10:01 am 
Newbie

Joined: Fri Jan 13, 2017 9:35 am
Posts: 2
Thanks.

Issue reported here https://hibernate.atlassian.net/browse/HHH-11397.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.