我的情况下面是超类: -
abstract class Container
{
Long id;
FieldParent parent;
}
class SubContainer extends Container
{
Long extid;
}
abstract class FieldParent
{
Long fid;
String name;
}
class SubField extends FieldParent
{
String typeOfSub;
}
我使用了一个使用鉴别器的每子类策略 下面是容器的hbm映射: -
<class name="Container" table="Container">
<id name="id" type="long" column="ID">
<generator class="native"/>
</id>
<many-to-one name="parent"
class="FieldParent"
cascade="none"
column="FieldParentID"/>
<discriminator column="TYPE"/>
....
<subclass name="SubContainer"
discriminator-value="S"
lazy="true">
<property name="extid" type="long" column="extid" not-null="true"/>
</subclass>
</class>
下面是FieldParent的hbm映射: -
<class name="FieldParent" table="FieldParent">
<id name="fid" type="long" column="FID">
<generator class="native"/>
</id>
<property name="name" type="java.lang.String" column="name" not-null="true"/>
<discriminator column="TYPE_Parent"/>
....
<subclass name="SubField"
discriminator-value="F"
lazy="true">
<property name="typeOfSub" type="java.lang.String" column="typeOfSub" not-null="true"/>
</subclass>
</class>
现在我有SubContainer的对象,我的查询基于&#39; typeOfSub&#39;值。 我尝试使用以下查询
getHibernateTemplate().find(
"from " + SubContainer.class.getName()
+ " subContainer where subContainer.extid = ? and subContainer.parent.typeOfSub=? ",
new Object[]{new Long(id), "sampeTypeoFSub"});
但面对&#39; org.hibernate.PropertyAccessException:发生IllegalArgumentException&#39;。
我明白我不能只是假设它将是SubField对象所以无法访问字段但我需要找出方法。我不确定我们是否可以投入HQL?
我试着寻找解决方案,但是找到了类似的问题。
下面是stacktrace:
java.sql.SQLSyntaxErrorException:ORA-00904:&#34; FieldParent_3 _&#34;。&#34; typeOfSub&#34;:无效的标识符 在oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:445)[ojdbc6.jar:11.2.0.3.0] 在oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:396)[ojdbc6.jar:11.2.0.3.0] 在oracle.jdbc.driver.T4C8Oall.processError(T4C8Oall.java:879)[ojdbc6.jar:11.2.0.3.0] at oracle.jdbc.driver.T4CTTIfun.receive(T4CTTIfun.java:450)[ojdbc6.jar:11.2.0.3.0] at oracle.jdbc.driver.T4CTTIfun.doRPC(T4CTTIfun.java:192)[ojdbc6.jar:11.2.0.3.0] 在oracle.jdbc.driver.T4C8Oall.doOALL(T4C8Oall.java:531)[ojdbc6.jar:11.2.0.3.0] at oracle.jdbc.driver.T4CPreparedStatement.doOall8(T4CPreparedStatement.java:207)[ojdbc6.jar:11.2.0.3.0] at oracle.jdbc.driver.T4CPreparedStatement.executeForDescribe(T4CPreparedStatement.java:884)[ojdbc6.jar:11.2.0.3.0] 在oracle.jdbc.driver.OracleStatement.executeMaybeDescribe(OracleStatement.java:1167)[ojdbc6.jar:11.2.0.3.0] 在oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1281)[ojdbc6.jar:11.2.0.3.0] at oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java:3584)[ojdbc6.jar:11.2.0.3.0] 在oracle.jdbc.driver.OraclePreparedStatement.executeQuery(OraclePreparedStatement.java:3628)[ojdbc6.jar:11.2.0.3.0] 在oracle.jdbc.driver.OraclePreparedStatementWrapper.executeQuery(OraclePreparedStatementWrapper.java:1493)[ojdbc6.jar:11.2.0.3.0] 在org.jboss.resource.adapter.jdbc.WrappedPreparedStatement.executeQuery(WrappedPreparedStatement.java:342)[:6.0.0.Final]
更新了异常的堆栈跟踪。另外只有FYI,FieldParent有3个子类,其中一个是SubField。
java.sql.SQLSyntaxErrorException:ORA-00904:&#34; FieldParent1_3 _&#34;。&#34; typeOfSub&#34;:无效标识符
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:445) [ojdbc6.jar:11.2.0.3.0]
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:396) [ojdbc6.jar:11.2.0.3.0]
at oracle.jdbc.driver.T4C8Oall.processError(T4C8Oall.java:879) [ojdbc6.jar:11.2.0.3.0]
at oracle.jdbc.driver.T4CTTIfun.receive(T4CTTIfun.java:450) [ojdbc6.jar:11.2.0.3.0]
at oracle.jdbc.driver.T4CTTIfun.doRPC(T4CTTIfun.java:192) [ojdbc6.jar:11.2.0.3.0]
at oracle.jdbc.driver.T4C8Oall.doOALL(T4C8Oall.java:531) [ojdbc6.jar:11.2.0.3.0]
at oracle.jdbc.driver.T4CPreparedStatement.doOall8(T4CPreparedStatement.java:207) [ojdbc6.jar:11.2.0.3.0]
at oracle.jdbc.driver.T4CPreparedStatement.executeForDescribe(T4CPreparedStatement.java:884) [ojdbc6.jar:11.2.0.3.0]
at oracle.jdbc.driver.OracleStatement.executeMaybeDescribe(OracleStatement.java:1167) [ojdbc6.jar:11.2.0.3.0]
at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1281) [ojdbc6.jar:11.2.0.3.0]
at oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java:3584) [ojdbc6.jar:11.2.0.3.0]
at oracle.jdbc.driver.OraclePreparedStatement.executeQuery(OraclePreparedStatement.java:3628) [ojdbc6.jar:11.2.0.3.0]
at oracle.jdbc.driver.OraclePreparedStatementWrapper.executeQuery(OraclePreparedStatementWrapper.java:1493) [ojdbc6.jar:11.2.0.3.0]
at org.jboss.resource.adapter.jdbc.WrappedPreparedStatement.executeQuery(WrappedPreparedStatement.java:342) [:6.0.0.Final]
at org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:208) [:3.6.10.Final]
at org.hibernate.loader.Loader.getResultSet(Loader.java:1953) [:3.6.10.Final]
答案 0 :(得分:1)
<div id="tabs" class="txtabs-wrap style1">
<ul class="txtabs-nav top clearfix">
<li class="first active">
<a data-target="#tabs-0" data-toggle="tab">
<span>Lorem</span>
</a>
</li>
<li class="last">
<a data-target="#tabs-2" data-toggle="tab">
<span>Lorem</span>
</a>
</li>
属性位于typeOfSub
类中,SubField
与Container
有多对一关联。
FieldParent
您可以过滤与子类类型的关联:
FieldParent
答案 1 :(得分:-1)
我尝试了@VladMihalcea答案,但遗憾的是工作。在深入研究这个问题后,我不认为可以在HQL中访问子类元素。 所以这就是我做的解决方法并为我工作。
getHibernateTemplate().find("select subCont from " +SubContainer.class.getName()+" subCont, " + SubField.class.getName() +" subField "
where subCont.extid = ? and subField.typeOfSub=? and subCont.parent.fid=subField.fid",
new Object[]{new Long(id), "sampeTypeoFSub"});
基本上加入表格。有点类似于内连接。