|
29 | 29 | import org.hibernate.HibernateException; |
30 | 30 | import org.hibernate.LockMode; |
31 | 31 | import org.hibernate.LockOptions; |
| 32 | +import org.hibernate.MappingException; |
32 | 33 | import org.hibernate.NonUniqueResultException; |
33 | 34 | import org.hibernate.PropertyNotFoundException; |
34 | 35 | import org.hibernate.ScrollMode; |
35 | 36 | import org.hibernate.ScrollableResults; |
| 37 | +import org.hibernate.Session; |
36 | 38 | import org.hibernate.TypeMismatchException; |
37 | 39 | import org.hibernate.engine.query.spi.EntityGraphQueryHint; |
38 | 40 | import org.hibernate.engine.query.spi.HQLQueryPlan; |
|
54 | 56 | import org.hibernate.property.access.spi.BuiltInPropertyAccessStrategies; |
55 | 57 | import org.hibernate.property.access.spi.Getter; |
56 | 58 | import org.hibernate.property.access.spi.PropertyAccess; |
| 59 | +import org.hibernate.proxy.HibernateProxyHelper; |
57 | 60 | import org.hibernate.query.ParameterMetadata; |
58 | 61 | import org.hibernate.query.QueryParameter; |
59 | 62 | import org.hibernate.query.spi.QueryImplementor; |
60 | 63 | import org.hibernate.query.spi.QueryParameterBinding; |
61 | 64 | import org.hibernate.transform.ResultTransformer; |
| 65 | +import org.hibernate.type.SerializableType; |
62 | 66 | import org.hibernate.type.StandardBasicTypes; |
63 | 67 | import org.hibernate.type.Type; |
64 | 68 |
|
@@ -531,11 +535,33 @@ protected Type determineType(String namedParam, Class retType) { |
531 | 535 | type = parameterMetadata.getQueryParameter( namedParam ).getType(); |
532 | 536 | } |
533 | 537 | if ( type == null ) { |
534 | | - type = StandardBasicTypes.SERIALIZABLE; |
| 538 | + type = guessType( retType ); |
535 | 539 | } |
536 | 540 | return type; |
537 | 541 | } |
538 | 542 |
|
| 543 | + private Type guessType(Class clazz) throws HibernateException { |
| 544 | + String typename = clazz.getName(); |
| 545 | + Type type = getProducer().getFactory().getTypeResolver().heuristicType( typename ); |
| 546 | + boolean serializable = type != null && type instanceof SerializableType; |
| 547 | + if ( type == null || serializable ) { |
| 548 | + try { |
| 549 | + getProducer().getFactory().getMetamodel().entityPersister( clazz ); |
| 550 | + } |
| 551 | + catch ( MappingException me ) { |
| 552 | + if ( serializable ) { |
| 553 | + return type; |
| 554 | + } |
| 555 | + else { |
| 556 | + throw new HibernateException( "Could not determine a type for class: " + typename ); |
| 557 | + } |
| 558 | + } |
| 559 | + return ( (Session) getProducer() ).getTypeHelper().entity( clazz ); |
| 560 | + } |
| 561 | + else { |
| 562 | + return type; |
| 563 | + } |
| 564 | + } |
539 | 565 |
|
540 | 566 | @Override |
541 | 567 | @SuppressWarnings("unchecked") |
|
0 commit comments