[hibernate-issues] [Hibernate-JIRA] Commented: (HHH-2828) criteria search by class throws org.hibernate.QueryException: Unsupported discriminator type null when mapping exists for this class

Tim Vasil (JIRA) noreply at atlassian.com
Fri Oct 26 16:57:39 EDT 2007


    [ http://opensource.atlassian.com/projects/hibernate/browse/HHH-2828?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_28578 ] 

Tim Vasil commented on HHH-2828:
--------------------------------

I mentioned a workaround in 2571--you can create your own Hibernate UserType class based on Hibernate's ClassType.  You just need to convert the class to a string in nullSafeSet (using Class.getName), and from a string to a class in nullSafeGet (using ReflectHelper.classForName).

> criteria search by class throws org.hibernate.QueryException: Unsupported discriminator type null  when mapping exists for this class
> -------------------------------------------------------------------------------------------------------------------------------------
>
>                 Key: HHH-2828
>                 URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-2828
>             Project: Hibernate3
>          Issue Type: Bug
>          Components: core
>    Affects Versions: 3.2.5
>         Environment: hibernate 3.2.5, oracle 10g
>            Reporter: jo desmet
>         Attachments: src.zip
>
>
> when making a criteria based on a property of type class the query succeeds if this class is not mapped, the query building fails when this class is mapped within hibernate and has no discriminator
> e.g. code :
>                 Criteria l = session.createCriteria(SearchClass.class);
>                 l.add(Restrictions.eq("type", ClassWithNoMapping.class));  // SUCCESS
>                 java.util.List result = l.list();
>                 l = session.createCriteria(SearchClass.class);
>                 l.add(Restrictions.eq("type", ClassWithMapping.class));   // EXCEPTION
>                 result = l.list();
> exception is 
> Hibernate: select this_.ID as ID0_0_, this_.name as name0_0_, this_.type as type0_0_ from SEARCHCLASS this_ where this_.type=?
> org.hibernate.QueryException: Unsupported discriminator type null
> 	at org.hibernate.loader.criteria.CriteriaQueryTranslator.getTypedValue(CriteriaQueryTranslator.java:499)
> 	at org.hibernate.criterion.SimpleExpression.getTypedValues(SimpleExpression.java:71)
> 	at org.hibernate.loader.criteria.CriteriaQueryTranslator.getQueryParameters(CriteriaQueryTranslator.java:251)
> 	at org.hibernate.loader.criteria.CriteriaLoader.list(CriteriaLoader.java:95)
> 	at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1569)
> 	at org.hibernate.impl.CriteriaImpl.list(CriteriaImpl.java:283)
> 	at Test.list(Test.java:40)
> 	at Test.main(Test.java:27)
> 	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> 	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
> 	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
> 	at java.lang.reflect.Method.invoke(Method.java:597)
> 	at com.intellij.rt.execution.application.AppMain.main(AppMain.java:90)
> classes are attached, tables should exists but no data is required.
> Please also provide workaround on short term if possible

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://opensource.atlassian.com/projects/hibernate/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        



More information about the hibernate-issues mailing list