First of all thanks to all of you for your answers and time. Michael let me 
say that I agree 100% with all you wrote and my will/wish is to work as you 
wrote, but when you are inside the ORM its easy, other is if you want to 
interact with the ORM from outside.

In my actual system I have more than 500 tables automatically generated 
from a UML model. Not all of them have a central role but all of them do 
something in the data model. If I want to fill one of the highest level 
object its attributes are classes their self with other attributes which 
are classes again; because I cannot simply send a few primitive parameters 
to the a function-ORM-aware and make the function create that object I am 
forced to create locally (in the GUI application) such object and their 
children (some of them can be NOT NULL so I cannot avoid it) then send the 
full object to the ORM interface.

Apart the great advantages that an ORM offers it should be possible to 
install it as a service, that is separate it from the any other 
application: in other words I can have a library of objects (like I have) 
shared among several GUI/WEB applications and an ORM. The communication 
between the applications and the ORM should be done serializing and 
deserializing instances of objects in the shared library. As example you 
can take the remote interface for an EJB in Java (btw I am thinking about 
the stateless interface). In this way the ORM does have not to expose to 
other applicaitons it's "session" (or EntityManager in EJB) but just an 
interface. Still in other words the rules that I impose on how I manage my 
database (that is one or more method using session/transaction), should be 
independent from the way I display/control them. Again: I would like to use 
SA as the MODEL of a Model-View-Controller strategy and because of this I 
can have a myriad of views/controlles but just one separate model 
application acting as service.

Now I am aware that my application is not decoupled as I want (Django 
initialize the SQL engine) so I cannot avoid SA to inject instruments in 
new instances but nonetheless I would expect that I may be able to work 
with objects in two separate universes: the GUI and the ORM.

When I wrote that I feel to have missed something I was referring to this: 
it seems to me that I cannot use SA in a remote-like way, creating an 
object in the GUI and then send it to the ORM, being sure that because the 
ORM maps such object it knows how to persist it or eventually retrieve it 
because it know where to catch the key for each mapped object.

For all the rest, thanks for your great software.
Maurizio

P.S.
If you are curious about the system I am working on just take a brief look 
at it here <http://cedadocs.badc.rl.ac.uk/905/> or 
here<http://jenkins.badc.rl.ac.uk/cedaManager/cov/1>

On Thursday, May 31, 2012 4:50:38 AM UTC+1, Michael Bayer wrote:
>
>
> On May 30, 2012, at 8:53 PM, Claudio Freire wrote: 
>
> > 
> > Thing is, in order to work with a large volume of objects, you're 
> > forced to do this, otherwise the session can grow uncontrollably. 
>
> flush periodically, and don't maintain references to things you're done 
> with.  The Session does not strongly reference objects that have no pending 
> changes, and they'll be garbage collected. 
>
>
> > When 
> > you separate the operation to work in batches, you almost always have 
> > some objects that have a lifespan larger than a single batch, and then 
> > a single session. 
>
> Working in batches is fine.  You only need a single Session for all those 
> batches, and a single transaction.    If you want several transactions, 
> also fine, call commit() periodically.  In none of these cases does the 
> Session need to be closed, and all objects worked with thus far which are 
> still referenced in memory can remain attached to that Session, and you 
> wont have any detachment errors. 
>
> The problems you're having are from unnecessary detachment of objects, 
> from calling Session.close() and continuing to work with objects that have 
> lost their owning Session, within the context of a new Session they have no 
> association with.   
>
> > 
> > Another case in which an object's lifespan can exceed the session's, 
> > is when you want to implement caching with objects of your data model 
> > - cached values will have come from other sessions than the current 
> > one, and things get horribly messy. 
>
> There are documented patterns for caching - see the example in 
> examples/beaker_caching in the distro.   This pattern is designed to 
> cleanly handle the pattern of detached objects becoming re-associated with 
> a particular session at once.   The pattern is along the lines of, session 
> is created to work with a field of objects, a set of objects is retrieved 
> from the cache, then re-associated with the cache en-masse using the 
> merge_result() method illustrated in the example. 
>
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/sqlalchemy/-/S-_KYwrs544J.
To post to this group, send email to sqlalchemy@googlegroups.com.
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.

Reply via email to