Hi,
I have an abstract class Account and three Subclasses of Account: RealAccount, AliasAccount and MailList.
Mapping works fine.
How can I select the count of RealAccount objects and AliasAccount objects with one query?
In plain SQL I would do something like
Code:
select count(*) from account where account_type in ('RA','AA') and domain_id=18
Hibernate version: 2.1
Mapping documents:Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping
>
<class
name="de.splendid.cca.modules.email.model.beans.Account"
table="account"
>
<id
name="accountId"
column="account_id"
type="int"
>
<generator class="identity">
<!--
To add non XDoclet generator parameters, create a file named
hibernate-generator-params-Account.xml
containing the additional parameters and place it in your merge dir.
-->
</generator>
</id>
<discriminator
column="account_type"
/>
<property
name="creationDate"
type="java.util.Date"
column="creation_date"
not-null="true"
/>
<property
name="description"
type="java.lang.String"
column="description"
not-null="true"
/>
<many-to-one
name="domain"
class="de.splendid.cca.modules.email.model.beans.Domain"
cascade="save-update"
outer-join="auto"
column="domain_id"
not-null="true"
/>
<property
name="localpart"
type="java.lang.String"
column="localpart"
not-null="true"
/>
<!--
To add non XDoclet property mappings, create a file named
hibernate-properties-Account.xml
containing the additional properties and place it in your merge dir.
-->
<subclass
name="de.splendid.cca.modules.email.model.beans.AliasAccount"
discriminator-value="AA"
>
<many-to-one
name="realAccount"
class="de.splendid.cca.modules.email.model.beans.RealAccount"
cascade="none"
outer-join="auto"
column="real_account_id"
/>
<!--
To add non XDoclet property mappings, create a file named
hibernate-properties-AliasAccount.xml
containing the additional properties and place it in your merge dir.
-->
</subclass>
<subclass
name="de.splendid.cca.modules.email.model.beans.RealAccount"
discriminator-value="RA"
>
<property
name="owner"
type="java.lang.String"
column="owner"
/>
<property
name="size"
type="int"
column="size"
/>
<property
name="used"
type="int"
column="used"
/>
<property
name="usedUpdated"
type="long"
column="used_updated"
/>
<!--
To add non XDoclet property mappings, create a file named
hibernate-properties-RealAccount.xml
containing the additional properties and place it in your merge dir.
-->
</subclass>
<subclass
name="de.splendid.cca.modules.email.model.beans.MailList"
discriminator-value="ML"
>
<set
name="accountSet"
table="maillist_account"
lazy="false"
cascade="none"
sort="unsorted"
>
<key
column="maillist_id"
>
</key>
<many-to-many
class="de.splendid.cca.modules.email.model.beans.Account"
column="account_id"
outer-join="auto"
/>
</set>
<set
name="externalAccountSet"
table="maillist_externalaccount"
lazy="true"
cascade="none"
sort="unsorted"
>
<key
column="maillist_id"
>
</key>
<many-to-many
class="de.splendid.cca.modules.email.model.beans.ExternalAccount"
column="external_account_id"
outer-join="auto"
/>
</set>
<property
name="name"
type="java.lang.String"
column="maillistname"
/>
<!--
To add non XDoclet property mappings, create a file named
hibernate-properties-MailList.xml
containing the additional properties and place it in your merge dir.
-->
</subclass>
</class>
</hibernate-mapping>
Name and version of the database you are using:MySQL 4.0.23
[/code]