I'm not sure whether this is a hibernate-tools question or just a hibernate question. I haven't experienced this problem when using hibernate without hibernate-tools, though, so I am posting it here.
I am using hibernate tools 3.2.4 along with ant 1.6.5. I am generating classes that inherit from each other by overriding the tableToMetaAttributes method in the DelegatingReverseEngineeringStrategy class, like so.
Code:
public Map tableToMetaAttributes(TableIdentifier tableIdentifier)
{
Map attributes = super.tableToMetaAttributes(tableIdentifier);
// Get the map of inheritances between the tables.
String className = tableIdentifier.getName();
String superclass = getInheritanceMap().get(className);
if (superclass == null)
{
return attributes;
}
// If there are no meta attributes yet, initialize the attributes
// map.
if (attributes == null)
{
attributes = new HashMap<String, MetaAttribute>();
}
// Add the inheritance to the set of attributes.
MetaAttribute attribute = new MetaAttribute("extends");
attribute.addValue(superclass);
attributes.put("extends", attribute);
return attributes;
}
I am generating a class called Country that inherits from Location. Here is the country hbm file.
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">
<!-- Generated Jan 15, 2009 5:38:04 PM by Hibernate Tools 3.2.0.CR1 -->
<hibernate-mapping>
<class catalog="Enum" name="com.structuralwealth.dsl.Country" table="Country">
<meta attribute="extends" inherit="false">Location</meta>
<id name="id" type="java.lang.Long">
<meta attribute="finder" inherit="false">findById</meta>
<column name="id"/>
<generator class="identity"/>
</id>
<many-to-one class="com.structuralwealth.dsl.Currency"
fetch="select" name="currency">
<meta attribute="finder" inherit="false">findByCurrencyId</meta>
<column name="currency_id"/>
</many-to-one>
<many-to-one class="com.structuralwealth.dsl.Location"
fetch="select" name="location">
<meta attribute="finder" inherit="false">findByLocationId</meta>
<column name="location_id"/>
</many-to-one>
<property name="iso2" type="string">
<meta attribute="finder" inherit="false">findByIso2</meta>
<column length="2" name="iso2"/>
</property>
<property name="iso3" type="string">
<meta attribute="finder" inherit="false">findByIso3</meta>
<column length="3" name="iso3"/>
</property>
<property name="name" type="string">
<meta attribute="finder" inherit="false">findByName</meta>
<column name="name"/>
</property>
<property name="isDomestic" type="java.lang.Boolean">
<meta attribute="finder" inherit="false">findByIsDomestic</meta>
<column name="is_domestic"/>
</property>
<property name="isEmergingMarket" type="java.lang.Boolean">
<meta attribute="finder" inherit="false">findByIsEmErgingMarket</meta>
<column name="is_emerging_market"/>
</property>
<property name="isBarraSupported" type="java.lang.Boolean">
<meta attribute="finder" inherit="false">findByIsBarraSupported</meta>
<column name="is_barra_supported"/>
</property>
<property name="isInternationalDeveloped" type="java.lang.Boolean">
<meta attribute="finder" inherit="false">findByIsInternatIonalDevelopeD</meta>
<column name="is_international_developed"/>
</property>
<property name="isTaxHaven" type="java.lang.Boolean">
<meta attribute="finder" inherit="false">findByIsTaxHaven</meta>
<column name="is_tax_haven"/>
</property>
<property name="hasForeignWithholdingTax" type="java.lang.Boolean">
<meta attribute="finder" inherit="false">findByHasForeignWithholdingTax</meta>
<column name="has_foreign_withholding_tax"/>
</property>
<set inverse="true" name="countryPercentRegions">
<key>
<column name="country_id"/>
</key>
<one-to-many class="com.structuralwealth.dsl.CountryPercentRegion"/>
</set>
<set inverse="true" name="exchanges">
<key>
<column name="country_id"/>
</key>
<one-to-many class="com.structuralwealth.dsl.Exchange"/>
</set>
<set inverse="true" name="companyRiskEntitysForCountryOfIncorporationId">
<key>
<column name="country_of_incorporation_id"/>
</key>
<one-to-many class="com.structuralwealth.dsl.CompanyRiskEntity"/>
</set>
<set inverse="true" name="companyRiskEntitysForCountryOfIssueId">
<key>
<column name="country_of_issue_id"/>
</key>
<one-to-many class="com.structuralwealth.dsl.CompanyRiskEntity"/>
</set>
<set inverse="true" name="companyRiskEntitysForIssuerCountryOfDomicileId">
<key>
<column name="issuer_country_of_domicile_id"/>
</key>
<one-to-many class="com.structuralwealth.dsl.CompanyRiskEntity"/>
</set>
<set inverse="true" name="barraFactorCountryMaps">
<key>
<column name="country_id"/>
</key>
<one-to-many class="com.structuralwealth.dsl.BarraFactorCountryMap"/>
</set>
</class>
</hibernate-mapping>
I attempt to run the following query
Code:
Session session = sessionFactory.openSession();
Query query = session.createQuery("FROM Location l WHERE l.rootId = 1");
query.list();
And I receive the following error.
Code:
Exception in thread "main" org.hibernate.QueryException: could not resolve property: rootId of: com.structuralwealth.dsl.Country [FROM com.structuralwealth.dsl.Country l WHERE l.rootId = 1]
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.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 com.structuralwealth.dsl.test.Test.main(Test.java:25)
But that's not the query I executed! what's going on here?
Thanks
[/code]