-->
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: filter-def/filter with collection enums as parameter list
PostPosted: Mon Apr 24, 2017 8:20 pm 
Newbie

Joined: Mon Apr 24, 2017 7:27 pm
Posts: 3
Hibernate: 4.2.18.Final-redhat-2
Java 1.7/1.8
JBOSS EAP 6.4

The issue is about the conversion of Java enum type to Varchar when a filter-def/filter is used to filter the results from a child class. I see that on passing a collection of enum (VehicleType) to t he filter did not produce a resultset. I looked at the generated query, and it looks correct. FYI to confirm, I took the query and ran it through SQL developer by passing valid params, it produced the desired result.

I was curious and logged the params and found:
17:30:12,088 TRACE [org.hibernate.type.descriptor.sql.BasicBinder] (http-/127.0.0.1:8080-2) binding parameter [1] as [VARBINARY] - AUDI
17:30:12,088 TRACE [org.hibernate.type.descriptor.sql.BasicBinder] (http-/127.0.0.1:8080-2) binding parameter [2] as [VARBINARY] - PORSCHE

VARBINARY appears to be the issue, the column vehicle_type in table Vehicle is defined as VARCHAR.

I passed a Collection of<String> to the filter instead of Collection<VehicleType>, updated the type in filter-param to string, and this worked.

The Question:
The hbm already maps the VehicleType to org.hibernate.type.EnumType ( config below), the inserts work fine, the VehicleType.AUDI are is converted to VARCHAR and I see the vehicle_type column populated with correct values e.g. AUDI , PORSCHE.


The issue occurred with a filter-def/filter, I'm expecting hibernate to handle the translation as well i.e. the enum to VARCHAR, but it appears that is instead translating it to VARBINARY. I would at least expect hibernate to throw an exception as the VARBINARY does not match the target column type VARCHAR. Looks like a bug to me.


Annotated Vehicle.VehicleType with @Enumerated(EnumType.STRING), this did not make any difference.


Appreciate your answer.





Parent is the root table, that holds a one-to-one with a Vehicle table.
Vehicle table has a property of type enum (VehicleType)
The filter-def is used to filter results with a collection of enum Collection<VehicleType> of matching type.

Collection<VehicleType> vehicleTypes= new ArrayList<VehicleType>();
changeRequestReferences.add(VehicleType.AUDI);
changeRequestReferences.add(VehicleType.PORSCHE);

Filter filter = getCurrentSession().enableFilter("vehicleFilter");
filter.setParameterList("filterParams", vehicleTypes);




<hibernate-mapping package="com.volks.cars.Parent"
default-access="field">

<list name="vehicles" inverse="false"
cascade="all-delete-orphan" lazy="false" batch-size="100">
<key column="cr_id" not-null="true"/>
<list-index column="cr_idx"/>
<one-to-many entity-name="Vehicle"/>
<filter name="vehicleFilter" condition="vehicle_type in (:filterParams)"/>
</list>


<filter-def name="vehicleFilter">
<filter-param name="filterParams" type="com.volks.car.enums.VehicleType"/>
</filter-def>
</hibernate-mapping>


<hibernate-mapping package="com.volks.cars.Parent"
default-access="field">
<class name="Vehicle"
entity-name="Vehicle">
<id name="id">
<generator class="native"/>
</id>
<property name="vehicleType" not-null="true">
<type name="org.hibernate.type.EnumType">
<param name="enumClass">
com.rj.cob.domain.enums.VehicleType
</param>
<param name="useNamed">true</param>
</type>
</property>
</class>
</hibernate-mapping>




public enum VehicleType{
AUDI,
PORSCHE
}


Top
 Profile  
 
 Post subject: Re: filter-def/filter with collection enums as parameter list
PostPosted: Mon May 01, 2017 3:04 am 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1628
Location: Romania
Hibernate 4.2 is quite old so, if there is an issue, you need to replicate with the latest version of Hibernate. Also, try to see if it works better with Annotation mappings.


Top
 Profile  
 
 Post subject: Re: filter-def/filter with collection enums as parameter list
PostPosted: Mon May 01, 2017 8:27 am 
Newbie

Joined: Mon Apr 24, 2017 7:27 pm
Posts: 3
It might work with a higher version of Hibernate. Up
grade to a higher version is not possible in my case.
Im trying to find out if this is a bug in 4.2.18.


Top
 Profile  
 
 Post subject: Re: filter-def/filter with collection enums as parameter list
PostPosted: Mon May 01, 2017 10:07 am 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1628
Location: Romania
Even if it's a bug, I don;t think it will be fixed. Bugs are only fixed to the latest Hibernate version (5.2 as of writing), and only critical issues are backported to old versions.


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.