I'm trying to get a oneToMany relationship to work but the list on my object is never populated. The database values look good in my test so it looks like im missing a connecting piece in the mapping file. I've successfully used oneToOne relations but oneToMany is giving me trouble. For clarity, CNight has 1 to Many to Player, and Player has 1 to 1 with CNight.
SittingPlayers needs to be a CPersistentCollection object. I'll assume that it is and that you have instatiated the object.
Assuming it is, could you have a look at the SQL that is generated for the select statement. You should see it in the output window in studio when you run the app.
The SQL should be something like
select ... from (night as t1 left join player as t2 on t1.oid = t2.night_oid) where t1.oid = 'xxxx'
You can cut and paste this SQL into the database query tool and see that you get expected results. You should also see a debug output line in VStudio under the SQL indicating how many records were returned for the query.
You should also see in the debug output, each of the CPlayer objects being loaded into the cache as they are processed.
If the debug output looks OK, could you post the debug output, and the class definitions (or email them to me). You will need to create a bug or support item if you want to post them as an attachment.
Let me know what you find.
- Richard.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Im not seeing any debug SQL printing out for the join, but i am seeing this:
retrievePrivateObject: CNight
Cache - Attempt to Find() <CNight> object in cache
Cache - Found object in cache
retrievePrivateObject: retreived from cache
I'll poke around in the cache until I hear back from you.
Thanks for the help Richard.
eric.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
!Doh, I wasn't using the useCache bool flag. Now I see the SQL ;) There's no WHERE clause:
SELECT t1.oid AS t1_oid,
t1.CreatedDate AS t1_CreatedDate,
t1.ModifiedDate AS t1_ModifiedDate,
t1.notes AS t1_notes,
t1.date_played AS t1_date_played
FROM poker.night as t1 WHERE
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
That looks quite wierd. The only way you can screw up the where clause is when you haven't declared a primary key for a class. But the XML looks OK to me.
Also, there is no Join being generated. It looks like you are just getting retrieving a night object at the moment, and none of the associations.
It might be best if you create a support item and attach all the code so I can have a look and see whats going wrong.
- Richard.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Just in follow up to the response on the support issue. You will probably find that the associations you have here will work well once you mark the OID values as Find="true" or change your code to use a Retrieve() instead of a Find() to get objects.
- Richard
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I'm trying to get a oneToMany relationship to work but the list on my object is never populated. The database values look good in my test so it looks like im missing a connecting piece in the mapping file. I've successfully used oneToOne relations but oneToMany is giving me trouble. For clarity, CNight has 1 to Many to Player, and Player has 1 to 1 with CNight.
Here's the relation from the mapping file.
<class name="CNight" table="night" database="poker">
<attribute name="OIDValue" column="oid" key="primary"/>
<attribute name="SittingPlayers"/>
</class>
<class name="CPlayer" table="player" database="poker">
<attribute name="OIDValue" column="oid" key="primary"/>
<attribute name="CreatedDate" column="CreatedDate" timestamp="true"/>
<attribute name="ModifiedDate" column="ModifiedDate" timestamp="true"/>
<attribute name="Night"/>
<attribute name="NightOID" column="night_oid"/>
<attribute name="Person" />
<attribute name="PersonOID" column="person_oid"/>
</class>
<association fromClass="CNight"
toClass="CPlayer"
cardinality="oneToMany"
target="SittingPlayers"
retrieveAutomatic="true"
saveAutomatic="false"
deleteAutomatic="false"
inverse="false">
<entry fromAttribute="OIDValue" toAttribute="NightOID"/>
</association>
<association fromClass="CPlayer"
toClass="CNight"
cardinality="oneToOne"
target="Night"
retrieveAutomatic="true"
saveAutomatic="false"
deleteAutomatic="false"
inverse="false">
<entry fromAttribute="NightOID" toAttribute="OIDValue"/>
</association>
Hi Eric,
SittingPlayers needs to be a CPersistentCollection object. I'll assume that it is and that you have instatiated the object.
Assuming it is, could you have a look at the SQL that is generated for the select statement. You should see it in the output window in studio when you run the app.
The SQL should be something like
select ... from (night as t1 left join player as t2 on t1.oid = t2.night_oid) where t1.oid = 'xxxx'
You can cut and paste this SQL into the database query tool and see that you get expected results. You should also see a debug output line in VStudio under the SQL indicating how many records were returned for the query.
You should also see in the debug output, each of the CPlayer objects being loaded into the cache as they are processed.
If the debug output looks OK, could you post the debug output, and the class definitions (or email them to me). You will need to create a bug or support item if you want to post them as an attachment.
Let me know what you find.
- Richard.
Im not seeing any debug SQL printing out for the join, but i am seeing this:
retrievePrivateObject: CNight
Cache - Attempt to Find() <CNight> object in cache
Cache - Found object in cache
retrievePrivateObject: retreived from cache
I'll poke around in the cache until I hear back from you.
Thanks for the help Richard.
eric.
!Doh, I wasn't using the useCache bool flag. Now I see the SQL ;) There's no WHERE clause:
SELECT t1.oid AS t1_oid,
t1.CreatedDate AS t1_CreatedDate,
t1.ModifiedDate AS t1_ModifiedDate,
t1.notes AS t1_notes,
t1.date_played AS t1_date_played
FROM poker.night as t1 WHERE
That looks quite wierd. The only way you can screw up the where clause is when you haven't declared a primary key for a class. But the XML looks OK to me.
Also, there is no Join being generated. It looks like you are just getting retrieving a night object at the moment, and none of the associations.
It might be best if you create a support item and attach all the code so I can have a look and see whats going wrong.
- Richard.
added support issue
http://sourceforge.net/tracker/index.php?func=detail&aid=981700&group_id=61771&atid=498348
Just in follow up to the response on the support issue. You will probably find that the associations you have here will work well once you mark the OID values as Find="true" or change your code to use a Retrieve() instead of a Find() to get objects.
- Richard