Re: dynamci Proxy: ClassCastException with Interfaces
Could you try rc4 CVS HEAD? Just a guess... - Original Message - From: Joerg Lensing To: OJB Users List Sent: Saturday, September 13, 2003 4:51 AM Subject: Re: dynamci Proxy: ClassCastException with Interfaces Edson Carlos Ericksson Richter wrote: Ok, I've not asked yet: what version of OJB are you using? I'm using rc 3 joerg - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] --- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.518 / Virus Database: 316 - Release Date: 11/9/2003
Re: dynamci Proxy: ClassCastException with Interfaces
Edson Carlos Ericksson Richter wrote: Ok, I've not asked yet: what version of OJB are you using? I'm using rc 3 joerg - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: dynamci Proxy: ClassCastException with Interfaces
Hi Carlos, as you can see below, I nearly did the same you wrote, except that all my classes/interfaces extend java.io.Serializable. joerg Edson Carlos Ericksson Richter wrote: Hi! I'm using dynamic proxy and seen no problems at all (at least for rc3/rc4). Let me show how I'm using. I'll use sample you sent as base: public interface AbstractPersistentIF { public interface AbstractPersistentIF { ... } public interface PartnerIF extends AbstractPersistentIF { public interface PartnerIF extends java.io.Serializable , AbstractPersistentIF { ... } public interface OrganisationIF extends PartnerIF { public interface OrganisationIF extends java.io.Serializable , PartnerIF { ... } public interface PersonIF extends PartnerIF { public interface PersonIF extends java.io.Serializable , PartnerIF { ... } public abstract class AbstractPersistentPO implements AbstractPersistentIF { public abstract class AbstractPersistentPO implements java.io.Serializable, AbstractPersistentIF { ... } public class PartnerPO extends AbstractPersistentPO implements PartnerIF { public abstract class PartnerPO extends AbstractPersistentPO implements PartnerIF, java.io.Serializable { // this make PartnerPO can be cast to PartnerIF and AbstractPersistentIF. } public class OrganizationPO extends PartnerPO implements OrganizationIF { public class OrganisationPO extends PartnerPO implements OrganisationIF, java.io.Serializable { // this makes OrganizationPO can be cast to OrganizationIF, PartnerIF and AbstractPersistentIF } public class PersonPO extends PartnerPO implements PersonIF { public class PersonPO extends PartnerPO implements PersonIF, java.io.Serializable { // this makes PersonPO can be cast to PersonIF, PartnerIF and AbstractPersistentIF. } All this said, you must guarantee that you have proxy=dynamic in you .xml defination file. I use this with PB API (but AFAIK, is the same for OQL, that appear you are using), and works fine. My2c, Edson Richter - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: dynamci Proxy: ClassCastException with Interfaces
I've the two situation in my project. I have a documents table table has a fixed structure to all types of documents, and I have different tables for different objects, in another (a payment structure). All that works. I think you must specify that your interfaces extends others. The java.io.Serializable ins't necessary to work with OJB (but you may need it to work with another tech). But see. If you make AbstractPersistentIF extends java.io.Seralizable, all your interfaces (since they will extends AbstractPersistentIF) will be subclasses of java.io.Seralizable. AFAIK, your interfaces must extend the super-interfaces. Oh, in the .xml you must specify the class name, not interface name... I expect to help... Edson Richter - Original Message - From: Joerg Lensing To: OJB Users List Sent: Friday, September 12, 2003 5:22 AM Subject: Re: dynamci Proxy: ClassCastException with Interfaces hi carlos, did I say, that PersonPO and OrganisationPO are mapped to the same table? The do! joerg - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] --- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.516 / Virus Database: 313 - Release Date: 1/9/2003 - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: dynamci Proxy: ClassCastException with Interfaces
Hi Edson thanks for your reply. I'm still stuck :-( Edson Carlos Ericksson Richter wrote: I've the two situation in my project. I have a documents table table has a fixed structure to all types of documents, and I have different tables for different objects, in another (a payment structure). All that works. I think you must specify that your interfaces extends others. The java.io.Serializable ins't necessary to work with OJB (but you may need it to work with another tech). But see. If you make AbstractPersistentIF extends java.io.Seralizable, all your interfaces (since they will extends AbstractPersistentIF) will be subclasses of java.io.Seralizable. I changed it. No difference! The problem is, that the proxy-instance get the wrong interfaces for the class in question. see eclipse watch-expression after this code: [code]: Criteria crit = new Criteria(); crit.addEqualTo(id, new Integer(pOID)); Query query = new QueryByCriteria(PartnerPO.class, crit); PartnerIF partner = (PartnerIF)broker.getObjectByQuery(query); if (broker.hasClassDescriptor(partner.getClass())) { tx.lock(partner, org.odmg.Transaction.READ); } [watch-expression]: Class[] Class[] test = partner.getClass().getInterfaces();= Class[4] (id=175) Class [0]= Class (de.softcon.webcontrol.business.model.PersonIF) (id=106) Class [1]= Class (de.softcon.webcontrol.business.model.AbstractPersistentIF) (id=94) Class [2]= Class (java.io.Serializable) (id=95) Class [3]= Class (de.softcon.webcontrol.business.model.PartnerIF) (id=107) ---snip-- As you can see, the proxy doesn't show the expected interface OrganisationIF. (The field id has a table-field value of an OrganisationPO (I know this is OK, because before used proxies, this has been OK) joerg - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: dynamci Proxy: ClassCastException with Interfaces
Why do you think that the partner object should support OrganizationIF? It's perfectly reasonable that it does not, for some configurations of data/classes. Furthermore, if you load it using dynamic proxies, you've said I want to treat this as a PartnerIF the fact that the real object behind the scenes might implement a other interfaces is not relevant. David |-+--- | | Joerg Lensing | | | [EMAIL PROTECTED]| | | nsing.de | | | | | | 09/11/2003 09:02| | | AM | | | Please respond | | | to OJB Users | | | List | | | | |-+--- --| | | |To: OJB Users List [EMAIL PROTECTED] | |cc: | |Subject: dynamci Proxy: ClassCastException with Interfaces | | | --| hi all, I'm using dynamic proxies for these classes look at this Interface/class-hierarchy: AbstractPersistentIF |_PartnerIF |_OrganisationIF |_PersonIF (PO: persistent/mapped objects) AbstractPersistentPO |_PartnerPO |_OrganisationPO |_PersonPO if i query an organisation: snip public PartnerIF getPartnerByOID(int pOID,Transaction tx) { // obtain a broker instance from the current transaction HasBroker hasBroker = (HasBroker) tx; PersistenceBroker broker = hasBroker.getBroker(); Criteria crit = new Criteria(); crit.addEqualTo(id, new Integer(pOID)); Query query = new QueryByCriteria(PartnerPO.class, crit); PartnerIF partner = (PartnerIF)broker.getObjectByQuery(query); if (broker.hasClassDescriptor(partner.getClass())) { tx.lock(partner, org.odmg.Transaction.READ); } return partner; } snip if i test the implemented interfaces for the queried class (--partner.getClass().getIntefaces();), it doesn't show the right implemented interface. The class shoud show OrganisationIF, but shows PersonIF as being implemented by this class who can help? tx joerg - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: dynamci Proxy: ClassCastException with Interfaces
Hi David, [EMAIL PROTECTED] wrote: Why do you think that the partner object should support OrganizationIF? It's perfectly reasonable that it does not, for some configurations of data/classes. yes. but the object in question does support the OrganizationIF . Take a look at the code: -snip--- // class definition public class OrganisationPO extends PartnerPO implements OrganisationIF, java.io.Serializable { snip the queried object is a of type OrgansiationPO. (Because before switching to dynamic proxy, this class was of this type) joerg Furthermore, if you load it using dynamic proxies, you've said I want to treat this as a PartnerIF the fact that the real object behind the scenes might implement a other interfaces is not relevant. David |-+--- | | Joerg Lensing | | | [EMAIL PROTECTED]| | | nsing.de | | | | | | 09/11/2003 09:02| | | AM | | | Please respond | | | to OJB Users | | | List | | | | |-+--- --| | | |To: OJB Users List [EMAIL PROTECTED] | |cc: | |Subject: dynamci Proxy: ClassCastException with Interfaces | | | --| hi all, I'm using dynamic proxies for these classes look at this Interface/class-hierarchy: AbstractPersistentIF |_PartnerIF |_OrganisationIF |_PersonIF (PO: persistent/mapped objects) AbstractPersistentPO |_PartnerPO |_OrganisationPO |_PersonPO if i query an organisation: snip public PartnerIF getPartnerByOID(int pOID,Transaction tx) { // obtain a broker instance from the current transaction HasBroker hasBroker = (HasBroker) tx; PersistenceBroker broker = hasBroker.getBroker(); Criteria crit = new Criteria(); crit.addEqualTo(id, new Integer(pOID)); Query query = new QueryByCriteria(PartnerPO.class, crit); PartnerIF partner = (PartnerIF)broker.getObjectByQuery(query); if (broker.hasClassDescriptor(partner.getClass())) { tx.lock(partner, org.odmg.Transaction.READ); } return partner; } snip if i test the implemented interfaces for the queried class (--partner.getClass().getIntefaces();), it doesn't show the right implemented interface. The class shoud show OrganisationIF, but shows PersonIF as being implemented by this class who can help? tx joerg - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]