[Hibernate-JIRA] Created: (HHH-3300) HQL looks for property in wrong class and reports "could not resolve property"
by Cristian Bogdan (JIRA)
HQL looks for property in wrong class and reports "could not resolve property"
------------------------------------------------------------------------------
Key: HHH-3300
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-3300
Project: Hibernate3
Issue Type: Bug
Components: query-hql
Affects Versions: 3.2.6
Environment: Hibernate 3.2.6.ga, mysql 5.0.37
Reporter: Cristian Bogdan
could not resolve property: groupMembers of: projman.Project
[SELECT it.project.color AS col1 FROM projman.Deficienta def JOIN def.item it WHERE exists (FROM it.project.participants grp JOIN grp.groupMembers p WHERE p=:principal )
)) ORDER BY it.end]
the problem is, groupMembers is not a property of projman.Project, but a bag in projman,Principal.
as soon as I replace the it.project.color projection with e.g. it.start (i.e. i don't make any other join with projman.Project), the query works.
the original query is actually more complicated but i reduced my test to the above for simplicity. rewriting the query without subqueries is not an option.
i paste the relevant (generated) mappings.
<hibernate-mapping auto-import="false">
<class name="projman.Project" table="projman_Project_">
<id name="primaryKey" column="Project_">
<generator class="identity"/>
</id>
<property name="TS_modify" column="TS_modify_"/>
<property name="TS_create" column="TS_create_"/>
<property name="name">
<column name="name_" length="255"/>
</property>
<bag name="participants" table="projman_Project__participants_" cascade="all" inverse="false">
<key column="Project_"/>
<many-to-many class="projman.Principal" column="Principal_"/>
</bag>
<many-to-one name="beneficiar" column="beneficiar_" cascade="all" class="projman.Company"/>
<many-to-one name="generalDesigner" column="generalDesigner_" cascade="all" class="projman.Compa
ny"/>
<bag name="signExecution" table="projman_Project__signExecution_" cascade="all" inverse="false">
<key column="Project_"/>
<many-to-many class="projman.Company" column="Company_"/>
</bag>
<property name="color">
<column name="color_" length="6"/>
</property>
</class>
</hibernate-mapping>
<hibernate-mapping auto-import="false">
<class name="projman.Principal" table="projman_Principal_">
<id name="primaryKey" column="Principal_">
<generator class="identity"/>
</id>
<property name="TS_modify" column="TS_modify_"/>
<property name="TS_create" column="TS_create_"/>
<property name="kind" column="kind_"/>
<bag name="groupMembers" table="projman_Principal__groupMembers_" cascade="all" inverse="false">
<key column="Principal_"/>
<many-to-many class="projman.Principal" column="Principal__"/>
</bag>
<property name="displayName">
<column name="displayName_" length="255"/>
</property>
</class>
</hibernate-mapping>
<hibernate-mapping auto-import="false">
<class name="projman.Deficienta" table="projman_Deficienta_">
<id name="primaryKey" column="Deficienta_">
<generator class="identity"/>
</id>
<property name="TS_modify" column="TS_modify_"/>
<property name="TS_create" column="TS_create_"/>
<many-to-one name="item" column="item_" cascade="all" class="projman.Item"/>
<many-to-one name="firma" column="firma_" cascade="all" class="projman.Company"/>
<bag name="alteFirme" table="projman_Deficienta__alteFirme_" cascade="all" inverse="false">
<key column="Deficienta_"/>
<many-to-many class="projman.Company" column="Company_"/>
</bag>
<property name="amenda" column="amenda_"/>
</class>
</hibernate-mapping>
<hibernate-mapping auto-import="false">
<class name="projman.Item" table="projman_Item_">
<id name="primaryKey" column="Item_">
<generator class="identity"/>
</id>
<property name="TS_modify" column="TS_modify_"/>
<property name="TS_create" column="TS_create_"/>
<many-to-one name="project" column="project_" cascade="all" class="projman.Project"/>
<property name="type" column="type_"/>
<bag name="toWhom" table="projman_Item__toWhom_" cascade="all" inverse="false">
<key column="Item_"/>
<many-to-many class="projman.Principal" column="Principal_"/>
</bag>
<property name="subject">
<column name="subject_" length="255"/>
</property>
<property name="description" type="org.makumba.db.hibernate.TextUserType">
<column name="description_" sql-type="longtext"/>
</property>
<many-to-one name="creator" column="creator_" cascade="all" class="projman.Principal"/>
<property name="creationDate" column="creationDate_"/>
<property name="start" column="start_"/>
<property name="end" column="end_"/>
<bag name="events" inverse="true" cascade="none">
<key column="Item_"/>
<one-to-many class="projman.Item__events"/>
</bag>
<bag name="attachments" table="projman_Item__attachments_" cascade="all" inverse="false">
<key column="Item_"/>
<many-to-many class="projman.Document" column="Document_"/>
</bag>
</class>
</hibernate-mapping>
--
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....
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
12 years, 7 months
[Hibernate-JIRA] Created: (EJB-363) @OrderBy applied to collection property of derived class does not work properly when column used for ordering belongs to base class (using MySQL 5)
by Rich Eggert (JIRA)
@OrderBy applied to collection property of derived class does not work properly when column used for ordering belongs to base class (using MySQL 5)
---------------------------------------------------------------------------------------------------------------------------------------------------
Key: EJB-363
URL: http://opensource.atlassian.com/projects/hibernate/browse/EJB-363
Project: Hibernate Entity Manager
Issue Type: Bug
Components: EntityManager
Affects Versions: 3.3.2.GA
Environment: MySQL 5.0.18, Hibernate Core 3.2.6, Hibernate EntityManager 3.3.2, and the MySQL5InnoDBDialect.
Test run with Tomcat 6.0.16 (Sun JDK 1.6.0_06) and Spring Framework 2.5.3.
Relying on Hibernate automatic DDL generation (hibernate.hbm2ddl.auto=update), which appears to be working properly.
Reporter: Rich Eggert
Attachments: SampleBase.java, SampleDerived.java, SampleServiceImpl.java
I applied the (JPA) @OrderBy annotation to a collection of entities belonging to an entity class (named SampleDerived in the attached sample code) of the same type (i.e., the class has a one-to-many parent-child relationship to itself). The property name passed as the argument to the @OrderBy annotation refers to a property of the base class (named SampleBase in the example), which employs the "JOINED" inheritence strategy.
When I attempted to access the collection of a persisted instance of the entity class (in the example, this is accomplished by calling SampleServiceImpl.createSample() followed by calling SampleServiceImpl.findChildren() against the return value), the following (root cause) exception is generated:
com.mysql.jdbc.exceptions.MySQLSyntaxErrorException: Unknown column 'SampleBase.timestamp' in 'order clause'
com.mysql.jdbc.SQLError.createSQLException(SQLError.java:936)
com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2870)
com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1573)
com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1665)
com.mysql.jdbc.Connection.execSQL(Connection.java:3176)
com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1153)
com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:1266)
org.apache.tomcat.dbcp.dbcp.DelegatingPreparedStatement.executeQuery(DelegatingPreparedStatement.java:93)
org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:186)
org.hibernate.loader.Loader.getResultSet(Loader.java:1787)
org.hibernate.loader.Loader.doQuery(Loader.java:674)
org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:236)
org.hibernate.loader.Loader.loadCollection(Loader.java:1994)
org.hibernate.loader.collection.CollectionLoader.initialize(CollectionLoader.java:36)
org.hibernate.persister.collection.AbstractCollectionPersister.initialize(AbstractCollectionPersister.java:565)
org.hibernate.event.def.DefaultInitializeCollectionEventListener.onInitializeCollection(DefaultInitializeCollectionEventListener.java:63)
org.hibernate.impl.SessionImpl.initializeCollection(SessionImpl.java:1716)
org.hibernate.collection.AbstractPersistentCollection.initialize(AbstractPersistentCollection.java:344)
org.hibernate.collection.AbstractPersistentCollection.read(AbstractPersistentCollection.java:86)
org.hibernate.collection.PersistentBag.iterator(PersistentBag.java:249)
org.frecklepuppy.bb.service.impl.SampleServiceImpl.findChildren(SampleServiceImpl.java:52)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
java.lang.reflect.Method.invoke(Method.java:597)
org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:310)
org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:182)
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:149)
org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:106)
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
$Proxy209.findChildren(Unknown Source)
org.frecklepuppy.bb.ui.controllers.IndexController.listForums(IndexController.java:66)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
java.lang.reflect.Method.invoke(Method.java:597)
org.springframework.web.bind.annotation.support.HandlerMethodInvoker.doInvokeMethod(HandlerMethodInvoker.java:413)
org.springframework.web.bind.annotation.support.HandlerMethodInvoker.invokeHandlerMethod(HandlerMethodInvoker.java:134)
org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.invokeHandlerMethod(AnnotationMethodHandlerAdapter.java:310)
org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.handle(AnnotationMethodHandlerAdapter.java:297)
org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:875)
org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:809)
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:523)
org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:453)
javax.servlet.http.HttpServlet.service(HttpServlet.java:690)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
org.springframework.security.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:359)
org.springframework.security.intercept.web.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:109)
org.springframework.security.intercept.web.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:83)
org.springframework.security.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:371)
org.springframework.security.ui.ExceptionTranslationFilter.doFilterHttp(ExceptionTranslationFilter.java:101)
org.springframework.security.ui.SpringSecurityFilter.doFilter(SpringSecurityFilter.java:53)
org.springframework.security.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:371)
org.springframework.security.providers.anonymous.AnonymousProcessingFilter.doFilterHttp(AnonymousProcessingFilter.java:105)
org.springframework.security.ui.SpringSecurityFilter.doFilter(SpringSecurityFilter.java:53)
org.springframework.security.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:371)
org.springframework.security.ui.rememberme.RememberMeProcessingFilter.doFilterHttp(RememberMeProcessingFilter.java:109)
org.springframework.security.ui.SpringSecurityFilter.doFilter(SpringSecurityFilter.java:53)
org.springframework.security.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:371)
org.springframework.security.wrapper.SecurityContextHolderAwareRequestFilter.doFilterHttp(SecurityContextHolderAwareRequestFilter.java:91)
org.springframework.security.ui.SpringSecurityFilter.doFilter(SpringSecurityFilter.java:53)
org.springframework.security.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:371)
org.springframework.security.ui.basicauth.BasicProcessingFilter.doFilterHttp(BasicProcessingFilter.java:172)
org.springframework.security.ui.SpringSecurityFilter.doFilter(SpringSecurityFilter.java:53)
org.springframework.security.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:371)
org.springframework.security.ui.AbstractProcessingFilter.doFilterHttp(AbstractProcessingFilter.java:268)
org.springframework.security.ui.SpringSecurityFilter.doFilter(SpringSecurityFilter.java:53)
org.springframework.security.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:371)
org.springframework.security.ui.logout.LogoutFilter.doFilterHttp(LogoutFilter.java:87)
org.springframework.security.ui.SpringSecurityFilter.doFilter(SpringSecurityFilter.java:53)
org.springframework.security.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:371)
org.springframework.security.ui.SessionFixationProtectionFilter.doFilterHttp(SessionFixationProtectionFilter.java:68)
org.springframework.security.ui.SpringSecurityFilter.doFilter(SpringSecurityFilter.java:53)
org.springframework.security.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:371)
org.springframework.security.context.HttpSessionContextIntegrationFilter.doFilterHttp(HttpSessionContextIntegrationFilter.java:235)
org.springframework.security.ui.SpringSecurityFilter.doFilter(SpringSecurityFilter.java:53)
org.springframework.security.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:371)
org.springframework.security.securechannel.ChannelProcessingFilter.doFilterHttp(ChannelProcessingFilter.java:116)
org.springframework.security.ui.SpringSecurityFilter.doFilter(SpringSecurityFilter.java:53)
org.springframework.security.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:371)
org.springframework.security.util.FilterChainProxy.doFilter(FilterChainProxy.java:174)
org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:183)
org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:138)
I verified (using MySQL Administrator) that the SampleBase.timestamp column does, in fact, exist. According to the org.hibernate.SQL log, the offending SQL statement looks like this:
select children0_.parent_id as parent2_1_, children0_.id as id1_, children0_.id as id5_0_, children0_1_.timestamp as timestamp5_0_, children0_.parent_id as parent2_6_0_ from SampleDerived children0_ inner join SampleBase children0_1_ on children0_.id=children0_1_.id where children0_.parent_id=? order by SampleBase.timestamp asc
I believe the problem is that MySQL 5 requires that the alias for the base class table used in the FROM clause (children0_1_ in this case) be used in the ORDER BY clause, instead of the actual name of the base class table. After browsing various MySQL discussions, it appears this is new to MySQL 5 (versus 4 or earlier) and was done in order to be more standards compliant.
It's unclear to me whether this affects Hibernate Core or is limited to EntityManager. I'll try to narrow down the problem further as time permits (which it isn't likely to do any time soon).
--
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....
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
12 years, 7 months
[Hibernate-JIRA] Created: (HHH-3577) Wrong SQL in order by clause when using joined subclasses
by Hardy Ferentschik (JIRA)
Wrong SQL in order by clause when using joined subclasses
---------------------------------------------------------
Key: HHH-3577
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-3577
Project: Hibernate Core
Issue Type: Bug
Components: core
Reporter: Hardy Ferentschik
Assignee: Steve Ebersole
The changes for HHH-2802 seem to have broken the following tests in Annotations:
* ManyToManyTest.testOrderByContractor()
* OneToManyTest.testOrderByOnSuperclassProperty()
Prior to the changes for HHH-2802 no table aliases where generated for in the SQL for these tests. Since it is generally a problem to generate the right table alias in case of joined subclasses there is a workaround in CollectionBinder.buildOrderByClauseFromHql() line 910 where the table name is explicitly set in the oder by clause. This workaround together with the changes for HHH-2802 now generate illegal SQL, eg:
select
contractor0_.EMPLOYER_ID as EMPLOYER1_1_,
contractor0_.CONTRACTOR_ID as CONTRACTOR2_1_,
contractor1_.id as id2_0_,
contractor1_1_.fld_name as fld2_2_0_,
contractor1_.hourlyRate as hourlyRate3_0_
from
EMPLOYER_CONTRACTOR contractor0_
left outer join
Contractor contractor1_
on contractor0_.CONTRACTOR_ID=contractor1_.id
left outer join
Employee contractor1_1_
on contractor1_.id=contractor1_1_.id
where
contractor0_.EMPLOYER_ID=?
order by
contractor1_.Employee.fld_name desc
Hibernate:
select
contractor0_.EMPLOYER_ID as EMPLOYER1_1_,
contractor0_.CONTRACTOR_ID as CONTRACTOR2_1_,
contractor1_.id as id2_0_,
contractor1_1_.fld_name as fld2_2_0_,
contractor1_.hourlyRate as hourlyRate3_0_
from
EMPLOYER_CONTRACTOR contractor0_
left outer join
Contractor contractor1_
on contractor0_.CONTRACTOR_ID=contractor1_.id
left outer join
Employee contractor1_1_
on contractor1_.id=contractor1_1_.id
where
contractor0_.EMPLOYER_ID=?
order by
contractor1_.Employee.fld_name desc
In this case 'contractor1_' is generated by the changes made for HHH-2802 whereas 'Employee' is added by the workaround. Note that even though Employee is not working for all databases, the generated alias is wrong and should be 'contractor1_1_.
For now I commented out the failing tests since I cannot use the test skipping functionality in Annotations yet.
--
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....
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
12 years, 7 months
[Hibernate-JIRA] Created: (HHH-4044) ejbql select count() and composite keys problem
by Thierry Accart (JIRA)
ejbql select count() and composite keys problem
-----------------------------------------------
Key: HHH-4044
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-4044
Project: Hibernate Core
Issue Type: Bug
Components: core
Affects Versions: 3.2.6
Environment: Jboss 4.2.2, JDK 1.5.18, Seam 2.1.2, MSSQL2000
Reporter: Thierry Accart
Priority: Critical
Hi
we're using seam 2.1.2 on JBoss 4.2.2 with JDK 1.5.18.
Our db is hosted on mssql server.
our persistence.xml contains sets hibernate.dialect to org.hibernate.dialect.SQLServerDialect.
UserRole is an entity containing userid and roleid as a composite key.
When the following ejbql query is run :
select count(userRole) from UserRole userRole
sql receives the following statement :
declare @P1 int
set @P1=NULL
declare @P2 int
set @P2=0
declare @P3 int
set @P3=0
exec sp_cursorprepexec @P1 output, @P2 output, NULL, N'select count((userrole0_.roleId, userrole0_.userId)) as col_0_0_ from TP_UM_UserRole userrole0_', 16, 8193, @P3 output
select @P1, @P2, @P3
the count((userrole0_.roleId, userrole0_.userId)) is not understood by mssql server, causing an error " Incorrect syntax near ','."
I think that a simple select count (*) would work fine.
--
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....
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
12 years, 7 months
[Hibernate-JIRA] Created: (HHH-6044) Compound ID with auto-generated part produces exception
by Alex Shubert (JIRA)
Compound ID with auto-generated part produces exception
-------------------------------------------------------
Key: HHH-6044
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-6044
Project: Hibernate Core
Issue Type: Bug
Components: core
Affects Versions: 3.5.6
Environment: java 6.23 64bit
Hibernate 3.5.6
Reporter: Alex Shubert
@Entity
public class TestRow implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@Id
private Long version;
setters and getters are ommited for it's triviality
}
2. creating database and table by hand
#mysql -u username ...
create table F_TESTROW (ID bigint not null auto_increment, VERSION bigint not null, primary key (VERSION, ID))
TestRow testRow = new TestRow();
testRow.setVersion(2L);
testRow.setAddr("somewhere");
sessionFactory.openSession().save(testRow);
produces
java.lang.IllegalArgumentException: Can not set java.lang.Long field ru.kctsoft.fenestro.domain.strategy.TestRow.id to org.hibernate.id.IdentifierGeneratorHelper$2
at org.hibernate.property.DirectPropertyAccessor$DirectSetter.set(DirectPropertyAccessor.java:139)
This is kinda frustrating.
http://docs.jboss.org/hibernate/stable/annotations/reference/en/html_single/
2.2.3.2.4. Partial identifier generation
Hibernate supports the automatic generation of some of the identifier properties. Simply use the @GeneratedValue annotation on one or several id properties.
--
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....
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
12 years, 7 months
[Hibernate-JIRA] Created: (HHH-5396) JPQL KEY() and VALUE() not implemented
by Harald Wellmann (JIRA)
JPQL KEY() and VALUE() not implemented
--------------------------------------
Key: HHH-5396
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-5396
Project: Hibernate Core
Issue Type: Bug
Affects Versions: 3.5.3
Environment: Hibernate 3.5.3, PostgreSQL 8.4.3
Reporter: Harald Wellmann
The KEY() and VALUE() operators for persistent maps do not seem to be implemented in Hibernate.
E.g. consider the query
{code}
select m.text from MultilingualString s join s.map m where key(m) = 'de'
{code}
given the following classes and mappings.
{code:java}
@Embeddable
public class LocalizedString {
private String language;
@Column(name = "_text")
private String text;
}
@Entity
@Table(schema = "jpa", name = "multilingual_string")
public class MultilingualString {
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE)
@Column(name = "string_id")
private long id;
@ElementCollection(fetch=FetchType.EAGER)
@MapKeyColumn(name = "language_key", insertable = false, updatable = false)
@CollectionTable(schema = "jpa", name = "multilingual_string_map", joinColumns = @JoinColumn(name = "string_id"))
private Map<String, LocalizedString> map = new HashMap<String, LocalizedString>();
}
{code}
(Note that these mappings are similar to but slightly different from the ones I used in HHH-5393. This time the map key column has a different name, creating a redundant column I would have liked to avoid. That way, Hibernate is at least happy about the mapping.)
Running the query, I get the following exception:
java.lang.IllegalArgumentException: org.hibernate.hql.ast.QuerySyntaxException: unexpected AST node: [select m.text from de.myjourney.model.media.MultilingualString s join s.map m where key(m) = 'de']
at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1222)
at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1168)
at org.hibernate.ejb.AbstractEntityManagerImpl.createQuery(AbstractEntityManagerImpl.java:292)
at de.myjourney.model.test.MultilingualStringTest.createGerman(MultilingualStringTest.java:35)
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 org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:76)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:46)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused by: org.hibernate.hql.ast.QuerySyntaxException: unexpected AST node: [select m.text from de.myjourney.model.media.MultilingualString s join s.map m where key(m) = 'de']
at org.hibernate.hql.ast.QuerySyntaxException.convert(QuerySyntaxException.java:54)
at org.hibernate.hql.ast.QuerySyntaxException.convert(QuerySyntaxException.java:47)
at org.hibernate.hql.ast.ErrorCounter.throwQueryException(ErrorCounter.java:82)
at org.hibernate.hql.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:261)
at org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:185)
at org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:136)
at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:101)
at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:80)
at org.hibernate.engine.query.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:98)
at org.hibernate.impl.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:156)
at org.hibernate.impl.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:135)
at org.hibernate.impl.SessionImpl.createQuery(SessionImpl.java:1760)
at org.hibernate.ejb.AbstractEntityManagerImpl.createQuery(AbstractEntityManagerImpl.java:277)
... 23 more
Using upper-case 'KEY(m)', the exception is different:
javax.persistence.PersistenceException: org.hibernate.exception.SQLGrammarException: could not execute query
at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1235)
at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1168)
at org.hibernate.ejb.QueryImpl.getResultList(QueryImpl.java:250)
at de.myjourney.model.test.MultilingualStringTest.createGerman(MultilingualStringTest.java:36)
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 org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:76)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:46)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused by: org.hibernate.exception.SQLGrammarException: could not execute query
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:92)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)
at org.hibernate.loader.Loader.doList(Loader.java:2297)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2172)
at org.hibernate.loader.Loader.list(Loader.java:2167)
at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:448)
at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:363)
at org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:196)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1258)
at org.hibernate.impl.QueryImpl.list(QueryImpl.java:102)
at org.hibernate.ejb.QueryImpl.getResultList(QueryImpl.java:241)
... 23 more
Caused by: org.postgresql.util.PSQLException: FEHLER: Funktion key(bigint) existiert nicht
Hint: Keine Funktion stimmt mit dem angegebenen Namen und den Argumenttypen überein. Sie müssen möglicherweise ausdrückliche Typumwandlungen hinzufügen.
Position: 161
at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2062)
at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1795)
at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:257)
at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:479)
at org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:367)
at org.postgresql.jdbc2.AbstractJdbc2Statement.executeQuery(AbstractJdbc2Statement.java:271)
at org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:208)
at org.hibernate.loader.Loader.getResultSet(Loader.java:1849)
at org.hibernate.loader.Loader.doQuery(Loader.java:718)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:270)
at org.hibernate.loader.Loader.doList(Loader.java:2294)
... 31 more
(The message from PostgreSQL means "Function key(bigint) does not exist".)
I had a look at the ANTLR grammar for the query parser a while ago (which may have been before 3.5.3), and as far as I could make out, key() and value() are only recognized as lower case keywords, and while the parser accepts the syntax, it fails to generate any appropriate actions.
The stack traces are up-to-date though, I just ran my test cases on Hibernate 3.5.3.
--
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....
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
12 years, 7 months
[Hibernate-JIRA] Created: (HHH-2828) criteria search by class throws org.hibernate.QueryException: Unsupported discriminator type null when mapping exists for this class
by jo desmet (JIRA)
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....
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
12 years, 8 months