Iam trying to implement a many-to-many mapped application , my domain Objects are as shown below :
public class Folder implements Persistable
{
private Long id;
private String folderName;
private Set<Filterable> myQueries;
private Set<Filterable> mySets;
private Set<Filterable> myScenarios;
public Folder(String name,List<Filterable> queries, List<Filterable>sets, List<Filterable>scenarios)
{
setFolderName(name);
setMyQueries(new HashSet<Filterable>(queries));
setMySets(new HashSet<Filterable>(sets));
setMyScenarios(new HashSet<Filterable>(scenarios));
}
public Folder()
{
}
public void addQuery(Filterable query)
{
this.getMyQueries().add(query);
}
public void addSet(Filterable set)
{
this.getMySets().add(set);
}
public void addScenario(Filterable scenario)
{
this.getMyScenarios().add(scenario);
}
public Long getId()
{
return id;
}
public void setId(Long id)
{
this.id = id;
}
public String getFolderName()
{
return folderName;
}
public void setFolderName(String folderName)
{
this.folderName = folderName;
}
public Set<Filterable> getMyQueries()
{
return myQueries;
}
public void setMyQueries(Set<Filterable> myQueries)
{
this.myQueries = myQueries;
}
public Set<Filterable> getMySets()
{
return mySets;
}
public void setMySets(Set<Filterable> mySets)
{
this.mySets = mySets;
}
public Set<Filterable> getMyScenarios()
{
return myScenarios;
}
public void setMyScenarios(Set<Filterable> myScenarios)
{
this.myScenarios = myScenarios;
}
}
As can be seen from the above class , One the association is :
1 folder can have many Queries/Sets/scenarions (all these are domain Objects themselves).
A single query/set/Scenario can exist in many Folders
My tables in play are :
Folder (Corresponds to the folder domain Object)
SearchQuery(Corresponds to the qury Domain Object)
Set(Corresponds to the set domain Object)
Scenario(Corresponds to the Scenario domain Object)
folder-Query (Link table btw the folder and the Query)
folder-set(Link table between the folder and the set)
folder-scenario(Link table between the folder and the scenario)
My hbm mapping is as shown below:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>
<class name="com.equifax.ic.tdp.framework.catalog.dao.Folder" table="FOLDER">
<id name="id" column="id" type="long">
<generator class="native">
<param name="sequence">folder_seq</param>
</generator>
</id>
<property name="folderName" type="string" column="NAME" not-null="true" />
<set name="myQueries" table="FOLDER_QUERY" lazy="true" cascade="all">
<key column="FOLDER_ID"/>
<many-to-many class="com.equifax.ic.tdp.framework.catalog.dao.SearchQuery" column="QUERY_ID"/>
</set>
<set name="mySets" table="FOLDER_SET" lazy="true" cascade="all">
<key column="FOLDER_ID"/>
<many-to-many class="com.equifax.ic.tdp.framework.catalog.dao.ContentSet" column="SET_ID"/>
</set>
<set name="myScenarios" table="FOLDER_SCENARIO" lazy="true" cascade="all">
<key column="FOLDER_ID"/>
<many-to-many class="com.equifax.ic.tdp.framework.catalog.dao.BasicScenario" column="SCENARIO_ID"/>
</set>
</class>
<query name="find.folders.with.queries">
<![CDATA[
from Folder fldr join fetch fldr.myQueries
]]>
</query>
<query name="find.folders.with.sets">
<![CDATA[
from Folder fldr join fetch fldr.mySets
]]>
</query>
<query name="find.folders.with.scenarios">
<![CDATA[
from Folder fldr join fetch fldr.myScenarios
]]>
</query>
</hibernate-mapping>
Question:
Iam succesfully able to save the above many-to-many mapping, but when retrieving the folder Object, I am compelled to use three different queries as in the above hbm file , to retrive it with Queries/sets and Scenarios.
Iam not able to disjucnt this join , I want to retrieve the folder object with just One HQL which has all the queries/sets and scenarions.
In short if I have more than one many-to-many in the same class , how do I wrote the HQL query to get that Object and all the associated Objects.(Iam able to get one associate Object at a time) .
|