RE: [flexcoders] many-to-many managed association in Hibernate destination
Hi Jeff, I could not follow the code.txt link in your post I wonder why that wouldn't work for you. Let's try again. I've posted the file again with a different name: http://www.brightworks.com/technology/tech_questions/hibernate_lazy_associations/code_2.txt Can you see this one? I suspect that you are still missing the intermediate destination in the FDMS configuration. I apologize if I wasn’t clear No, I think that you were clear, and believe that I've implemented the intermediate filmActors destination as suggested. Let me know how it looks. I'd also be happy to give you the whole app so that you can run it if you'd like. Thanks, Douglas -- Flexcoders Mailing List FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com Yahoo! Groups Links * To visit your group on the web, go to: http://groups.yahoo.com/group/flexcoders/ * Your email settings: Individual Email | Traditional * To change settings online go to: http://groups.yahoo.com/group/flexcoders/join (Yahoo! ID required) * To change settings via email: mailto:[EMAIL PROTECTED] mailto:[EMAIL PROTECTED] * To unsubscribe from this group, send an email to: [EMAIL PROTECTED] * Your use of Yahoo! Groups is subject to: http://docs.yahoo.com/info/terms/
RE: [flexcoders] many-to-many managed association in Hibernate destination
Hi Douglas, (snip) 3. Jeff said that I should set the association properties for my filmActors destination as one-to-one. I'm guessing that this should be many-to-one, but am not sure. I've tried both it doesn't help my current problem, but I'd love a definitive answer on which this should be. Victor Rubba sent me some code that uses many-to-one for an intermediate object (albeit one with numeric ID, rather than complex object ID like mine). This is working code so it seems to support my guess. I could not follow the code.txt link in your post but I suspect that you are still missing the intermediate destination in the FDMS configuration. I apologize if I wasn't clear, but in this case since you have 3 entity types in hibernate (Film, FilmActor, and Actor) in hibernate, you need three destinations in FDMS one for each entity type. The actor type would have a filmActors association property which is of type: one-to-many or maybe many-to-many (we actually treat those two as the same... we only care about the to-many or to-one part of the association). This one should point to the filmActors destination. The filmActors destination would have a film association property and an actor association property - both of these would be one-to-one or many-to-one. Probably all association properties should be marked lazy=true. If you can provide access to your FDMS configuration somehow, I'll take a look to make sure that looks right. Unfortunately I can't easily send an updated version of the HibernateAssembler since the current version depends on some new code we added that is not yet released. Jeff -- Flexcoders Mailing List FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com Yahoo! Groups Links http://groups.yahoo.com/group/flexcoders/ Individual Email | Traditional http://groups.yahoo.com/group/flexcoders/join (Yahoo! ID required) mailto:[EMAIL PROTECTED] mailto:[EMAIL PROTECTED] [EMAIL PROTECTED] http://docs.yahoo.com/info/terms/
Re: [flexcoders] many-to-many managed association in Hibernate destination
Douglas McCarroll wrote: Thanks. I'll let you know how it goes. Still stuck. :-) Same Page request made for item with id = '{filmId=null}' error. I believe that I've implemented Jeff's suggestions. I've refreshed this code listing so that it reflects my current code: http://www.brightworks.com/technology/tech_questions/hibernate_lazy_associations/code.txt Here's my current logging output: http://www.brightworks.com/technology/tech_questions/hibernate_lazy_associations/debug_log_02.txt Here's a nice variable view showing what HibernateAssembler.fill() returns: http://www.brightworks.com/technology/tech_questions/hibernate_lazy_associations/actor_destination_fill_result_at_app_startup.jpg The comments and questions that follow are addressed to Jeff Vroom in particular, but all are welcome to contribute... 1. Jeff explained a while back in this thread that FDMS and Hibernate currently don't do lazy loading in the same way - http://tech.groups.yahoo.com/group/flexcoders/message/57339 - I assume that this explains why fill() is returning so much data on Films in what is supposed to be a lazy fill() of Actors. 2. In any case, both the fill() results and the logging output - which I believe shows the data being sent over the wire - show the associated films as having a filmId of zero (in Java) or null (passed over the wire). 3. Jeff said that I should set the association properties for my filmActors destination as one-to-one. I'm guessing that this should be many-to-one, but am not sure. I've tried both it doesn't help my current problem, but I'd love a definitive answer on which this should be. Victor Rubba sent me some code that uses many-to-one for an intermediate object (albeit one with numeric ID, rather than complex object ID like mine). This is working code so it seems to support my guess. 4. I'm wondering what general approach I should take to resolving this. Here are my options: a. I can continue to post code and logs and hope that Jeff (or someone else) spots my error or identifies a bug in FDMS. b. I can dig in with the debugger. I'm already looking at HibernateAssembler.java (thanks, Adobe, for making source public!). Now it occurs to me that Hibernate itself is open source. Should I be digging into that and trying to figure out why it's giving me Film instances without ID values? This could be dangerous - I might learn more Java! :-) Seriously, what's the likelihood that I could help to resolve this problem by doing this, given that I have more time to put into this than Jeff does? c. I could re-zip the whole project and repost it if anyone else would like to play with it. d. Other suggestions? e. All of the above? :-) 5. Jeff said, I think the hibernate assembler is missing an error test for snip. I’ll fix that right away as that would have saved you a lot of time. Can I get a copy of the fixed code? Finally, thanks to Jeff and to all for all your input so far. Douglas -- Flexcoders Mailing List FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com Yahoo! Groups Links * To visit your group on the web, go to: http://groups.yahoo.com/group/flexcoders/ * Your email settings: Individual Email | Traditional * To change settings online go to: http://groups.yahoo.com/group/flexcoders/join (Yahoo! ID required) * To change settings via email: mailto:[EMAIL PROTECTED] mailto:[EMAIL PROTECTED] * To unsubscribe from this group, send an email to: [EMAIL PROTECTED] * Your use of Yahoo! Groups is subject to: http://docs.yahoo.com/info/terms/
Re: [flexcoders] many-to-many managed association in Hibernate destination
PS. Be careful. I just checked the links in this post and the code page was retrieved from my cache. The new version does *not* have and error message at the top. Hit refresh if it does. :-) Douglas Douglas McCarroll wrote: Douglas McCarroll wrote: Thanks. I'll let you know how it goes. Still stuck. :-) Same Page request made for item with id = '{filmId=null}' error. I believe that I've implemented Jeff's suggestions. I've refreshed this code listing so that it reflects my current code: http://www.brightworks.com/technology/tech_questions/hibernate_lazy_associations/code.txt Here's my current logging output: http://www.brightworks.com/technology/tech_questions/hibernate_lazy_associations/debug_log_02.txt Here's a nice variable view showing what HibernateAssembler.fill() returns: http://www.brightworks.com/technology/tech_questions/hibernate_lazy_associations/actor_destination_fill_result_at_app_startup.jpg The comments and questions that follow are addressed to Jeff Vroom in particular, but all are welcome to contribute... 1. Jeff explained a while back in this thread that FDMS and Hibernate currently don't do lazy loading in the same way - http://tech.groups.yahoo.com/group/flexcoders/message/57339 - I assume that this explains why fill() is returning so much data on Films in what is supposed to be a lazy fill() of Actors. 2. In any case, both the fill() results and the logging output - which I believe shows the data being sent over the wire - show the associated films as having a filmId of zero (in Java) or null (passed over the wire). 3. Jeff said that I should set the association properties for my filmActors destination as one-to-one. I'm guessing that this should be many-to-one, but am not sure. I've tried both it doesn't help my current problem, but I'd love a definitive answer on which this should be. Victor Rubba sent me some code that uses many-to-one for an intermediate object (albeit one with numeric ID, rather than complex object ID like mine). This is working code so it seems to support my guess. 4. I'm wondering what general approach I should take to resolving this. Here are my options: a. I can continue to post code and logs and hope that Jeff (or someone else) spots my error or identifies a bug in FDMS. b. I can dig in with the debugger. I'm already looking at HibernateAssembler.java (thanks, Adobe, for making source public!). Now it occurs to me that Hibernate itself is open source. Should I be digging into that and trying to figure out why it's giving me Film instances without ID values? This could be dangerous - I might learn more Java! :-) Seriously, what's the likelihood that I could help to resolve this problem by doing this, given that I have more time to put into this than Jeff does? c. I could re-zip the whole project and repost it if anyone else would like to play with it. d. Other suggestions? e. All of the above? :-) 5. Jeff said, I think the hibernate assembler is missing an error test for snip. I’ll fix that right away as that would have saved you a lot of time. Can I get a copy of the fixed code? Finally, thanks to Jeff and to all for all your input so far. Douglas -- Flexcoders Mailing List FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com Yahoo! Groups Links -- Flexcoders Mailing List FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com Yahoo! Groups Links * To visit your group on the web, go to: http://groups.yahoo.com/group/flexcoders/ * Your email settings: Individual Email | Traditional * To change settings online go to: http://groups.yahoo.com/group/flexcoders/join (Yahoo! ID required) * To change settings via email: mailto:[EMAIL PROTECTED] mailto:[EMAIL PROTECTED] * To unsubscribe from this group, send an email to: [EMAIL PROTECTED] * Your use of Yahoo! Groups is subject to: http://docs.yahoo.com/info/terms/
Re: [flexcoders] many-to-many managed association in Hibernate destination
more thing is that because you are using a “complex” object type as an identity property, your FilmActor.as class will need a function like: public function toString():String { return actorId + “:” + filmId } This is a requirement for complex object identity properties in FDMS (due to the fact that there is no Hashtable like class in ActionScript which uses equals/hashCode methods, we use a string key generated from the toString values of all identity properties to keep track of instances on the client). I think the hibernate assembler is missing an error test for the case where the type of the referenced entity does not match the destination’s entity type. I’ll fix that right away as that would have saved you a lot of time. Instead, it is looking for a “filmId” property on the FilmActor type and is getting back null (it should also print an error instead here). One other thing I’ll mention as an aside is that you could potentially implement the Film/Actors relationship without an intermediate FilmActors class – both hibernate and FDMS will support that and since you do not have any additional properties in the mapping table, it is pretty common to avoid an extra type. You are right though that this fix will not greatly improve the performance. We are still going to need to do a query for each actor to retrieve the filmActors properties. It will be a little faster than today because it won’t need to join in the Film table because of the intermediate mapping object. Jeff *From:* flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] *On Behalf Of *Douglas McCarroll *Sent:* Thursday, November 30, 2006 5:39 PM *To:* flexcoders@yahoogroups.com *Subject:* Re: [flexcoders] many-to-many managed association in Hibernate destination Hi Jeff, A couple more thoughts... It's worth noting that I don't get the error when I use the hierarchical values approach without lazy loading, and get my films info from my actor objects. Thanks for this info. The performance problem is most likely due to the fact that FDMS is fetching the list of films for each actor... this is the lazy loading issue we have currently that I mentioned in a previous post. If we were to follow the hibernate model more closely, we'd send actor instances to the client without having populated the list of films for each actor at all. The first get call made on the films property for a given actor would then go back to the server and fetch them. As it is now, we'll do one query to retrieve the list of actors, then a query for each actor to get its list of films. For a large DB, this is a lot of queries to do. This is a pretty high priority feature request. For now, the workaround would be to modify your domain model so there is an intermediate object but that is awkward when you are generating everything from the simple schema. I'm not sure that I understand this. I believe that I have an intermediate object - filmActor.java and filmActor.as. Are you suggesting that I use that object - or rather those objects - as a way of finding out what filmIds are related to an actorId? I.e. that I load them from their own destination? I'm tired so if this isn't clear, don't worry about it. :-) Do I understand correctly that until we get the fix lazy loading isn't necessarily going to solve any performance problems? Douglas Jeff Vroom wrote: Thanks for this info. The performance problem is most likely due to the fact that FDMS is fetching the list of films for each actor... this is the lazy loading issue we have currently that I mentioned in a previous post. If we were to follow the hibernate model more closely, we'd send actor instances to the client without having populated the list of films for each actor at all. The first get call made on the films property for a given actor would then go back to the server and fetch them. As it is now, we'll do one query to retrieve the list of actors, then a query for each actor to get its list of films. For a large DB, this is a lot of queries to do. This is a pretty high priority feature request. For now, the workaround would be to modify your domain model so there is an intermediate object but that is awkward when you are generating everything from the simple schema. As to why it is not working, from the output, the filmId of each Film object is getting sent to the client as a null value. I am not sure why... I can't tell if it is retrieving the values from the database as null or if FDMS is just not getting the values from the objects properly. It could have something to do with the short data type - I do not think we've tried id properties as short values so maybe something is getting messed up because of that? It might be worth changing that to an int if that is an easy test to run
RE: [flexcoders] many-to-many managed association in Hibernate destination
Hi Douglas, I misspoke on one of my recommendations: One more thing is that because you are using a complex object type as an identity property, your FilmActor.as class will need a function like: public function toString():String { return actorId + : + filmId } I meant to say add this to the FilmActorId.as class. Sorry about that! Two more questions: 1. This would be so much easier if I had a working example to work from. I haven't found any examples that use the 'managed associations' approach - with one-to-many or many-to-many relationships. Jeff, do you know of any? Does anyone? Let me see if I can dig something up. We have a few applications folks built internally here that use hibernate with managed associations. It may take a bit of cleaning up to get it so they can be given out. 2. Victor Rubba has been kind enough to show me some code that he has that implements a many-to-many relationship with a link table. His link table has a numeric id column, which allows his code to avoid the whole complex id issue. Thus his destination config avoids 'composite-id'. Everything is much simpler. :-) (!) But we're wondering if this approach is correct, or if it's more correct to have a link table that only contains IDs from the linked tables, i.e. a composite ID. Both of those approaches work and so are correct in a certain sense. Probably most DBAs would prefer the link table which only has the ids from the linked tables since that extra id column is not strictly necessary. Note that FDMS supports Java/Actionscript objects which have more than one id property but I think hibernate requires that all id columns are stored in the same property in Java. I am not sure about that... Jeff -Original Message- From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On Behalf Of Douglas McCarroll Sent: Monday, December 04, 2006 6:00 PM To: flexcoders@yahoogroups.com Subject: Re: [flexcoders] many-to-many managed association in Hibernate destination Hi Jeff, Ok, so I think I see the problem then... Thanks for the response. I'm having some trouble applying this to my particular case and would like to check a bit to make sure that we're on the same page. Here's my question: If I run HibernateTools on a many-to-many table relationship with a link table - as shown here: http://www.brightworks.com/technology/tech_questions/hibernate_lazy_asso ciations/index.html - it creates a Java file like this: FilmActor.java package com.brightworks.apps.dvd_store; import java.util.Date; public class FilmActor { private FilmActorId id; private Film film; private Actor actor; private Date lastUpdate; public FilmActor() { } public FilmActor(FilmActorId id, Film film, Actor actor, Date lastUpdate) { this.id = id; this.film = film; this.actor = actor; this.lastUpdate = lastUpdate; } public FilmActorId getId() { return this.id; } public void setId(FilmActorId id) { this.id = id; } public Film getFilm() { return this.film; } public void setFilm(Film film) { this.film = film; } public Actor getActor() { return this.actor; } public void setActor(Actor actor) { this.actor = actor; } public Date getLastUpdate() { return this.lastUpdate; } public void setLastUpdate(Date lastUpdate) { this.lastUpdate = lastUpdate; } } The link table uses actor_id and film_id columns to link to the other two tables. But a FilmActor.java instance has: a) References to the Actor and Film instances that it is linking b) An instance of FilmActorId.java. This class obviously acts as the ID for FilmActor.java and contains ActorId and FilmId values. It's described in the mapping file like this: composite-id name=id class=com.brightworks.apps.dvd_store.FilmActorId key-property name=actorId type=short column name=actor_id / /key-property key-property name=filmId type=short column name=film_id / /key-property /composite-id You wrote: One more thing is that because you are using a complex object type as an identity property, your FilmActor.as class will need a function like: When you say complex object type I assume that you're referring to FilmActorId. Am I correct so far? But I run into a problem here: public function toString():String { return actorId + : + filmId } My FilmActor.as looks like this: package com.brightworks.apps.dvd_store.vo { [Managed] [RemoteClass(alias=com.brightworks.apps.dvd_store.FilmActor)] public class FilmActor { public function FilmActor() {} public var filmActorId:FilmActorId; public var film:Film; public var actor:Actor; public var lastUpdate:Date; } } I wrote it to simply reflect FilmActor.java's structure. It has no actorId or filmId, so I can't do return actorId + : + filmId I could add these properties, but I don't see how/why they'd get int values from FilmActor.java. Would FDMS or Hibernate know enough to pull them out of the FilmActor.java's complex ID? you could potentially implement the Film/Actors
RE: [flexcoders] many-to-many managed association in Hibernate destination
* Do I need a fourth destination for the FilmActorID class? Nope, that instance is managed by the FilmActor destination. It does not have its own id so it can't be in a separate destination. Jeff
Re: [flexcoders] many-to-many managed association in Hibernate destination
Thanks. I'll let you know how it goes. Jeff Vroom wrote: Ø Do I need a fourth destination for the FilmActorID class? Nope, that instance is managed by the FilmActor destination. It does not have its own “id” so it can’t be in a separate destination. Jeff -- Flexcoders Mailing List FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com Yahoo! Groups Links * To visit your group on the web, go to: http://groups.yahoo.com/group/flexcoders/ * Your email settings: Individual Email | Traditional * To change settings online go to: http://groups.yahoo.com/group/flexcoders/join (Yahoo! ID required) * To change settings via email: mailto:[EMAIL PROTECTED] mailto:[EMAIL PROTECTED] * To unsubscribe from this group, send an email to: [EMAIL PROTECTED] * Your use of Yahoo! Groups is subject to: http://docs.yahoo.com/info/terms/
RE: [flexcoders] many-to-many managed association in Hibernate destination
Hi Douglas, Ok, so I think I see the problem then - my apologies for not seeing it sooner. The FDMS destination does not have a destination for the filmActors type. Also, the property: Actor.filmActors has this association tag: many-to-many property=filmActors destination=film.hibernate lazy=true / it should instead refer to the new filmActors.hibernate destination you would add. This type would have its identity property with the name id and would have lazy one-to-one association properties both for film and actor which refer to the destinations film.hibernate and actor.hibernate. One more thing is that because you are using a complex object type as an identity property, your FilmActor.as class will need a function like: public function toString():String { return actorId + : + filmId } This is a requirement for complex object identity properties in FDMS (due to the fact that there is no Hashtable like class in ActionScript which uses equals/hashCode methods, we use a string key generated from the toString values of all identity properties to keep track of instances on the client). I think the hibernate assembler is missing an error test for the case where the type of the referenced entity does not match the destination's entity type. I'll fix that right away as that would have saved you a lot of time. Instead, it is looking for a filmId property on the FilmActor type and is getting back null (it should also print an error instead here). One other thing I'll mention as an aside is that you could potentially implement the Film/Actors relationship without an intermediate FilmActors class - both hibernate and FDMS will support that and since you do not have any additional properties in the mapping table, it is pretty common to avoid an extra type. You are right though that this fix will not greatly improve the performance. We are still going to need to do a query for each actor to retrieve the filmActors properties. It will be a little faster than today because it won't need to join in the Film table because of the intermediate mapping object. Jeff From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On Behalf Of Douglas McCarroll Sent: Thursday, November 30, 2006 5:39 PM To: flexcoders@yahoogroups.com Subject: Re: [flexcoders] many-to-many managed association in Hibernate destination Hi Jeff, A couple more thoughts... It's worth noting that I don't get the error when I use the hierarchical values approach without lazy loading, and get my films info from my actor objects. Thanks for this info. The performance problem is most likely due to the fact that FDMS is fetching the list of films for each actor... this is the lazy loading issue we have currently that I mentioned in a previous post. If we were to follow the hibernate model more closely, we'd send actor instances to the client without having populated the list of films for each actor at all. The first get call made on the films property for a given actor would then go back to the server and fetch them. As it is now, we'll do one query to retrieve the list of actors, then a query for each actor to get its list of films. For a large DB, this is a lot of queries to do. This is a pretty high priority feature request. For now, the workaround would be to modify your domain model so there is an intermediate object but that is awkward when you are generating everything from the simple schema. I'm not sure that I understand this. I believe that I have an intermediate object - filmActor.java and filmActor.as. Are you suggesting that I use that object - or rather those objects - as a way of finding out what filmIds are related to an actorId? I.e. that I load them from their own destination? I'm tired so if this isn't clear, don't worry about it. :-) Do I understand correctly that until we get the fix lazy loading isn't necessarily going to solve any performance problems? Douglas Jeff Vroom wrote: Thanks for this info. The performance problem is most likely due to the fact that FDMS is fetching the list of films for each actor... this is the lazy loading issue we have currently that I mentioned in a previous post. If we were to follow the hibernate model more closely, we'd send actor instances to the client without having populated the list of films for each actor at all. The first get call made on the films property for a given actor would then go back to the server and fetch them. As it is now, we'll do one query to retrieve the list of actors, then a query for each actor to get its list of films. For a large DB, this is a lot of queries to do. This is a pretty high priority feature request. For now, the workaround would be to modify your domain model so there is an intermediate object but that is awkward when you
Re: [flexcoders] many-to-many managed association in Hibernate destination
Hi Jeff, A couple more thoughts... It's worth noting that I don't get the error when I use the hierarchical values approach without lazy loading, and get my films info from my actor objects. Thanks for this info. The performance problem is most likely due to the fact that FDMS is fetching the list of films for each actor... this is the lazy loading issue we have currently that I mentioned in a previous post. If we were to follow the hibernate model more closely, we'd send actor instances to the client without having populated the list of films for each actor at all. The first get call made on the films property for a given actor would then go back to the server and fetch them. As it is now, we'll do one query to retrieve the list of actors, then a query for each actor to get its list of films. For a large DB, this is a lot of queries to do. This is a pretty high priority feature request. For now, the workaround would be to modify your domain model so there is an intermediate object but that is awkward when you are generating everything from the simple schema. I'm not sure that I understand this. I believe that I have an intermediate object - filmActor.java and filmActor.as. Are you suggesting that I use that object - or rather those objects - as a way of finding out what filmIds are related to an actorId? I.e. that I load them from their own destination? I'm tired so if this isn't clear, don't worry about it. :-) Do I understand correctly that until we get the fix lazy loading isn't necessarily going to solve any performance problems? Douglas Jeff Vroom wrote: Thanks for this info. The performance problem is most likely due to the fact that FDMS is fetching the list of films for each actor... this is the lazy loading issue we have currently that I mentioned in a previous post. If we were to follow the hibernate model more closely, we'd send actor instances to the client without having populated the list of films for each actor at all. The first get call made on the films property for a given actor would then go back to the server and fetch them. As it is now, we'll do one query to retrieve the list of actors, then a query for each actor to get its list of films. For a large DB, this is a lot of queries to do. This is a pretty high priority feature request. For now, the workaround would be to modify your domain model so there is an intermediate object but that is awkward when you are generating everything from the simple schema. As to why it is not working, from the output, the filmId of each Film object is getting sent to the client as a null value. I am not sure why... I can't tell if it is retrieving the values from the database as null or if FDMS is just not getting the values from the objects properly. It could have something to do with the short data type - I do not think we've tried id properties as short values so maybe something is getting messed up because of that? It might be worth changing that to an int if that is an easy test to run. I will try to get a chance to look at this more tomorrow. Jeff -Original Message- From: flexcoders@yahoogroups.com mailto:flexcoders%40yahoogroups.com [mailto:flexcoders@yahoogroups.com mailto:flexcoders%40yahoogroups.com] On Behalf Of Douglas McCarroll Sent: Wednesday, November 29, 2006 11:26 AM To: flexcoders@yahoogroups.com mailto:flexcoders%40yahoogroups.com Subject: Re: [flexcoders] many-to-many managed association in Hibernate destination Jeff Vroom wrote: 4) If you turn on debug logging in the server for the Endpoint.* logging category, you'll see the object graph which is sent to the client after your fill. I am curious if the time is being spent loading the data from the database or sending data to the client, or a combination of both. Okay, I've figured out how to do this part. Results here: http://www.brightworks.com/technology/tech_questions/hibernate_lazy_asso http://www.brightworks.com/technology/tech_questions/hibernate_lazy_asso ciations/debug_log_01.txt If you can also turn on debug logging of the SQL that hibernate is using that would help figure out if we are just fetching too many objects or what. It looks as though I do this by adding a line to HibernateManager.java... public void createSessionFactory(Configuration hibernateConfig, boolean useTransactions) throws ExceptionInInitializerError { try { New Line - hibernateConfig.setProperty(hibernate.show_sql, true) sessionFactory = hibernateConfig.buildSessionFactory(); Yes? BTW, in case someone finds this someday with Google, here are some resources: FDS Logging: http://livedocs.macromedia.com/flex/2/docs/wwhelp/wwhimpl/common/html/ww http://livedocs.macromedia.com/flex/2/docs/wwhelp/wwhimpl/common/html/ww help.htm?context=LiveDocs_Partsfile=1112.html http://weblogs.macromedia.com/dharfleet/archives/2006/08/debugging_flex. http
Re: [flexcoders] many-to-many managed association in Hibernate destination
Jeff Vroom wrote: 4) If you turn on debug logging in the server for the “Endpoint.*” logging category, you’ll see the object graph which is sent to the client after your fill. I am curious if the time is being spent loading the data from the database or sending data to the client, or a combination of both. Okay, I've figured out how to do this part. Results here: http://www.brightworks.com/technology/tech_questions/hibernate_lazy_associations/debug_log_01.txt If you can also turn on debug logging of the SQL that hibernate is using that would help figure out if we are just fetching too many objects or what. It looks as though I do this by adding a line to HibernateManager.java... public void createSessionFactory(Configuration hibernateConfig, boolean useTransactions) throws ExceptionInInitializerError { try { New Line - hibernateConfig.setProperty(hibernate.show_sql, true) sessionFactory = hibernateConfig.buildSessionFactory(); Yes? BTW, in case someone finds this someday with Google, here are some resources: FDS Logging: http://livedocs.macromedia.com/flex/2/docs/wwhelp/wwhimpl/common/html/wwhelp.htm?context=LiveDocs_Partsfile=1112.html http://weblogs.macromedia.com/dharfleet/archives/2006/08/debugging_flex.cfm http://tech.groups.yahoo.com/group/flexcoders/message/56192 Hibernate Logging: http://www.javalobby.org/java/forums/t44119.html -- Flexcoders Mailing List FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com Yahoo! Groups Links * To visit your group on the web, go to: http://groups.yahoo.com/group/flexcoders/ * Your email settings: Individual Email | Traditional * To change settings online go to: http://groups.yahoo.com/group/flexcoders/join (Yahoo! ID required) * To change settings via email: mailto:[EMAIL PROTECTED] mailto:[EMAIL PROTECTED] * To unsubscribe from this group, send an email to: [EMAIL PROTECTED] * Your use of Yahoo! Groups is subject to: http://docs.yahoo.com/info/terms/
RE: [flexcoders] many-to-many managed association in Hibernate destination
Thanks for this info. The performance problem is most likely due to the fact that FDMS is fetching the list of films for each actor... this is the lazy loading issue we have currently that I mentioned in a previous post. If we were to follow the hibernate model more closely, we'd send actor instances to the client without having populated the list of films for each actor at all. The first get call made on the films property for a given actor would then go back to the server and fetch them. As it is now, we'll do one query to retrieve the list of actors, then a query for each actor to get its list of films. For a large DB, this is a lot of queries to do. This is a pretty high priority feature request. For now, the workaround would be to modify your domain model so there is an intermediate object but that is awkward when you are generating everything from the simple schema. As to why it is not working, from the output, the filmId of each Film object is getting sent to the client as a null value. I am not sure why... I can't tell if it is retrieving the values from the database as null or if FDMS is just not getting the values from the objects properly. It could have something to do with the short data type - I do not think we've tried id properties as short values so maybe something is getting messed up because of that? It might be worth changing that to an int if that is an easy test to run. I will try to get a chance to look at this more tomorrow. Jeff -Original Message- From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On Behalf Of Douglas McCarroll Sent: Wednesday, November 29, 2006 11:26 AM To: flexcoders@yahoogroups.com Subject: Re: [flexcoders] many-to-many managed association in Hibernate destination Jeff Vroom wrote: 4) If you turn on debug logging in the server for the Endpoint.* logging category, you'll see the object graph which is sent to the client after your fill. I am curious if the time is being spent loading the data from the database or sending data to the client, or a combination of both. Okay, I've figured out how to do this part. Results here: http://www.brightworks.com/technology/tech_questions/hibernate_lazy_asso ciations/debug_log_01.txt If you can also turn on debug logging of the SQL that hibernate is using that would help figure out if we are just fetching too many objects or what. It looks as though I do this by adding a line to HibernateManager.java... public void createSessionFactory(Configuration hibernateConfig, boolean useTransactions) throws ExceptionInInitializerError { try { New Line - hibernateConfig.setProperty(hibernate.show_sql, true) sessionFactory = hibernateConfig.buildSessionFactory(); Yes? BTW, in case someone finds this someday with Google, here are some resources: FDS Logging: http://livedocs.macromedia.com/flex/2/docs/wwhelp/wwhimpl/common/html/ww help.htm?context=LiveDocs_Partsfile=1112.html http://weblogs.macromedia.com/dharfleet/archives/2006/08/debugging_flex. cfm http://tech.groups.yahoo.com/group/flexcoders/message/56192 Hibernate Logging: http://www.javalobby.org/java/forums/t44119.html -- Flexcoders Mailing List FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com Yahoo! Groups Links
[flexcoders] many-to-many managed association in Hibernate destination
Hi All, This is essentially a repost of my How to implement Lazy Hibernate? question. I'm still completely stuck. Here's the error message I'm getting: [RPC Fault faultString=Page request made for item with id = '{filmId=null}'. The item was not in the cache and the adapter's get method failed to return the item for destination = film.hibernate that is expected to be in the requested page. faultCode=Server.Processing faultDetail=null] Here's the big picture: I'm attempting to create a Cairngorm/FDMS/Hibernate/MySQL example program. I have three tables. 'actor' and 'film' have a many-to-many relationship so they're connected by a link table 'film_actor'. I've used HibernateTools to create .java and .hbm.xml classes by reverse engineering the DB. I assume the HibernateTools knows what it is doing so I'm assuming that the generated code is correct. And I've successfully implemented .as classes and data-management-config.xml and displayed data. I can click on an actor and display the films that s/he's in. This all works through a single destination that uses my Actor.java class. This uses the 'hierarchical values' approach to managing hierarchical collections, i.e. just using the 'actor' destination. This approach is problematic because there are circular references between Actor and Film objects. It seems to me that the obvious solution is lazy loading. I don't see anything in the docs explaining how to do this with the hierarchical values approach, so I'm attempting to use a 'lazy' managed associations approach. But I get the above error. Someone who knows FDMS might be able to look at my code and fairly easily point me in the right direction. I've zipped up the entire project - plus a .sql file you can use to create my MySQL DB - and put them up for download: http://www.brightworks.com/technology/tech_questions/hibernate_lazy_associations/Bw_005.zip Or, you can just look at the code here: http://www.brightworks.com/technology/tech_questions/hibernate_lazy_associations/code.txt The DB's schema is here: http://www.brightworks.com/technology/tech_questions/hibernate_lazy_associations/index.html And here's a lovely variables view of the circular references I'm trying to avoid :-) : http://www.brightworks.com/technology/tech_questions/hibernate_lazy_associations/deeply_nested_actors_and_films.jpg Help? Douglas
Re: [flexcoders] many-to-many managed association in Hibernate destination
I'm not currently using Flex, but I don't believe it's possible to map ActionScript classes to lazily-loaded Hibernate classes because of all the hibernate proxy stuff. I was under the impression that you have to use DTOs, rather than mapping your client classes to your domain objects. Am I wrong? - Richard On 11/28/06, Douglas McCarroll [EMAIL PROTECTED] wrote: Hi All, This is essentially a repost of my How to implement Lazy Hibernate? question. I'm still completely stuck. Here's the error message I'm getting: [RPC Fault faultString=Page request made for item with id = '{filmId=null}'. The item was not in the cache and the adapter's get method failed to return the item for destination = film.hibernate that is expected to be in the requested page. faultCode=Server.Processing faultDetail=null] Here's the big picture: I'm attempting to create a Cairngorm/FDMS/Hibernate/MySQL example program. I have three tables. 'actor' and 'film' have a many-to-many relationship so they're connected by a link table 'film_actor'. I've used HibernateTools to create .java and .hbm.xml classes by reverse engineering the DB. I assume the HibernateTools knows what it is doing so I'm assuming that the generated code is correct. And I've successfully implemented .as classes and data-management-config.xml and displayed data. I can click on an actor and display the films that s/he's in. This all works through a single destination that uses my Actor.java class. This uses the 'hierarchical values' approach to managing hierarchical collections, i.e. just using the 'actor' destination. This approach is problematic because there are circular references between Actor and Film objects. It seems to me that the obvious solution is lazy loading. I don't see anything in the docs explaining how to do this with the hierarchical values approach, so I'm attempting to use a 'lazy' managed associations approach. But I get the above error. Someone who knows FDMS might be able to look at my code and fairly easily point me in the right direction. I've zipped up the entire project - plus a .sql file you can use to create my MySQL DB - and put them up for download: http://www.brightworks.com/technology/tech_questions/hibernate_lazy_associations/Bw_005.zip Or, you can just look at the code here: http://www.brightworks.com/technology/tech_questions/hibernate_lazy_associations/code.txt The DB's schema is here: http://www.brightworks.com/technology/tech_questions/hibernate_lazy_associations/index.html And here's a lovely variables view of the circular references I'm trying to avoid :-) : http://www.brightworks.com/technology/tech_questions/hibernate_lazy_associations/deeply_nested_actors_and_films.jpg Help? Douglas
Re: [flexcoders] many-to-many managed association in Hibernate destination
Hi Richard, I was under the impression that you have to use DTOs, rather than mapping your client classes to your domain objects. I Google flex hibernate lazy and I find this: http://livedocs.macromedia.com/flex/2/docs/wwhelp/wwhimpl/common/html/wwhelp.htm?context=LiveDocs_Partsfile=1201.html It includes config code that looks like this: destination id=HibernatePerson channels=rtmp-ac adapter ref=java-adapter / properties sourceflex.data.assemblers.HibernateAssembler/source scopeapplication/scope metadata identity property=id/ many-to-one property=group destination=HibernateGroup lazy=true/ /metadata This looks like they're mapping directly to a domain object, yes? Douglas Richard Rodseth wrote: I'm not currently using Flex, but I don't believe it's possible to map ActionScript classes to lazily-loaded Hibernate classes because of all the hibernate proxy stuff. I was under the impression that you have to use DTOs, rather than mapping your client classes to your domain objects. Am I wrong? - Richard On 11/28/06, *Douglas McCarroll* [EMAIL PROTECTED] mailto:[EMAIL PROTECTED] wrote: Hi All, This is essentially a repost of my How to implement Lazy Hibernate? question. I'm still completely stuck. Here's the error message I'm getting: [RPC Fault faultString=Page request made for item with id = '{filmId=null}'. The item was not in the cache and the adapter's get method failed to return the item for destination = film.hibernate that is expected to be in the requested page. faultCode=Server.Processing faultDetail=null] Here's the big picture: I'm attempting to create a Cairngorm/FDMS/Hibernate/MySQL example program. I have three tables. 'actor' and 'film' have a many-to-many relationship so they're connected by a link table 'film_actor'. I've used HibernateTools to create .java and .hbm.xml classes by reverse engineering the DB. I assume the HibernateTools knows what it is doing so I'm assuming that the generated code is correct. And I've successfully implemented .as classes and data-management-config.xml and displayed data. I can click on an actor and display the films that s/he's in. This all works through a single destination that uses my Actor.java class. This uses the 'hierarchical values' approach to managing hierarchical collections, i.e. just using the 'actor' destination. This approach is problematic because there are circular references between Actor and Film objects. It seems to me that the obvious solution is lazy loading. I don't see anything in the docs explaining how to do this with the hierarchical values approach, so I'm attempting to use a 'lazy' managed associations approach. But I get the above error. Someone who knows FDMS might be able to look at my code and fairly easily point me in the right direction. I've zipped up the entire project - plus a .sql file you can use to create my MySQL DB - and put them up for download: http://www.brightworks.com/technology/tech_questions/hibernate_lazy_associations/Bw_005.zip http://www.brightworks.com/technology/tech_questions/hibernate_lazy_associations/Bw_005.zip Or, you can just look at the code here: http://www.brightworks.com/technology/tech_questions/hibernate_lazy_associations/code.txt http://www.brightworks.com/technology/tech_questions/hibernate_lazy_associations/code.txt The DB's schema is here: http://www.brightworks.com/technology/tech_questions/hibernate_lazy_associations/index.html http://www.brightworks.com/technology/tech_questions/hibernate_lazy_associations/index.html And here's a lovely variables view of the circular references I'm trying to avoid :-) : http://www.brightworks.com/technology/tech_questions/hibernate_lazy_associations/deeply_nested_actors_and_films.jpg http://www.brightworks.com/technology/tech_questions/hibernate_lazy_associations/deeply_nested_actors_and_films.jpg Help? Douglas
RE: [flexcoders] many-to-many managed association in Hibernate destination
Sorry for not chiming in sooner - I was on vacation the last couple of days. I'm afraid I haven't had a chance to look at the code you posted but I have a few comments that will hopefully help. 1) The HibernateAssembler does have some logic to deal with hibernate's generated proxy classes when you are using FDMS with hibernate. This involves two parts: 1) pre-fetching any lazily loaded data that we will need to serialize to the client and 2) unwrapping the proxied classes so that the class names are properly mapped if you are using strongly typed AS classes to map to your hibernate domain model classes. We need to do 1) so that hibernate has loaded all of the object's state that the client requires while the transaction is still open. This also allows us to unwrap the proxies during deserialization since we know all of the state we need will have been fetched in the wrapped implementation instance. There is a performance issue with the code that implements 1) in that currently hibernate's lazy loading and FDMS's lazy loading are a little different for multi-valued properties and this could be contributing to your performance problem. Basically, weFDMS needs to prefetch the value of the multi-valued association property even when the property is marked with lazy=true in your FDMS configuration. This is because FDMS wants to send the ids of the referenced objects down with the state of the parent object... hibernate initially does not fetch any values in the multi-valued association property and when you first retrieve the collection it gets all of the data in the collection. We have an open enhancement request to support a model for FDMS which matches hibernate's to make this more efficient. 2) We should support bi-directional references in your object graph though it is a good practice to ensure all back ptrs are marked with lazy=true in the FDMS configuration. 3) In the flex-builder variables view you sent in the screen-shot, keep in mind that flexbuilder is not good at letting you know when you have hit a recursive ptr in the variables view. It looks to me like you are seeing the same objects over and over again rather than seeing a huge tree that is being sent to the client (you can match up the addresses flexbuilder displays for each object to detect this yourself). 4) If you turn on debug logging in the server for the Endpoint.* logging category, you'll see the object graph which is sent to the client after your fill. I am curious if the time is being spent loading the data from the database or sending data to the client, or a combination of both. If you can also turn on debug logging of the SQL that hibernate is using that would help figure out if we are just fetching too many objects or what. I'll hopefully get a chance to look into the test case in more detail later. Regards, Jeff From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On Behalf Of Douglas McCarroll Sent: Tuesday, November 28, 2006 3:19 PM To: flexcoders@yahoogroups.com Subject: Re: [flexcoders] many-to-many managed association in Hibernate destination Hi Richard, I was under the impression that you have to use DTOs, rather than mapping your client classes to your domain objects. I Google flex hibernate lazy and I find this: http://livedocs.macromedia.com/flex/2/docs/wwhelp/wwhimpl/common/html/ww help.htm?context=LiveDocs_Partsfile=1201.html http://livedocs.macromedia.com/flex/2/docs/wwhelp/wwhimpl/common/html/w whelp.htm?context=LiveDocs_Partsfile=1201.html It includes config code that looks like this: destination id=HibernatePerson channels=rtmp-ac adapter ref=java-adapter / properties sourceflex.data.assemblers.HibernateAssembler/source scopeapplication/scope metadata identity property=id/ many-to-one property=group destination=HibernateGroup lazy=true/ /metadata This looks like they're mapping directly to a domain object, yes? Douglas Richard Rodseth wrote: I'm not currently using Flex, but I don't believe it's possible to map ActionScript classes to lazily-loaded Hibernate classes because of all the hibernate proxy stuff. I was under the impression that you have to use DTOs, rather than mapping your client classes to your domain objects. Am I wrong? - Richard On 11/28/06, *Douglas McCarroll* [EMAIL PROTECTED] mailto:org.yahoo_primary.001%40douglasmccarroll.com mailto:[EMAIL PROTECTED] mailto:org.yahoo_primary.001%40douglasmccarroll.com wrote: Hi All, This is essentially a repost of my How to implement Lazy Hibernate? question. I'm still completely stuck. Here's the error message I'm getting: [RPC Fault faultString=Page request made for item with id = '{filmId=null}'. The item was not in the cache and the adapter's get method failed to return the item for destination = film.hibernate that is expected to be in the requested page. faultCode=Server.Processing
Re: [flexcoders] many-to-many managed association in Hibernate destination
Hi Jeff, Thanks for your response! I'm going to take a while to absorb (1) and (2) but here's a quick response for (3) and (4). (3) It looks to me like you are seeing the same objects over and over again rather than seeing a huge tree Yes, absolutely. I'd noticed that that was the case. And I assume that the fact that they are the same objects referenced over and over limits the damage. Instead of huge numbers of objects we just have huge numbers of references? Or maybe we don't - I guess that we're just seeing the same references over and over again too. But something is slowing the app down big-time. I've pared the number of records in the DB down to hundreds per table so that it loads in a few seconds, but with thousands of records and non-lazy hierarchical-data-approach it was taking over 30 seconds to load... (4) Can you give me a few details on how to turn on these two types of debugging? Even just file names would help - then I can Google/research the details - and ask again if I get stuck. :-) Thanks, Douglas Jeff Vroom wrote: Sorry for not chiming in sooner – I was on vacation the last couple of days. I’m afraid I haven’t had a chance to look at the code you posted but I have a few comments that will hopefully help. 1) The HibernateAssembler does have some logic to deal with hibernate’s generated proxy classes when you are using FDMS with hibernate. This involves two parts: 1) pre-fetching any lazily loaded data that we will need to serialize to the client and 2) unwrapping the proxied classes so that the class names are properly mapped if you are using strongly typed AS classes to map to your hibernate domain model classes. We need to do 1) so that hibernate has loaded all of the object’s state that the client requires while the transaction is still open. This also allows us to unwrap the proxies during deserialization since we know all of the state we need will have been fetched in the wrapped implementation instance. There is a performance issue with the code that implements 1) in that currently hibernate’s lazy loading and FDMS’s lazy loading are a little different for multi-valued properties and this could be contributing to your performance problem. Basically, we FDMS needs to prefetch the value of the multi-valued association property even when the property is marked with lazy=”true” in your FDMS configuration. This is because FDMS wants to send the ids of the referenced objects down with the state of the parent object… hibernate initially does not fetch any values in the multi-valued association property and when you first retrieve the collection it gets all of the data in the collection. We have an open enhancement request to support a model for FDMS which matches hibernate’s to make this more efficient. 2) We should support bi-directional references in your object graph though it is a good practice to ensure all “back ptrs” are marked with lazy=”true” in the FDMS configuration. 3) In the flex-builder variables view you sent in the screen-shot, keep in mind that flexbuilder is not good at letting you know when you have hit a recursive ptr in the variables view. It looks to me like you are seeing the same objects over and over again rather than seeing a huge tree that is being sent to the client (you can match up the addresses flexbuilder displays for each object to detect this yourself). 4) If you turn on debug logging in the server for the “Endpoint.*” logging category, you’ll see the object graph which is sent to the client after your fill. I am curious if the time is being spent loading the data from the database or sending data to the client, or a combination of both. If you can also turn on debug logging of the SQL that hibernate is using that would help figure out if we are just fetching too many objects or what. I’ll hopefully get a chance to look into the test case in more detail later. Regards, Jeff *From:* flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] *On Behalf Of *Douglas McCarroll *Sent:* Tuesday, November 28, 2006 3:19 PM *To:* flexcoders@yahoogroups.com *Subject:* Re: [flexcoders] many-to-many managed association in Hibernate destination Hi Richard, I was under the impression that you have to use DTOs, rather than mapping your client classes to your domain objects. I Google flex hibernate lazy and I find this: http://livedocs.macromedia.com/flex/2/docs/wwhelp/wwhimpl/common/html/wwhelp.htm?context=LiveDocs_Partsfile=1201.html http://livedocs.macromedia.com/flex/2/docs/wwhelp/wwhimpl/common/html/wwhelp.htm?context=LiveDocs_Partsfile=1201.html It includes config code that looks like this: destination id=HibernatePerson channels=rtmp-ac adapter ref=java-adapter / properties sourceflex.data.assemblers.HibernateAssembler/source