Does anybody know if it is possible to map a column as a discriminator and a property in the same object, like:
Code:
<class name="licenceBeans.LicenceTypeBean" table="LICENCE_TYPE">
<id name="id" type="long" column="ID" unsaved-value="-1">
<generator class="identity"/>
</id>
<discriminator>
<column name="LICENCE_TYPE"/>
</discriminator>
<!--Properties-->
<property name="licenceType" type="string" column="LICENCE_TYPE"/>
<!--discriminator classes-->
<subclass name="licenceBeans.licenceTypes.GmCaptureLicenceBean" discriminator-value="..."/>
</class>
Using this mapping definition, when I do some query using that field it says that licenceType could not be resolved. The strange thing is that if I query elements of this class using other fields the "licenceType" field is correctly initialized.
this is the exception:
Code:
org.hibernate.QueryException: could not resolve property: licenceType of: licenceBeans.LicenceTypeBean [from licenceBeans.LicenceTypeBean currLicenceType where currLicenceType.product = ? and currLicenceType.licenceType = ?]
at org.hibernate.persister.entity.AbstractPropertyMapping.propertyException(AbstractPropertyMapping.java:44)
at org.hibernate.persister.entity.AbstractPropertyMapping.toType(AbstractPropertyMapping.java:38)
at org.hibernate.persister.entity.AbstractEntityPersister.toType(AbstractEntityPersister.java:1362)
at org.hibernate.hql.ast.tree.FromElementType.getPropertyType(FromElementType.java:279)
at org.hibernate.hql.ast.tree.FromElement.getPropertyType(FromElement.java:386)
at org.hibernate.hql.ast.tree.DotNode.getDataType(DotNode.java:567)
at org.hibernate.hql.ast.tree.DotNode.prepareLhs(DotNode.java:241)
at org.hibernate.hql.ast.tree.DotNode.resolve(DotNode.java:188)
at org.hibernate.hql.ast.tree.FromReferenceNode.resolve(FromReferenceNode.java:94)
at org.hibernate.hql.ast.tree.FromReferenceNode.resolve(FromReferenceNode.java:90)
at org.hibernate.hql.ast.HqlSqlWalker.resolve(HqlSqlWalker.java:728)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.expr(HqlSqlBaseWalker.java:1216)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.exprOrSubquery(HqlSqlBaseWalker.java:4041)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.comparisonExpr(HqlSqlBaseWalker.java:3525)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.logicalExpr(HqlSqlBaseWalker.java:1762)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.logicalExpr(HqlSqlBaseWalker.java:1690)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.whereClause(HqlSqlBaseWalker.java:776)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.query(HqlSqlBaseWalker.java:577)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.selectStatement(HqlSqlBaseWalker.java:281)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.statement(HqlSqlBaseWalker.java:229)
at org.hibernate.hql.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:228)
at org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:160)
at org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:111)
at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:77)
at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:56)
at org.hibernate.engine.query.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:72)
at org.hibernate.impl.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:133)
at org.hibernate.impl.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:112)
at org.hibernate.impl.SessionImpl.createQuery(SessionImpl.java:1623)
at licenceDaos.LicenceDao.activateLicence(LicenceDao.java:281)
at licenceDaos.LicenceDao.main(LicenceDao.java:59)
Exception in thread "main" org.hibernate.TransactionException: Transaction not successfully started
at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:100)
at licenceDaos.LicenceDao.activateLicence(LicenceDao.java:307)
at licenceDaos.LicenceDao.main(LicenceDao.java:59)