Hibernate version: 3.0.5
Mapping documents:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<!-- Generated file - Do not edit! -->
<hibernate-configuration>
<!-- a SessionFactory instance listed as /jndi/name -->
<session-factory>
<!-- properties -->
<property name="connection.datasource">java:comp/env/jdbc/slateHibernate</property>
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="show_sql">true</property>
<property name="use_outer_join">false</property>
<!-- mapping files -->
<mapping resource="slate/util/SlateRole.hbm.xml"/>
<mapping resource="slate/util/SlateUser.hbm.xml"/>
<mapping resource="slate/components/SlateComponentStyle.hbm.xml"/>
<mapping resource="slate/util/SlatePriviledge.hbm.xml"/>
<mapping resource="slate/components/SlateComponent.hbm.xml"/>
</session-factory>
</hibernate-configuration>
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping
>
<class
name="slate.components.SlateComponent"
table="SlateComponent"
discriminator-value="Abstract"
>
<id
name="ID"
column="nSlateID"
type="java.lang.Long"
>
<generator class="native">
<!--
To add non XDoclet generator parameters, create a file named
hibernate-generator-params-SlateComponent.xml
containing the additional parameters and place it in your merge dir.
-->
</generator>
</id>
<discriminator
column="cSubclass"
length="20"
/>
<version
name="version"
column="nVersion"
type="long"
/>
<many-to-one
name="parent"
class="slate.components.SlateComponent"
cascade="none"
outer-join="auto"
update="true"
insert="true"
column="nParentSlateID"
/>
<bag
name="children"
lazy="false"
inverse="true"
cascade="all-delete-orphan"
order-by="nOrder"
>
<key
column="nParentSlateID"
>
</key>
<one-to-many
class="slate.components.SlateComponent"
/>
</bag>
<property
name="basename"
type="java.lang.String"
update="true"
insert="true"
column="cBasename"
length="50"
not-null="true"
/>
<property
name="path"
type="java.lang.String"
update="true"
insert="true"
column="cPath"
length="250"
not-null="true"
unique="true"
/>
<property
name="index"
type="int"
update="true"
insert="true"
column="nOrder"
not-null="true"
/>
<set
name="ancestorsAndSelf"
table="SlateComponentAncestor"
lazy="false"
cascade="none"
sort="natural"
order-by="nLevel"
>
<key
column="nSlateID"
>
</key>
<many-to-many
class="slate.components.SlateComponent"
column="nAncestorSlateID"
outer-join="auto"
/>
</set>
<set
name="rolePriviledges"
table="SlateComponentRolePriviledge"
lazy="false"
cascade="none"
sort="unsorted"
>
<key
column="nSlateID"
>
</key>
<composite-element
class="slate.components.SlateComponentRolePriviledge"
>
<parent
name="slateComponent"
/>
<many-to-one
name="slateRole"
class="slate.util.SlateRole"
cascade="none"
outer-join="auto"
update="true"
insert="true"
column="cRoleID"
not-null="true"
/>
<many-to-one
name="slatePriviledge"
class="slate.util.SlatePriviledge"
cascade="none"
outer-join="auto"
update="true"
insert="true"
column="nPriviledgeID"
not-null="true"
/>
<property
name="value"
type="int"
update="true"
insert="true"
column="nValue"
not-null="true"
/>
</composite-element>
</set>
<many-to-one
name="style"
class="slate.components.SlateComponentStyle"
cascade="none"
outer-join="auto"
update="true"
insert="true"
column="nStyleID"
not-null="true"
/>
<!--
To add non XDoclet property mappings, create a file named
hibernate-properties-SlateComponent.xml
containing the additional properties and place it in your merge dir. -->
<subclass
name="slate.components.SlatePage"
discriminator-value="SlatePage"
>
<property
name="pageTitle"
type="java.lang.String"
update="true"
insert="true"
column="cTitle"
length="50"
/>
<!--
To add non XDoclet property mappings, create a file named
hibernate-properties-SlatePage.xml
containing the additional properties and place it in your merge
dir.
-->
</subclass>
<subclass
name="slate.components.SlatePageComponent"
discriminator-value="AbstractPC"
>
<property
name="pageTitle"
type="java.lang.String"
update="true"
insert="true"
column="cTitle"
length="50"
/>
<!--
To add non XDoclet property mappings, create a file named
hibernate-properties-SlatePage.xml
containing the additional properties and place it in your merge
dir.
-->
</subclass>
<subclass
name="slate.components.SlatePageComponent"
discriminator-value="AbstractPC"
>
<!--
To add non XDoclet property mappings, create a file named
hibernate-properties-SlatePageComponent.xml
containing the additional properties and place it in your merge
dir.
-->
<subclass
name="slate.components.Text"
discriminator-value="Text"
>
<property
name="text"
type="text"
update="true"
insert="true"
column="cText"
/>
<!--
To add non XDoclet property mappings, create a file named
hibernate-properties-Text.xml
containing the additional properties and place it in your merge
dir.
-->
</subclass>
</subclass>
</class>
</hibernate-mapping>
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping
>
<class
name="slate.util.SlateRole"
table="SlateRole"
>
<id
name="rolename"
column="cRoleID"
type="java.lang.String"
length="32"
>
<generator class="assigned">
<!--
To add non XDoclet generator parameters, create a file named
hibernate-generator-params-SlateRole.xml
containing the additional parameters and place it in your merge dir.
-->
</generator>
</id>
<version
name="version"
column="nVersion"
type="long"
/>
<property
name="description"
type="java.lang.String"
update="true"
insert="true"
column="cDescription"
not-null="true"
/>
<!--
To add non XDoclet property mappings, create a file named
hibernate-properties-SlateRole.xml
containing the additional properties and place it in your merge dir. -->
</class>
</hibernate-mapping>
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping
>
<class
name="slate.util.SlatePriviledge"
table="SlatePriviledge"
mutable="false"
>
<id
name="ID"
column="nPriviledgeID"
type="java.lang.Long"
>
<generator class="native">
<!--
To add non XDoclet generator parameters, create a file named
hibernate-generator-params-SlatePriviledge.xml
containing the additional parameters and place it in your merge dir.
-->
</generator>
</id>
<version
name="version"
column="nVersion"
type="long"
/>
<property
name="priviledge"
type="java.lang.String"
update="true"
insert="true"
column="cPriviledge"
length="3"
not-null="true"
unique="true"
/>
<property
name="description"
type="java.lang.String"
update="true"
insert="true"
column="cDescription"
not-null="true"
/>
</class>
Code between sessionFactory.openSession() and session.close():The following works:
Code:
session
.createQuery(
"SELECT scrp.value FROM"
+ " SlateComponent AS sc"
+ " INNER JOIN sc.ancestorsAndSelf AS ancestor"
+ " INNER JOIN ancestor.rolePriviledges AS scrp"
+ " INNER JOIN scrp.slatePriviledge AS sp"
+ " WHERE"
+ " sc = :slatecomponent"
+ " AND scrp.slateRole = :slaterole"
+ " AND sp = :slatepriviledge"
+ " ORDER BY ancestor DESC")
.setFirstResult(0).setMaxResults(1)
.setEntity("slatecomponent", sc)
.setEntity("slaterole", sr)
.setEntity("slatepriviledge", sp)
.uniqueResult());
the following doesn't
Code:
session
.createQuery(
"SELECT new slate.components.SlateComponentRolePriviledge(ancestor, scrp.slateRole, scrp.slatePriviledge, scrp.value) FROM"
+ " SlateComponent AS sc"
+ " INNER JOIN sc.ancestorsAndSelf AS ancestor"
+ " INNER JOIN ancestor.rolePriviledges AS scrp"
+ " INNER JOIN scrp.slatePriviledge AS sp"
+ " WHERE"
+ " sc = :slatecomponent"
+ " AND scrp.slateRole = :slaterole"
+ " AND sp = :slatepriviledge"
+ " ORDER BY ancestor DESC")
.setFirstResult(0).setMaxResults(1)
.setEntity("slatecomponent", sc)
.setEntity("slaterole", sr)
.setEntity("slatepriviledge", sp)
.uniqueResult());
Full stack trace of any exception that occurs:Code:
Hibernate: select slatecompo2_.nSlateID as col_0_0_, roleprivil3_.cRoleID as col_1_0_, roleprivil3_.nPriviledgeID as col_2_0_, roleprivil3_.nValue as col_3_0_ from SlateComponent slatecompo0_ inner join SlateComponentAncestor ancestorsa1_ on slatecompo0_.nSlateID=ancestorsa1_.nSlateID inner join SlateComponent slatecompo2_ on ancestorsa1_.nAncestorSlateID=slatecompo2_.nSlateID inner join SlateComponentRolePriviledge roleprivil3_ on slatecompo2_.nSlateID=roleprivil3_.nSlateID SlatePriviledge slateprivi4_ SlateRole slaterole5_ where roleprivil3_.cRoleID=slaterole5_.cRoleID and roleprivil3_.nPriviledgeID=slateprivi4_.nPriviledgeID and slatecompo0_.nSlateID=? and roleprivil3_.cRoleID=? and slateprivi4_.nPriviledgeID=? order by slatecompo2_.nSlateID DESC limit ?
1-Jun-2005 12:03:37 PM org.hibernate.util.JDBCExceptionReporter logExceptions
WARNING: SQL Error: 1064, SQLState: 42000
1-Jun-2005 12:03:37 PM org.hibernate.util.JDBCExceptionReporter logExceptions
SEVERE: Syntax error or access violation message from server: "You have an error in your SQL syntax near 'SlatePriviledge slateprivi4_ SlateRole slaterole5_ where roleprivil3_.cRoleID=sl' at line 1"
1-Jun-2005 12:03:37 PM slate.util.SlateSystem getSlateComponentRolePriviledges(SlateComponent)
FINER: THROW
slate.util.SlatePersistException: Error getting SlateComponentRolePriviledges:
at slate.util.SlateSystem.getSlateComponentRolePriviledges(SlateSystem.java:2699)
at slate.components.SlatePage.getChildWrapperOpen(SlatePage.java:401)
at slate.components.SlatePage$3.visit(SlatePage.java:296)
at slate.components.Text.accept(Text.java:122)
at slate.components.SlatePage.getContentHTML(SlatePage.java:309)
at slate.components.SlatePage.readHTML(SlatePage.java:264)
at slate.components.SlatePage$$FastClassByCGLIB$$cb093c05.invoke(<generated>)
at net.sf.cglib.proxy.MethodProxy.invoke(MethodProxy.java:149)
at org.hibernate.proxy.CGLIBLazyInitializer.intercept(CGLIBLazyInitializer.java:137)
at slate.components.SlatePage$$EnhancerByCGLIB$$39a04031.readHTML(<generated>)
at slate.Slate.sendPage(Slate.java:175)
at slate.Slate.doGet(Slate.java:122)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:696)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:809)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:200)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:146)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:209)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:596)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:433)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:948) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:144)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:596)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:504)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:594)
at org.apache.catalina.valves.CertificatesValve.invoke(CertificatesValve.java:199)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:594)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:433)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:948) at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2358)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:133)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:596)
at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:118)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:594)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:116)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:594)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:433)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:948) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:127)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:596)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:433)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:948) at org.apache.coyote.tomcat4.CoyoteAdapter.service(CoyoteAdapter.java:152)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:799)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:705)
at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:577)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:683)
at java.lang.Thread.run(Thread.java:534)
Caused by: org.hibernate.exception.SQLGrammarException: could not execute query
at org.hibernate.exception.ErrorCodeConverter.convert(ErrorCodeConverter.java:70)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.loader.Loader.doList(Loader.java:1560)
at org.hibernate.loader.Loader.list(Loader.java:1540)
at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:375)
at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:271)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:791)
at org.hibernate.impl.QueryImpl.list(QueryImpl.java:74)
at org.hibernate.impl.AbstractQueryImpl.uniqueResult(AbstractQueryImpl.java:603)
at slate.util.SlateSystem.getSlateComponentRolePriviledges(SlateSystem.java:2674)
... 46 more
Caused by: java.sql.SQLException: Syntax error or access violation message from server: "You have an error in your SQL syntax near 'SlatePriviledge slateprivi4_ SlateRole slaterole5_ where roleprivil3_.cRoleID=sl' at line 1"
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:1997)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1167)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1278)
at com.mysql.jdbc.Connection.execSQL(Connection.java:2251)
at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:1586)
at org.apache.commons.dbcp.DelegatingPreparedStatement.executeQuery(DelegatingPreparedStatement.java:205)
at org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:118)
at org.hibernate.loader.Loader.getResultSet(Loader.java:1233)
at org.hibernate.loader.Loader.doQuery(Loader.java:370)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:210)
at org.hibernate.loader.Loader.doList(Loader.java:1557)
... 53 more
Name and version of the database you are using:Code:
INFO: Using datasource: java:comp/env/jdbc/slateHibernate
1-Jun-2005 12:35:16 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: RDBMS: MySQL, version: 3.23.58
1-Jun-2005 12:35:16 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: JDBC driver: MySQL-AB JDBC Driver, version: mysql-connector-java-3.0.16-ga ( $Date: 2004/09/30 07:35:03 $, $Revision: 1.27.2.44 $ )
1-Jun-2005 12:35:16 PM org.hibernate.dialect.Dialect <init>
INFO: Using dialect: org.hibernate.dialect.MySQLDialect
Basically, to retreive the properties of scrp.slateRole, scrp.slatePriviledge Hibernate is adding a JOIN to the SQL in the 'old' syntax of table1, table2, table3 but is missing out the commas. When I edit the SQL and run in the database there is no error.
Is this a bug? I believe I am following the example in Chapter 14: HQL of the documentation. THis is only the 3rd HQL statement I have written, so maybe I am missing things. I'm used to SQL Server stored procs!
I don't know how to get around this problem.