-->
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.  [ 1 post ] 
Author Message
 Post subject: Bug in org.hibernate.ejb.QueryImpl
PostPosted: Tue Mar 02, 2010 5:24 pm 
Newbie

Joined: Mon Jan 18, 2010 10:30 am
Posts: 5
Emmanuel

There seems to be a bug in the QueryImpl class in the method extractParameterInfo()

Here's what I've done:

I create an equal predicate using a Path to House.address and a Address value.

@Entity
class House
{
@Type(type="jc.AddressUserType")
@Columns(columns={@Column(name="address")})
Address address;



In the extractParameterInfo() method there is a loop that gets the javaType from a namedParameterTypeRedefinition.

It gets the javaType (Address.class) then since it is not null tries to find the hibernate Type using the TypeFactory.heuristicType() method. But given a javaType this will only work for strings, int, double etc. What is passed in is an Address not an AddressUserType.

The huristicType actually returns an hibernate SerializableType and resets the descriptor which was correct in the first place.

I've fix this for myself my just commenting out the call to resetExpectedType but there must be a good reason why this call is made there correct?

Again I've put this on the forum.
Thanks
Jean-Claude

@SuppressWarnings({ "unchecked", "RedundantCast" })
private void extractParameterInfo(Map<String,Class> namedParameterTypeRedefinition) {
if ( ! AbstractQueryImpl.class.isInstance( query ) ) {
throw new IllegalStateException( "Unknown query type for parameter extraction" );
}

HashSet<Parameter<?>> parameters = new HashSet<Parameter<?>>();
AbstractQueryImpl queryImpl = AbstractQueryImpl.class.cast( query );

// extract named params
for ( String name : (Set<String>) queryImpl.getParameterMetadata().getNamedParameterNames() ) {
final NamedParameterDescriptor descriptor =
queryImpl.getParameterMetadata().getNamedParameterDescriptor( name );
Class javaType = namedParameterTypeRedefinition.get( name );
if ( javaType != null ) {
descriptor.resetExpectedType(
TypeFactory.heuristicType( javaType.getName() )
);
}
else if ( descriptor.getExpectedType() != null ) {
javaType = descriptor.getExpectedType().getReturnedClass();
}
final ParameterImpl parameter = new ParameterImpl( name, javaType );
parameters.add( parameter );
if ( descriptor.isJpaStyle() ) {
if ( jpaPositionalIndices == null ) {
jpaPositionalIndices = new HashSet<Integer>();
}
jpaPositionalIndices.add( Integer.valueOf( name ) );
}
}


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

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.