Hello, I have a problem concerning mapping of multiple collections.
Lets's say I want to have a List of ZOO's objects.
I have a table called "zoo" with two fields:
id - id of ZOO
name - name of ZOO
Simple export from this table could look like this:
id:1 ; name:ZOO1
id:2 ; name:ZOO2
id:3 ; name:ZOO3
Then I have second table - "Animals" with four fields:
id - id of animal
zoo_id - id of zoo (this is a FK)
animal_type - describes type of animal (there can by only four types of animals: dog, cat, fish, bird)
animal_name - name of animal
A simple export from this table could look as below:
id:1 ; zoo_id:1 ; animal_type

og ; animal_name: doggy1
id:2 ; zoo_id:1 ; animal_type

og ; animal_name: doggy2
id:3 ; zoo_id:1 ; animal_type:cat ; animal_name: cat1
id:4 ; zoo_id:2 ; animal_type:cat ; animal_name: cat2
id:5 ; zoo_id:2 ; animal_type:fish ; animal_name: fishy1
id:6 ; zoo_id:2 ; animal_type:bird ; animal_name: bird1
Now, I want to have
Java class called "ZOO" as follows:
class Zoo{
Set dogs; //can be a Hashset
Set cats;
Set fish;
Set birds;
//I ommitt the rest of the listing of this class
}
Finally, I would like to retrieve from DB the list of ZOO's with eager-fetched animals just by calling
List zooList = session.createCriteria(Zoo.class).list();
As a result I should get List with two elements
element1 - object corresponding to ZOO1 (Set dogs should contain 2 elements ; Set cats should contain 1 elements ; Set fish should contain 0 elements ; Set birds should contain 0 elements)
element2 - object corresponding to ZOO2 (Set dogs should contain 0 elements ; Set cats should contain 1 elements ; Set fish should contain 1 elements ; Set birds should contain 1 elements)
Could you please advise me how to map tables/classes etc.?