<!--
Question for Hibernate 2.1.2
-->
I would like to get the column name(s) (via method getColumnIterator() or getPrimaryKey())) from the child table (i.e. map) to create my dynamic criterion, however, I could get back the table name only, am I missing sth?
Code:
Criterion criterion = Expression.sql("exists (select 1 from *child_table* where {alias}.id = *child_table*.*child_key_column* and *child_table*.*child_element_column* like upper(?))", s, Hibernate.STRING);
_criteria.add(criterion);
Thanks in advance!
<!--
CompanyVO.hbm.xml
-->
Code:
<class name="CompanyVO"
table="company"
optimistic-lock="version">
<id name="objId" type="string">
<column name="objId" length="16"/>
<generator class="uuid.hex"/>
</id>
<version name="revNo" column="revNo" type="long"/>
<property name="clientId" column="clientObjId" type="string"/>
<property name="code" column="code" type="string"/>
<property name="note" column="note" type="string"/>
<component name="owner" class="Owner">
<property name="id" column="ownerobjid" type="string"/>
</component>
<component name="auditInfo" class="AuditInformation">
<property name="creation" column="CreateDate" type="timestamp"/>
<property name="lastEdited" column="LastEditDate" type="timestamp"/>
<property name="createdByObjId" column="CreateBy_PersonObjId" type="string"/>
<property name="editedByObjId" column="LastEditBy_PersonObjId" type="string"/>
</component>
<many-to-one name="status" column="statusObjId" class="Status"/>
<map name="otherProperties" table="company_oproperty" lazy="false">
<key column="companyobjid"/>
<index column="key" type ="string"/>
<element column="value" type="string"/>
</map>
<map name="descriptions" table="company_descr" lazy="false">
<key column="companyobjid"/>
<index column="localeinfoobjid" type ="string"/>
<element column="description" type="string"/>
</map>
</class>
<!--
Code
-->
Code:
Iterator collectionMappings = configuration.getCollectionMappings();
while (collectionMappings.hasNext()) {
Object o = collectionMappings.next();
if (o instanceof Collection) {
Collection collection = (Collection) o;
log.info("Table name: "+collection.getCollectionTable().getName());
Iterator columnIterator = collection.getCollectionTable().getColumnIterator();
while (columnIterator.hasNext()) {
Object o1 = columnIterator.next();
log.info("Column name: "+o1);
}
log.info("Primary key: "+collection.getCollectionTable().getPrimaryKey());
}
}
<!--
Console output
-->
Code:
2004 Mar 30 10:06:38 INFO [ApplicationServerThread](PersistenceMetainfoManager loadPersistenceMetainfo 39) - Table name: company_descr
2004 Mar 30 10:06:53 INFO [ApplicationServerThread](PersistenceMetainfoManager loadPersistenceMetainfo 45) - Primary key: null