OK. Sorry for handwaving. I'm not an english native speaker, so I don't have a right feeling for "handwaving" :)
Here is my mapping:
Code:
<hibernate-mapping package="cz.presto.didacticus.study">
<class name="BlockImpl" table="T_BLOCK" proxy="Block">
<id name="id" type="integer" column="ID" >
<generator class="sequence">
<param name="sequence">G_BLOCK_ID</param>
</generator>
</id>
<property name="shortName" column="NAME_SHORT" length="20" not-null="true" type="string" />
<property name="nameLid" column="NAME_LID" type="integer" not-null="true" length="10" />
<property name="descriptionLid" column="DESCRIPTION_LID" type="integer" not-null="true" length="10" />
<property name="revisionId" column="REVISION_ID" type="integer" not-null="false" length="10" />
<property name="structureType" column="STRUCTURE_TYPE" type="integer" not-null="false" length="5" />
<property name="timeLimit" column="TIME_LIMIT" type="timestamp" not-null="false" length="8" />
<property name="timeLimitOpt" column="TIME_LIMIT_OPT" type="integer" not-null="false" length="5" />
<property name="kindId" column="KIND_ID" type="integer" not-null="false" length="5" />
<property name="typeId" column="TYPE_ID" type="int" not-null="true" insert="false" update="false"/>
<joined-subclass name="Block14Impl" table="T_B14" proxy="Block14">
<key column="BLOCK_ID"/>
<set name="block14Items" cascade="all" inverse="true" lazy="true" order-by="LIST_ORDER">
<key column="BLOCK_ID"/>
<one-to-many class="Block14ItemImpl"/>
</set>
</joined-subclass>
<joined-subclass name="Block15Impl" table="T_B15" proxy="Block15">
<key column="BLOCK_ID"/>
<set name="block15Items" cascade="all" inverse="true" lazy="true">
<key column="BLOCK_ID"/>
<one-to-many class="Block15ItemImpl"/>
</set>
</joined-subclass>
<joined-subclass name="Block11Impl" table="T_B11" proxy="Block11">
<key column="BLOCK_ID"/>
<property name="resourceLid" column="RESOURCE_LID" not-null="true" type="integer"/>
</joined-subclass>
<joined-subclass name="ExerciseImpl" table="T_EXERCISE" proxy="Exercise">
<key column="BLOCK_ID"/>
<bag name="problems" table="T_EXERCISE_X_PROBLEM" cascade="all" inverse="true" lazy="true">
<key column="EXERCISE_ID" />
<many-to-many column="PROBLEM_ID" class="ProblemImpl"/>
</bag>
<property name="taskLid" column="TASK_LID" type="integer"/>
<property name="example" column="EXAMPLE" type="string">
</property>
<joined-subclass name="Exercise18Impl" table="T_E18" proxy="Exercise18">
<key column="EXERCISE_ID"/>
<property name="direction" column="DIRECTION_ON" type="integer" />
</joined-subclass>
<joined-subclass name="Exercise20Impl" table="T_E20" proxy="Exercise20">
<key column="EXERCISE_ID"/>
<property name="justOne" column="JUST_ONE" type="integer" />
</joined-subclass>
<joined-subclass name="Exercise21Impl" table="T_E21" proxy="Exercise21">
<key column="EXERCISE_ID"/>
</joined-subclass>
</joined-subclass>
</class>
</hibernate-mapping>
The Java classes are generated by HibernateSynchronizer in this way:
interface Block extends Serializable
class BaseBlockImpl implements Block
class BlockImpl extends BaseBlockImpl
interface Block14 extends Block
class BaseBlock14 extends BlockImpl implements Block14
class Block14Impl extends BaseBlock14Impl
interface Exercise extends Block
class BaseExerciseImpl extends BlockImpl implements Exercise
class ExerciseImpl extends BaseExerciseImpl
interface Exercise18 extends Exercise
class BaseExercise18Impl extends ExerciseImpl implements Exercise18
class Exercise18Impl extends BaseExerciseImpl
...the others are the same.
The block is then selected as follows, but also in many other ways (query returning list, etc)
Code:
block = (Block) session.load(Exercise18Impl.class, blockId);
and then I call some method on the block, for example
Code:
block.getId()
I should mention that session is closed. The exception is:
Code:
java.lang.ClassCastException
at cz.presto.didacticus.study.Exercise21$$FastClassByCGLIB$$bafef9b3.invoke(<generated>)
at net.sf.cglib.proxy.MethodProxy.invoke(MethodProxy.java:149)
at net.sf.hibernate.proxy.CGLIBLazyInitializer.intercept(CGLIBLazyInitializer.java:108)
at cz.presto.didacticus.study.Exercise21$$EnhancerByCGLIB$$cae49957.getId(<generated>)
at cz.presto.didacticus.study.logic.StudyBean.getUnitContentItem(StudyBean.java:109)
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:324)
at org.springframework.aop.framework.AopProxyUtils.invokeJoinpointUsingReflection(AopProxyUtils.java:59)
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:149)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:118)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:191)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:138)
at org.springframework.aop.interceptor.PerformanceMonitorInterceptor.invoke(PerformanceMonitorInterceptor.java:46)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:138)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:148)
at $Proxy1.getUnitContentItem(Unknown Source)
at cz.presto.didacticus.study.web.BlockDispatcher.handleRequestInternal(BlockDispatcher.java:65)
at org.springframework.web.servlet.mvc.AbstractController.handleRequest(AbstractController.java:121)
at org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter.handle(SimpleControllerHandlerAdapter.java:45)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:485)
at org.springframework.web.servlet.FrameworkServlet.serviceWrapper(FrameworkServlet.java:342)
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:318)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:743)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:284)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:204)
at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:73)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:73)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:233)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:204)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:257)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:151)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:567)
at org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:245)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:199)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:151)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:567)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:184)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:151)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:164)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:149)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:567)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:156)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:151)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:567)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:972)
at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:206)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:833)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:732)
at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:619)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:688)
at java.lang.Thread.run(Thread.java:534)
This exception was thrown after the selected Block was of type Block14 (dicovered in debugger - toString() prints Block14Impl, but in the exception you can see Exercise21).
As I read over my reply, I feel like I should be a newbie. I tried to solve it myself in many ways following docs and this forum, but it failed.
Thaks
Pavel