I've hit a brick wall in attempting to create flattened relationships
in Cayenne. I must be doing something wrong, but from reading the
documentation I can't see what it is. Some step or order dependency
is assumed in the documentation but never stated.
In order to distill the problem into as simple of a situation as
possible, I use the Artist <-> ArtistExhibit <-> Exhibit linkage
used as an example in the documentation. The flattened relationship
I'm trying to achieve is to be able to obtain an array of Exhibits for
a given Artist.
I build an entirely new project in which to work as follows:
mkdir ~/projects/flat
I then run Cayenne modeler in that directory, creating a new data
domain and data node to an existing MySql database.
cd ~/projects/flat
$CAYENNE_HOME/bin/modeler.sh
File -> New Project
Create Data Domain (name: flat-x)
Create Data Node
(name: flat-node,
data source factory: org...DriverDataSourceFactory
DB Adapter: org...MySQLAdapter
User Name: mre
password: secret
Driver Class: org.gjt.mm.mysql.Driver
Database URL: jdbc:mysql://localhost/banana)
Create Data Map (name: flat-map)
Then I get down to the detail work of creating the artist/exhibit
stuff:
In flat-map:
Create DbEntity (DbEntity name: artist)
Create Attribute (name: pk, type: integer, pk <y>, Mandatory <y>)
Create Attribute
(name: name, type: varchar, pk <n>, Mandatory <n>, Max Length 20)
Create DbEntity (DbEntity name: exhibit)
Create Attribute (name: pk, type: integer, pk <y>, Mandatory <y>)
Create Attribute
(name: name, type: varchar, pk <n>, Mandatory <n>, Max Length 40)
Create ObjEntity
(ObjEntity Name: Artist, Table/View: artist, Java Class: Artist)
Create ObjEntity
(ObjEntity Name: Exhibit, Table/View: exhibit, Java Class: Exhibit)
Select Artist. Project -> Sync ObjEntity with DbEntity
Select Exhibit. Project -> Sync ObjEntity with DbEntity
Create DbEntity (DbEntity name: artist_exhibit)
Create Attribute (name: pk, type: integer, pk <y>, Mandatory <y>)
Create Attribute
(name: artist_pk, type: integer, pk <n>, Mandatory <y>)
Create Attribute
(name: exhibit_pk, type: integer, pk <n>, Mandatory <y>)
Create ObjEntity
(ObjEntity Name: ArtistExhibit,
Table/View: artist_exhibit, Java Class: ArtistExhibit)
Select ArtistExhibit. Project -> Sync ObjEntity with DbEntity
I feel confident that all the preceding steps are absolutely required.
However, from this point onward, I really don't know what steps are
required or what the order dependency is. So, I'll give it my best
guess.
I know I need to link the artist and exhibit tables together through
the artist_exhibit link table, so . . .
Select artist_exhibit DbEntity.
Create Relationship (Name: artist_for, Target: artist)
Database Mapping (Relationship: artist_for, Create Reverse: <y>,
Reverse Relationship: artist_for_x)
Add (Source: artist_pk, Target: pk )
Done
Create Relationship (Name: exhibit_for, Target: exhibit)
Database Mapping (Relationship: exhibit_for, Create Reverse: <y>,
Reverse Relationship: exhibit_for_x)
Add (Source: exhibit_pk, Target: pk )
Done
Select ArtistExhibit ObjEntity. Project -> Sync ObjEntity with DbEntity
Select Artist ObjEntity. Project -> Sync ObjEntity with DbEntity
Select Exhibit ObjEntity. Project -> Sync ObjEntity with DbEntity
Visual inspection at this point confirms that all the relationships
have made their way into the ObjEntities. At this point, I *should*
be able to create a flattened relationship from Artist to an array of
Exhibits, and vice versa. Following the documentation . . .
Select Artist ObjEntity
Create Relationship (Name: exhibits, Target: Exhibit)
I would click the "To Many" checkbox, but I cannot. It remains
unchecked.
Edit Relationship
(Relationship: exhibits, Source: Artist, Target: Exhibit)
At this point, I should be able to exploit the known path from Artist
to Exhibit through ArtistExhibit. However, the DbRelationships section
is depressingly empty.
And there it dies. No way to create the flattened relationship. So
. . . I must be leaving out a step, or doing things in the wrong
order, or something, right? I have actually created a flattened
relationship (once) before, but I don't know what extra step I
performed, or how the order differed, or whatever it took to make the
magic work.
Please help. What should I be doing differently?
Mike Elliott
This archive was generated by hypermail 2.0.0 : Sat Apr 24 2004 - 15:51:01 EDT