From: Alistair Y. <ali...@sm...> - 2006-05-19 07:45:22
|
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 always gives a ClassCastException. Is a User.PrimaryKey different from a UserDetail.PrimaryKey? Always have to use sql to get UserDetail from a User. Alistair |
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/ |
From: Alistair Y. <ali...@sm...> - 2006-05-23 11:52:43
|
That's really weird. So the only way you can get a UserDetail from a PrimaryKey is if you have the PrimaryKey of the UserDetail which you got from the UserDetail? and PrimaryKey can mean anything! It's a VARIANT in COM speak. Roll on Tetra! Alistair On 22 May 2006, at 21:22, Matthew Buckett wrote: > 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/ > > > ------------------------------------------------------- > Using Tomcat but need to do more? Need to support web services, > security? > Get stuff done quickly with pre-integrated technology to make your > job easier > Download IBM WebSphere Application Server v.1.0.1 based on Apache > Geronimo > http://sel.as-us.falkag.net/sel? > cmd=lnk&kid=120709&bid=263057&dat=121642 > _______________________________________________ > Bodington-developers mailing list > Bod...@li... > https://lists.sourceforge.net/lists/listinfo/bodington-developers |
From: Matthew B. <mat...@ou...> - 2006-05-23 12:19:14
|
Alistair Young wrote: > That's really weird. So the only way you can get a UserDetail from a > PrimaryKey is if you have the PrimaryKey of the UserDetail which you got > from the UserDetail? It's because the "standard" way to subclass PersistentObject is to have a findObject(PrimaryKey) which loads the object by its primary key. Classes that have been used allow have the nicer methods but allot of the other classes don't. > and PrimaryKey can mean anything! Should we subclass PrimaryKey for each type so we get argument checking by the compiler? Probably not worth the effort. > It's a VARIANT in > COM speak. Roll on Tetra! I'd just like to replace the PersistentObject/SqlDatabase/SoftCache classes with something else like Hibernate, but that ain't going to happen by tomorrow. If all the database stuff was done from the session layer this would be easier but we have masses of code in Facility (and subclasses) that goes direct :-( -- -- Matthew Buckett, VLE Developer -- Learning Technologies Group, Oxford University Computing Services -- Tel: +44 (0)1865 283660 http://www.oucs.ox.ac.uk/ltg/ |
From: Brian P. C. <bm...@bm...> - 2006-05-23 13:33:28
|
> That's really weird. So the only way you can get a UserDetail from a > PrimaryKey is if you have the PrimaryKey of the UserDetail which you > got from the UserDetail? and PrimaryKey can mean anything! It's a > VARIANT in COM speak. Roll on Tetra! <*>This is an automated response, please do not reply.<*> This program searches for the term "Tetra" and issues the reply: Go Tetra....<DAOSystemException: no statement begin/> bus .<DAOSystemException: no statement middle/> JBI. <*>End of automatic response.<*> <*>End of automatic response.<*> <*>End of automatic res com.sun.appserv.server.ServerLifecycleException: java.rmi.server.ExportException: Listen failed on port: 0; nested exception is: java.net.SocketException: Cannot assign requested address at com.sun.enterprise.admin.server.core.channel.Admin Channel.createRMIChannel(AdminChannel.java:79) at com.sun.enterprise.admin.server.core.AdminChannelL ifecycle.onInitialization(AdminChannelLifecycle.ja va:43) at com.sun.enterprise.server.ss.ASLazyKernel.initiali zeAdminService(ASLazyKernel.java:131) at com.sun.enterprise.server.ss.ASLazyKernel.startASS ocketServices(ASLazyKernel.java:51) at com.sun.enterprise.server.PEMain.run(PEMain.java:2 74) at com.sun.enterprise.server.PEMain.main(PEMain.java: 220) Caused by: java.rmi.server.ExportException: Listen failed on port: 0; nested exception is: java.net.SocketException: Cannot assign requested address at sun.rmi.transport.tcp.TCPTransport.listen(TCPTrans port.java:245) ... 731 more > > Alistair > > > On 22 May 2006, at 21:22, Matthew Buckett wrote: > > > 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/ > > > > > > ------------------------------------------------------- > > Using Tomcat but need to do more? Need to support web services, > > security? > > Get stuff done quickly with pre-integrated technology to make your > > job easier > > Download IBM WebSphere Application Server v.1.0.1 based on Apache > > Geronimo > > http://sel.as-us.falkag.net/sel? > > cmd=lnk&kid=120709&bid=263057&dat=121642 > > _______________________________________________ > > Bodington-developers mailing list > > Bod...@li... > > https://lists.sourceforge.net/lists/listinfo/bodington-developers > > > > ------------------------------------------------------- > Using Tomcat but need to do more? Need to support web services, security? > Get stuff done quickly with pre-integrated technology to make your job easier > Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo > http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642 > _______________________________________________ > Bodington-developers mailing list > Bod...@li... > https://lists.sourceforge.net/lists/listinfo/bodington-developers > |
From: Jon M. <jo...@te...> - 2006-05-23 14:54:53
|
You're getting confused about primary and secondary keys. A primary key is the field in the table that uniquely identifies each record in that table. A secondary key is a field that refers to a record in a different table, i.e. to that other table's primary key. The Java type PrimaryKey is used to embody the key for any table in Bodington. Since the data type for secondary keys must be identical to the data type for primary keys the same Java class is used for both. (In other words, a secondary key is a copy of a primary key from another table and so it's data type is also 'PrimaryKey' although it is being used as a secondary key.) [By the way, I haven't made all this up - it's pretty standard database terminology] The standard finder method for any PersistentObject looks for an object based on the primary key database field. Since you provided the primary key for a User object, then a User object is what you got. A User object is not a UserDetail object so obviously you got a casting error. If you want to find a UserDetail object by its primary key then you need to pass the primary key of the UserDetail object - i.e. a PrimaryKey instance that refers to the value in the field user_detail_id. However, what you wanted to do was a *secondary* key lookup on the table user_details using a primary key from the table users. There are two options - use the finder method that takes an SQL WHERE clause or add a new finder method findUserDetailByUserId( PrimaryKey user_id ); The latter protects you from accidentally producing silly WHERE clauses which throw exceptions at run time and would contain a single line of code which I provide below. public static UserDetail findUserDetailByUserId( PrimaryKey user_id ) throws BuildingServerException { return (UserDetail)findPersistentObject( "user_id IS " + user_id, "org.bodington.server.realm.UserDetail" ); } In most databases a single integer value for a primary key could be used in all the tables. I.e. the full unique identifier for a record must use a combination of the table name and the primary key. So you can't expect the database to work out which field to match the key you provided against. The SQL database can't know that the key you provided should be matched against a secondary key if it failed to find a match against the primary key. It's the old adage: computers don't do what you want them to do, only what you tell them to do. Jon P.S. I was let out of court early today, hence this Email. Alistair Young wrote: > That's really weird. So the only way you can get a UserDetail from a > PrimaryKey is if you have the PrimaryKey of the UserDetail which you > got from the UserDetail? and PrimaryKey can mean anything! It's a > VARIANT in COM speak. Roll on Tetra! > > Alistair > > > On 22 May 2006, at 21:22, Matthew Buckett wrote: > >> 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/ >> >> >> ------------------------------------------------------- >> Using Tomcat but need to do more? Need to support web services, >> security? >> Get stuff done quickly with pre-integrated technology to make your >> job easier >> Download IBM WebSphere Application Server v.1.0.1 based on Apache >> Geronimo >> http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642 >> _______________________________________________ >> Bodington-developers mailing list >> Bod...@li... >> https://lists.sourceforge.net/lists/listinfo/bodington-developers > > > > ------------------------------------------------------- > Using Tomcat but need to do more? Need to support web services, security? > Get stuff done quickly with pre-integrated technology to make your job > easier > Download IBM WebSphere Application Server v.1.0.1 based on Apache > Geronimo > http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642 > _______________________________________________ > Bodington-developers mailing list > Bod...@li... > https://lists.sourceforge.net/lists/listinfo/bodington-developers > |
From: Andrew B. <a.g...@le...> - 2006-05-23 17:49:34
|
See you a week on Thursday then. Large Masters Teaching Room. 10.130, Garstang Building. Aggie >Jon > >P.S. I was let out of court early today, hence this Email. |
From: Jon M. <jo...@ci...> - 2006-05-23 20:00:38
|
Andrew Booth wrote: > See you a week on Thursday then. > Large Masters Teaching Room. 10.130, Garstang Building. > I sincerely hope so but this trial is estimated to end on Wednesday next week and I could be on another case starting Thursday. If I don't get on another case I still have to be there for roll call at 10:30am every day until the end of next week but may be sent home by 11:00am. If I'm really unlucky I'll get onto a new case at the end of next week and it could run into the following week. On the other hand someone might threaten to nobble the jury and we will all get to stay in a nice hotel for a couple of weeks.... Obviously I can't tell you anything about the case but I think that 12 people might need a good long holiday after this. Jon |