From: Matthew B. <mat...@ou...> - 2006-05-22 20:22:51
|
Alistair Young wrote: > Before I dive off into bodguts, has anyone seen this before, or any > suggestions as to why it happens? > > UserDetail bodUserDetail = UserDetail.findUserDetail(user.getPrimaryKey()) > > where user = org.bodington.server.realm.User Yep this is because UserDetail has it's own primary key and the primary key of the refering User. Your asking for the UserDetail object with the primary key of the User which doesn't exist. > always gives a ClassCastException. Is a User.PrimaryKey different from a > UserDetail.PrimaryKey? You get this because the database layer is trying to case a User object found by its primary key into a UserDetail object. > Always have to use sql to get UserDetail from a User. Yep. UserDetail.findUserDetail("user_id = ?"); Or make a findUserDetailByUser which does the SQL behind the scenes. You may also want to make user_id an indexkey if performance becomes a problem. -- -- Matthew Buckett, VLE Developer -- Learning Technologies Group, Oxford University Computing Services -- Tel: +44 (0)1865 283660 http://www.oucs.ox.ac.uk/ltg/ |