Stephen, Andrew, If I remember correctly, CGLIB proxies can be configured to use dynamic proxies. Iirc, the class name returned by such a class (a dynamic proxy) will include a ...$6 or similar, so that's not going to be an option (I might be wrong, though). Having said that, a dynamic proxy will still (have to) implement an interface (if interfaces are used at all), so maybe that information can be used in some way or the other.
Thanks Werner wg> -----Original Message----- wg> From: Stephen Bash [mailto:[EMAIL PROTECTED] wg> Sent: Tuesday, February 14, 2006 2:10 PM wg> To: [email protected] wg> Subject: Re: [castor-user] Re: [SPAM] - [SPAM] - Re: wg> [castor-user] Castor marshalling Hibernate Pojos - Email wg> found in subject - Email found in subject - Email found in wg> subject - Email found in subject wg> wg> Andrew, Werner, et al- wg> wg> Not knowing a lot about these CGLib proxies, my first wg> question is what do they return when calling wg> obj.getClass()? I'm guessing since they're proxies, you wg> can't do a classA == classB comparison, but you might be wg> able to get away with a string comparison on the name or wg> something... I agree with Werner that there should be a wg> fix, we just need to find it :) wg> wg> Stephen wg> wg> wg> On 2/14/06, Erik Eide <[EMAIL PROTECTED]> wrote: wg> > For what its worth, I'm using Castor to map XML requests onto wg> > Hibernate entities. wg> > wg> > Based on similar issues (but also wanting to map one XML wg> element onto wg> > several object properties), I ended up writing a set of wg> mapping files, wg> > along with having setIgnoreExtraElements to true when I wg> generate XML wg> > response from the Hibernate entities. wg> > wg> > If you're using Hibernate 3, they've started implementing wg> their own wg> > XML marshalling/unmarshalling stuff, which I think is wg> based on dom4j. wg> > I'm not sure how far they've got with it, when I looked at it was wg> > still early on - with more features slated for the 3.1 release. wg> > wg> > Erik wg> > wg> > On 2/14/06, Andrew Mason <[EMAIL PROTECTED]> wrote: wg> > > Thanks for all your suggestions guys, I think I've wg> figured out what wg> > > is going on here, and it does seem to be linked to the wg> fact that wg> > > Hibernate is using CGLIB enhancements for Classes that wg> are lazily wg> > > loaded. wg> > > During the Validate phase of the Marshalling, the method wg> > > MappingLoader.getDescriptor(Class type) is called, this wg> uses the wg> > > Hashtable _clsDescs to find the ClassDescriptor which wg> are keyed by wg> > > the pojo's classes. wg> > > However, when the marshaller gets the class of a lazily wg> loaded field wg> > > (with it's CGLIB enhancements), it doesn't match the wg> classes within wg> > > MappingLoader._clsDescs, so the Marshaller treats the wg> classes as not wg> > > mapped, and introspects them. wg> > > wg> > > I don't know if this is the only place this is a wg> problem, or whether wg> > > I'm going to encounter similar issues deeper within the wg> code - can wg> > > anyone tell me? wg> > > I figure it must be possible to fix this problem, and as the wg> > > alternative is to drop Castor XML from the project I'll wg> have a go. wg> > > Unless there is some other way of geting around it? wg> > > Any ideas? wg> > > wg> > > Thanks wg> > > wg> > > Andrew wg> > > wg> > > wg> > > Werner Guttmann wrote: wg> > > wg> > > >Stephen, wg> > > > wg> > > >we'd be more than happy to provide you with some help wg> when it comes wg> > > >down to your personal learning experience. What do you need ? wg> > > > wg> > > >To, for example, model a 1:M relation from A to B, in wg> A you'll need wg> > > >a property named 'bs' of type e.g. List, and in the wg> mapping file a wg> > > >field mapping similar to wg> > > > wg> > > ><field name="bs" type="some.domain.B" collection="arraylist"> wg> > > > <sql many-key=" ..." /> wg> > > ></field> wg> > > > wg> > > >And in terms of the SQL statements to create A and B, wg> one could use wg> > > >the following statements as a starting point: wg> > > > wg> > > >create table domain_a ( wg> > > > id int not null PRIMARY KEY, wg> > > > name varchar(20) wg> > > >); wg> > > > wg> > > >create table domain_B 8 wg> > > > id int not null PRIMARY KEY, wg> > > > descr varchar(20), wg> > > > a_id int wg> > > >); wg> > > > wg> > > >I hope this keeps you going ... ;-). wg> > > > wg> > > >Werner wg> > > > wg> > > >Stephen Bash wrote: wg> > > > wg> > > > wg> > > >>Well gentlemen, since I've wanted to learn more about the JDO wg> > > >>world for a while now, I took this as a chance to wg> read up more on wg> > > >>Castor JDO. And honestly, most of it makes sense wg> though I have wg> > > >>very little experience with O/R mapping. wg> Unfortunately, when it wg> > > >>comes to actually creating the database schema or correctly wg> > > >>modeling the 1:m relations, I'm out of my league, so wg> I'm probably wg> > > >>going to have to leave this one for someone else. wg> > > >> wg> > > >>Thanks, wg> > > >>Stephen wg> > > >> wg> > > >>On 2/13/06, Ralf Joachim <[EMAIL PROTECTED]> wrote: wg> > > >> wg> > > >> wg> > > >>>Hi Andrew, Hi Stephen, wg> > > >>> wg> > > >>>according to my knowledge hibernate returns wg> cglib-proxies instead wg> > > >>>of the original ones as they havily us lazy loading wg> of data from wg> > > >>>database. In the past a few users had problems with the wg> > > >>>constelation castor xml together with hibernate wg> according to this cglib-proxies. wg> > > >>> wg> > > >>>Just in case you are not aware of it Ralf wg> > > >>> wg> > > >>> wg> > > >>>Stephen Bash schrieb: wg> > > >>> wg> > > >>> wg> > > >>>>Andrew- wg> > > >>>> wg> > > >>>>So I tried to recreate your problem with a simpler wg> set of classes: wg> > > >>>> wg> > > >>>> public class ParentFoo { wg> > > >>>> protected int parentId; wg> > > >>>> protected Set children; wg> > > >>>> wg> > > >>>> public int getParentId() { return parentId; } wg> > > >>>> public void setParentId( int parentId ) { wg> this.parentId = wg> > > >>>> parentId; } wg> > > >>>> wg> > > >>>> public Set getChildren() { return children; } wg> > > >>>> public void setChildren( Set children ) { wg> this.children = children; } wg> > > >>>> } wg> > > >>>> wg> > > >>>> public class ChildFoo { wg> > > >>>> protected int childId; wg> > > >>>> protected Set parents; wg> > > >>>> wg> > > >>>> public int getChildId() { return childId; } wg> > > >>>> public void setChildId( int childId ) { wg> this.childId = wg> > > >>>> childId; } wg> > > >>>> wg> > > >>>> public Set getParents() { return parents; } wg> > > >>>> public void setParents( Set parents ) { wg> this.parents = wg> > > >>>> parents; } wg> > > >>>> wg> > > >>>> public String toString() { return( wg> String.valueOf( childId ) ); } wg> > > >>>> } wg> > > >>>> wg> > > >>>>And the following mapping file: wg> > > >>>> wg> > > >>>> <mapping> wg> > > >>>> <class name="ParentFoo"> wg> > > >>>> <map-to xml="parent-foo" /> wg> > > >>>> wg> > > >>>> <field name="parentId" type="integer"> wg> > > >>>> <bind-xml name="id" node="attribute" /> wg> > > >>>> </field> wg> > > >>>> wg> > > >>>> <field name="children" collection="set" wg> type="ChildFoo"> wg> > > >>>> <bind-xml name="child" /> wg> > > >>>> </field> wg> > > >>>> </class> wg> > > >>>> wg> > > >>>> <class name="ChildFoo"> wg> > > >>>> <map-to xml="child-foo" /> wg> > > >>>> wg> > > >>>> <field name="childId" type="integer"> wg> > > >>>> <bind-xml name="id" node="attribute" /> wg> > > >>>> </field> wg> > > >>>> wg> > > >>>><!-- wg> > > >>>> <field name="parents" collection="set" wg> > > >>>>type="castor.mason.one.ParentFoo"> wg> > > >>>> <bind-xml name="parent" /> wg> > > >>>> </field> wg> > > >>>> --> wg> > > >>>> </class> wg> > > >>>> </mapping> wg> > > >>>> wg> > > >>>>I've attempted to recreate the 1:m m:1 relationship wg> you had. wg> > > >>>>You can see in my mapping file I have the wg> connection between the wg> > > >>>>children and the parents commented out. I then wg> created a series wg> > > >>>>of parents and children, mixing and matching them. wg> Using this wg> > > >>>>mapping file as is to marshal my first parent object I get: wg> > > >>>> wg> > > >>>> <parent-foo id="1"> wg> > > >>>> <child id="5"/> wg> > > >>>> <child id="4"/> wg> > > >>>> </parent-foo> wg> > > >>>> wg> > > >>>>If I uncomment the child->parent relationship, I get: wg> > > >>>> wg> > > >>>> <parent-foo id="1"> wg> > > >>>> <child id="5"> wg> > > >>>> <parent id="2"> wg> > > >>>> <child id="6"> wg> > > >>>> <parent id="3"/> wg> > > >>>> </child> wg> > > >>>> <child id="4"/> wg> > > >>>> </parent> wg> > > >>>> </child> wg> > > >>>> <child id="4"> wg> > > >>>> <parent id="2"> wg> > > >>>> <child id="6"> wg> > > >>>> <parent id="3"/> wg> > > >>>> </child> wg> > > >>>> <child id="5"/> wg> > > >>>> </parent> wg> > > >>>> </child> wg> > > >>>> </parent-foo> wg> > > >>>> wg> > > >>>>I'm somewhat surprised to find that I'm not getting wg> the deep wg> > > >>>>recursion you mention. I tested this with Castor 0.9.9 and wg> > > >>>>1.0M2. What version of Castor are you running? If wg> you can run wg> > > >>>>this example on your system and agree or disagree wg> with the output, that would also be helpful. wg> > > >>>> wg> > > >>>>Do you see anything grossly different between your wg> setup and wg> > > >>>>mine? I don't have the intermediate classes, so that might wg> > > >>>>change things, but I wanted to start simple. wg> > > >>>> wg> > > >>>>Let me know your thoughts on this example and its wg> comparison to wg> > > >>>>your code. I can't directly answer your question wg> because from wg> > > >>>>what I can tell, you're doing what I'm doing... wg> > > >>>> wg> > > >>>>Stephen wg> > > >>>> wg> > > >>>> wg> > > >>>>On 2/13/06, Andrew Mason <[EMAIL PROTECTED]> wrote: wg> > > >>>> wg> > > >>>> wg> > > >>>> wg> > > >>>>>OK, wg> > > >>>>> wg> > > >>>>>Here is the castor mapping file: wg> > > >>>>> wg> > > >>>>><?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE wg> mapping PUBLIC wg> > > >>>>>"-//EXOLAB/Castor Object Mapping DTD Version 1.0//EN" wg> > > >>>>> wg> > > >>>>>"http://castor.org/mapping.dtd"> <mapping> <class wg> > > >>>>>name="uk.gov.forestry.harpps.model.Species" wg> > > >>>>>auto-complete="false"> <map-to xml="species"/> <field wg> > > >>>>>name="scientificName"> <bind-xml name="scientific-name" wg> > > >>>>>node="attribute"/> </field> <field name="protections" wg> > > >>>>>collection="set" wg> > > >>>>>type="uk.gov.forestry.harpps.model.Protection"> wg> > > >>>>></field> wg> > > >>>>></class> wg> > > >>>>> wg> > > >>>>><class name="uk.gov.forestry.harpps.model.Protection" wg> > > >>>>>auto-complete="false"> wg> > > >>>>><map-to xml="protection"/> wg> > > >>>>><field name="lookupProtection" wg> > > >>>>>type="uk.gov.forestry.harpps.model.LookupProtection"> wg> > > >>>>><bind-xml name="lookup-protection" wg> node="element"/> </field> wg> > > >>>>></class> wg> > > >>>>> wg> > > >>>>><class name="uk.gov.forestry.harpps.model.LookupProtection" wg> > > >>>>>auto-complete="false"> wg> > > >>>>><map-to xml="protection-lookup"/> <field wg> name="protectionName"> wg> > > >>>>><bind-xml name="protection-name" wg> node="attribute"/> </field> wg> > > >>>>><field name="lookupProtectionType" wg> > > >>>>>type="uk.gov.forestry.harpps.model.LookupProtectionType"> wg> > > >>>>><bind-xml name="protection-type" node="element"/> </field> wg> > > >>>>></class> wg> > > >>>>> wg> > > >>>>><class wg> name="uk.gov.forestry.harpps.model.LookupProtectionType" wg> > > >>>>>auto-complete="false"> wg> > > >>>>><map-to xml="protection-type"/> <field wg> name="protectionTypeId"> wg> > > >>>>><bind-xml name="protection-type-id" wg> node="attribute"/> </field> wg> > > >>>>></class> </mapping> wg> > > >>>>> wg> > > >>>>>A Species has a Hashset of Protection objects. It wg> also has many wg> > > >>>>>other Objects associated with it in a similar way, wg> but I'm not wg> > > >>>>>interested in generating the XML for those (yet). wg> > > >>>>> wg> > > >>>>>A Protection has a LookupProtection object, and a wg> protectionName String. wg> > > >>>>> wg> > > >>>>>A LookupProtection object has a wg> LookupProtectionType object. wg> > > >>>>> wg> > > >>>>>A LookupProtectionType has a protectionTypeId (long) wg> > > >>>>> wg> > > >>>>>Below is the java code of the LookupProtectionType wg> class, you wg> > > >>>>>will see it has a relationship back to the wg> LookupProtection wg> > > >>>>>object, but I don't want to show this within the wg> XML. Most of wg> > > >>>>>the Objects also have similar wg> > > >>>>>2 way relationships. wg> > > >>>>> wg> > > >>>>>public class LookupProtectionType implements wg> > > >>>>>java.io.Serializable { wg> > > >>>>> wg> > > >>>>> wg> > > >>>>> // Fields wg> > > >>>>> wg> > > >>>>> private long protectionTypeId; wg> > > >>>>> private String protectionType; wg> > > >>>>> private Set lookupProtections = new HashSet(0); wg> > > >>>>> wg> > > >>>>> wg> > > >>>>> // Constructors wg> > > >>>>> wg> > > >>>>> /** default constructor */ wg> > > >>>>> public LookupProtectionType() { wg> > > >>>>> } wg> > > >>>>> wg> > > >>>>> /** minimal constructor */ wg> > > >>>>> public LookupProtectionType(long protectionTypeId) { wg> > > >>>>> this.protectionTypeId = protectionTypeId; wg> > > >>>>> } wg> > > >>>>> wg> > > >>>>> /** full constructor */ wg> > > >>>>> public LookupProtectionType(long wg> protectionTypeId, String wg> > > >>>>>protectionType, Set lookupProtections) { wg> > > >>>>> this.protectionTypeId = protectionTypeId; wg> > > >>>>> this.protectionType = protectionType; wg> > > >>>>> this.lookupProtections = lookupProtections; wg> > > >>>>> } wg> > > >>>>> wg> > > >>>>> wg> > > >>>>> wg> > > >>>>> // Property accessors wg> > > >>>>> wg> > > >>>>> public long getProtectionTypeId() { wg> > > >>>>> return this.protectionTypeId; wg> > > >>>>> } wg> > > >>>>> wg> > > >>>>> public void setProtectionTypeId(long protectionTypeId) { wg> > > >>>>> this.protectionTypeId = protectionTypeId; wg> > > >>>>> } wg> > > >>>>> wg> > > >>>>> public String getProtectionType() { wg> > > >>>>> return this.protectionType; wg> > > >>>>> } wg> > > >>>>> wg> > > >>>>> public void setProtectionType(String protectionType) { wg> > > >>>>> this.protectionType = protectionType; wg> > > >>>>> } wg> > > >>>>> wg> > > >>>>> public Set getLookupProtections() { wg> > > >>>>> return this.lookupProtections; wg> > > >>>>> } wg> > > >>>>> wg> > > >>>>> public void setLookupProtections(Set wg> lookupProtections) { wg> > > >>>>> this.lookupProtections = lookupProtections; wg> > > >>>>> } wg> > > >>>>> wg> > > >>>>> wg> > > >>>>>} wg> > > >>>>> wg> > > >>>>> wg> > > >>>>>Within the Hibernate mapping I made all the wg> relationships Lazy, wg> > > >>>>>so they should only load when their get method is called. wg> > > >>>>> wg> > > >>>>>When I test the marshalling, I can see all the Non-mapped wg> > > >>>>>objects being queried from the database. wg> > > >>>>>I have tried mapping all the fields and setting them as wg> > > >>>>>Trasient, but that seemed to have no effect. wg> > > >>>>> wg> > > >>>>> wg> > > >>>>> wg> > > >>>>> wg> > > >>>>>Werner Guttmann wrote: wg> > > >>>>> wg> > > >>>>> wg> > > >>>>> wg> > > >>>>> wg> > > >>>>>>Andrew, wg> > > >>>>>> wg> > > >>>>>>Can you please show us the relevant mapping file wg> section you wg> > > >>>>>>are using to 'disable' some of the relations ? wg> > > >>>>>> wg> > > >>>>>>Thanks wg> > > >>>>>>Werner wg> > > >>>>>> wg> > > >>>>>> wg> > > >>>>>> wg> > > >>>>>> wg> > > >>>>>> wg> > > >>>>>> wg> > > >>>>>>>-----Original Message----- wg> > > >>>>>>>From: Andrew Mason [mailto:[EMAIL PROTECTED] wg> > > >>>>>>>Sent: Montag, 13. Februar 2006 11:56 wg> > > >>>>>>>To: [email protected] wg> > > >>>>>>>Subject: [castor-user] Castor marshalling Hibernate Pojos wg> > > >>>>>>> wg> > > >>>>>>>Hello, wg> > > >>>>>>>I apologise if this topic has been covered wg> before - if so a wg> > > >>>>>>>pointer to the relevent posts will be appreciated. wg> > > >>>>>>> wg> > > >>>>>>>I am using Hibernate as my object persistence wg> layer (sorry wg> > > >>>>>>>but I can't use Castor JDO due to political reasons). wg> > > >>>>>>> wg> > > >>>>>>>I wish to use Castor XML to marshall the pojos wg> into xml documents. wg> > > >>>>>>>Many of the objects have relationships with wg> objects that are wg> > > >>>>>>>required from a database perspective, but are wg> not required wg> > > >>>>>>>within the XML. wg> > > >>>>>>>For example wg> > > >>>>>>> wg> > > >>>>>>>Species has a one-to-many relationship with Predator. wg> > > >>>>>>>Predator has a one-to-many relationship with Species. wg> > > >>>>>>> wg> > > >>>>>>>When I marshal a Species object I want to include it's wg> > > >>>>>>>predators, however, I do not want to include all wg> the Species wg> > > >>>>>>>the predator preys upon within the Species XML document. wg> > > >>>>>>> wg> > > >>>>>>>I assumed that by writing a mapping document for wg> Predator, wg> > > >>>>>>>that did not include rerlationship with Species, wg> Castor would wg> > > >>>>>>>not bother calling the getPreySpecies method. wg> > > >>>>>>>What I am finding is that despite the mapping wg> not including wg> > > >>>>>>>this relationship, the method is still being wg> called, causing wg> > > >>>>>>>more species to be instantiated, thus causing wg> more predators wg> > > >>>>>>>to be instantiated and so on until my machine wg> runs out of memory! wg> > > >>>>>>> wg> > > >>>>>>>Is there any way of ensuring that the Marshaller wg> pays strict wg> > > >>>>>>>attention to the Map, and doesn't call methods wg> that are not defined? wg> > > >>>>>>> wg> > > >>>>>>> wg> > > >>>>>>>Thanks wg> > > >>>>>>> wg> > > >>>>>>>-- wg> > > >>>>>>>************************************************* wg> > > >>>>>>>Andrew Mason wg> > > >>>>>>>Environ-IT Ltd. wg> > > >>>>>>>Tel.: 01899 880200 wg> > > >>>>>>>Mob.: 07919 967494 wg> > > >>>>>>>E-mail: [EMAIL PROTECTED] wg> > > >>>>>>>************************************************* wg> > > >>>>>>> wg> > > >>>>>>> wg> > > >>>>>>> wg> > > >>>>>>>------------------------------------------------- wg> > > >>>>>>>If you wish to unsubscribe from this list, wg> please send an wg> > > >>>>>>>empty message to the following address: wg> > > >>>>>>> wg> > > >>>>>>>[EMAIL PROTECTED] wg> > > >>>>>>>------------------------------------------------- wg> > > >>>>>>> wg> > > >>>>>>> wg> > > >>>>>>> wg> > > >>>>>>> wg> > > >>>>>>> wg> > > >>>>>>> wg> > > >>>>>>> wg> > > >>>>>>------------------------------------------------- wg> > > >>>>>>If you wish to unsubscribe from this list, please send an wg> > > >>>>>>empty message to the following address: wg> > > >>>>>> wg> > > >>>>>>[EMAIL PROTECTED] wg> > > >>>>>>------------------------------------------------- wg> > > >>>>>> wg> > > >>>>>> wg> > > >>>>>> wg> > > >>>>>> wg> > > >>>>>> wg> > > >>>>>> wg> > > >>>>>> wg> > > >>>>>-- wg> > > >>>>>************************************************* wg> > > >>>>>Andrew Mason wg> > > >>>>>Environ-IT Ltd. wg> > > >>>>>Tel.: 01899 880200 wg> > > >>>>>Mob.: 07919 967494 wg> > > >>>>>E-mail: [EMAIL PROTECTED] wg> > > >>>>>************************************************* wg> > > >>>>> wg> > > >>>>> wg> > > >>>>> wg> > > >>>>>------------------------------------------------- wg> > > >>>>>If you wish to unsubscribe from this list, please wg> send an empty wg> > > >>>>>message to the following address: wg> > > >>>>> wg> > > >>>>>[EMAIL PROTECTED] wg> > > >>>>>------------------------------------------------- wg> > > >>>>> wg> > > >>>>> wg> > > >>>>> wg> > > >>>>> wg> > > >>>------------------------------------------------- wg> > > >>>If you wish to unsubscribe from this list, please wg> send an empty wg> > > >>>message to the following address: wg> > > >>> wg> > > >>>[EMAIL PROTECTED] wg> > > >>>------------------------------------------------- wg> > > >>> wg> > > >>> wg> > > >>> wg> > > >>> wg> > > > wg> > > > wg> > > >------------------------------------------------- wg> > > >If you wish to unsubscribe from this list, please send wg> an empty wg> > > >message to the following address: wg> > > > wg> > > >[EMAIL PROTECTED] wg> > > >------------------------------------------------- wg> > > > wg> > > > wg> > > > wg> > > > wg> > > > wg> > > wg> > > -- wg> > > ************************************************* wg> > > Andrew Mason wg> > > Environ-IT Ltd. wg> > > Tel.: 01899 880200 wg> > > Mob.: 07919 967494 wg> > > E-mail: [EMAIL PROTECTED] wg> > > ************************************************* wg> > > wg> > > wg> > > wg> > > ------------------------------------------------- wg> > > If you wish to unsubscribe from this list, please send an empty wg> > > message to the following address: wg> > > wg> > > [EMAIL PROTECTED] wg> > > ------------------------------------------------- wg> > > wg> > > wg> > wg> > ------------------------------------------------- wg> > If you wish to unsubscribe from this list, please send an empty wg> > message to the following address: wg> > wg> > [EMAIL PROTECTED] wg> > ------------------------------------------------- wg> > wg> > wg> ------------------------------------------------- If you wish to unsubscribe from this list, please send an empty message to the following address: [EMAIL PROTECTED] -------------------------------------------------

