Hi I have to persitant classes...
1- Artist
2- Principal
The classes are linked by many-to-one using the "principal" column...
Now I would like to get a list of top X artists only if their principal account is active.
So far I have this which retrieves top X artists.
List artistList = hSession.createCriteria(Artist.class) .addOrder(Order.asc("artistID")).setMaxResults(maxResults) .list();
Now from what i read in the docs, I need to use an Example with an instance of my Pricnipal class. Problem is I dont have an instance of a principal, because I want to get all artist which have the Principal accounst active...
Here is the mapping doc. Am using hibernate 2.1.7 Thanks
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping
PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>
<class name="org.mamoth.Principal" table="Principals">
<id name="principalID" column="PrincipalID" type="int" unsaved-value="0">
<generator class="identity" />
</id>
<timestamp name="dateRegistered" column="DateRegistered"/>
<property name="principal" type="java.lang.String">
<column name="Principal" sql-type="varchar" length="50" not-null="true"/>
</property>
<property name="password" type="java.lang.String">
<column name="Password" sql-type="varchar" length="50" not-null="true"/>
</property>
<property name="uuid" type="java.lang.String">
<column name="UUID" sql-type="varchar" length="50" not-null="true"/>
</property>
<property name="active" type="boolean">
<column name="Active" sql-type="bit"/>
</property>
</class>
<class name="org.mamoth.Role" table="Roles">
<id name="roleID" column="RoleID" type="int" unsaved-value="0">
<generator class="identity" />
</id>
<property name="role" type="java.lang.String">
<column name="Role" sql-type="varchar" length="50" not-null="true"/>
</property>
<property name="roleGroup" type="java.lang.String">
<column name="RoleGroup" sql-type="varchar" length="50" not-null="false"/>
</property>
<many-to-one name="principal" class="org.mamoth.Principal" property-ref="principal"/>
</class>
<class name="org.mamoth.Country" table="Countries">
<id name="countryID" column="CountryID" type="int">
<generator class="identity" />
</id>
<property name="country" type="java.lang.String">
<column name="Country" sql-type="varchar" length = "50" not-null="true"/>
</property>
<property name="code" type="java.lang.String">
<column name="Code" sql-type="char" length="2" not-null="true"/>
</property>
</class>
<class name="org.mamoth.Genre" table="Genres">
<id name="genreID" column="GenreID" type="int" unsaved-value="0">
<generator class="assigned" />
</id>
<property name="genre" type="java.lang.String">
<column name="Genre" sql-type="varchar" length = "25" not-null="true"/>
</property>
<property name="description" type="java.lang.String">
<column name="Description" sql-type="varchar" length="100" not-null="false"/>
</property>
</class>
<class name="org.mamoth.ArtistPlan" table="ArtistPlans">
<id name="planID" column="PlanID" type="int">
<generator class="identity" />
</id>
<property name="totalBytesAllowed" type="int">
<column name="TotalBytesAllowed" sql-type="integer"/>
</property>
</class>
<class name="org.mamoth.Artist" table="Artists">
<id name="artistID" column="ArtistID" type="int" unsaved-value="0">
<generator class="identity" />
</id>
<timestamp name="dateCreated" column="DateCreated"/>
<property name="principalName" type="java.lang.String" insert="false" update="false">
<column name="Principal" sql-type="varchar" length = "50" not-null="true"/>
</property>
<property name="name" type="java.lang.String">
<column name="Name" sql-type="varchar" length="50" not-null="true"/>
</property>
<property name="address1" type="java.lang.String">
<column name="Address1" sql-type="varchar" length="50" not-null="true"/>
</property>
<property name="address2" type="java.lang.String">
<column name="Address2" sql-type="varchar" length="50" not-null="false"/>
</property>
<property name="city" type="java.lang.String">
<column name="City" sql-type="varchar" length="50" not-null="true"/>
</property>
<property name="state" type="java.lang.String">
<column name="State" sql-type="varchar" length="50" not-null="true"/>
</property>
<property name="countryID" type="int" insert="false" update="false">
<column name="CountryID" sql-type="integer" not-null="true"/>
</property>
<property name="postalCode" type="java.lang.String">
<column name="PostalCode" sql-type="varchar" length="50" not-null="true"/>
</property>
<property name="genreID" type="int" insert="false" update="false">
<column name="GenreID" sql-type="integer" not-null="true"/>
</property>
<property name="bookingEmail" type="java.lang.String">
<column name="BookingEmail" sql-type="varchar" length="50" not-null="false"/>
</property>
<property name="webSiteURL" type="java.lang.String">
<column name="WebSiteURL" sql-type="varchar" length="100" not-null="false"/>
</property>
<property name="bio" type="java.lang.String">
<column name="Bio" sql-type="varchar" length="1000" not-null="false"/>
</property>
<property name="picture" type="java.lang.String">
<column name="Picture" sql-type="varchar" length="50" not-null="false"/>
</property>
<property name="pictureThumb" type="java.lang.String">
<column name="PictureThumb" sql-type="varchar" length="50" not-null="false"/>
</property>
<property name="planID" type="int" insert="false" update="false">
<column name="PlanID" sql-type="integer" not-null="true"/>
</property>
<many-to-one name="principal" property-ref="principal" class="org.mamoth.Principal"/>
<many-to-one name="country" column="CountryID" class="org.mamoth.Country"/>
<many-to-one name="genre" column="GenreID" class="org.mamoth.Genre"/>
<many-to-one name="plan" column="PlanID" class="org.mamoth.ArtistPlan"/>
</class>
<class name="org.mamoth.Music" table="Music">
<id name="musicID" column="MusicID" type="int" unsaved-value="0">
<generator class="identity" />
</id>
<property name="artistID" type="int" insert="false" update="false">
<column name="ArtistID" sql-type="integer" not-null="true"/>
</property>
<property name="title" type="java.lang.String">
<column name="Title" sql-type="varchar" length="50" not-null="true"/>
</property>
<property name="year" type="java.lang.String">
<column name="Year" sql-type="varchar" length="4" not-null="true"/>
</property>
<property name="length" type="java.lang.String">
<column name="Length" sql-type="varchar" length="10" not-null="true"/>
</property>
<property name="bitrate" type="java.lang.String">
<column name="Bitrate" sql-type="varchar" length="10" not-null="true"/>
</property>
<property name="file" type="java.lang.String">
<column name="File" sql-type="varchar" length="50" not-null="true"/>
</property>
<property name="fileSize" type="int">
<column name="FileSize" sql-type="integer" not-null="true"/>
</property>
<many-to-one name="artist" column="ArtistID" class="org.mamoth.Artist"/>
<many-to-one name="genre" column="GenreID" class="org.mamoth.Genre"/>
</class>
</hibernate-mapping>