Managed Hosting



Project Home Blog Forums Wiki Known Issues Contact Project

FlexORM Issue: entityMap not destroyed when closing/opening async connection

Name: entityMap not destroyed when closing/opening async connection
ID: 2
Project: FlexORM
Type: Bug
Area: Code
Severity: Normal
Status: Open
Related URL:
Creator: Jim
Created: 10/18/09 9:57 PM
Updated: 03/21/10 2:25 PM
Description: Steps:
Open a connection (openAsyncConnection), create and save an object X to the DB, close the connection, delete the dbfile, open the connection again, then save a new object X to the DB
SQLConnection reports as not being open when you save X.
It appears that the entityMap that is managed for the EntityManagerBase retains a reference to the 1st SQLConnection and then uses this when saving object X.
A workaround is to take the code within the EntityManagerBase constructor and copy this out into a new public EntityManagerBase.init() function, then call this after closing the old connection.
History: Created by jdp (Jim) : 10/18/09 9:57 PM

Comment by fsans (Francesc Sans) : 01/16/10 8:00 AM
Unlok the singleton blocker in the EntityManager class commenting this code in the constructor:

if (!localInstantiation)
throw new Error("EntityManager is a singleton. Use EntityManager.instance ");

Then create a proxy class that instantiate, initialize, close, reopen the EntytyManager on demand, changing the db at runtime. Alternatively, comment the singleton blocker and create a new class extending the native EntytyManager class. The two worked fine.

Comment by danmoov2 (Dan Thomas) : 03/21/10 2:25 PM
Here's a patch to fix

if you want to apply to source and have subclipse:
Copy the below patch (starts -> Index: EntityManagerbase.as...)
Right click on the EntityManagerBase file
click Team > Apply Patch
follow prompts


Index: EntityManagerBase.as
--- EntityManagerBase.as   (revision 51)
+++ EntityManagerBase.as   (working copy)
@@ -1,12 +1,13 @@
package nz.co.codec.flexorm
import flash.data.SQLConnection;
+ import flash.events.SQLEvent;
import flash.utils.Dictionary;
import flash.utils.getDefinitionByName;
import flash.utils.getQualifiedClassName;
import mx.collections.ArrayCollection;
import nz.co.codec.flexorm.command.InsertCommand;
import nz.co.codec.flexorm.command.SQLParameterisedCommand;
import nz.co.codec.flexorm.command.UpdateCommand;
@@ -43,7 +44,12 @@

public function EntityManagerBase()
- _schema = DEFAULT_SCHEMA;
+ init();
+ }
+ private function init():void
+ {
+    _schema = DEFAULT_SCHEMA;
_prefs = {};
_prefs.namingStrategy = NamingStrategy.UNDERSCORE_NAMES;
_prefs.syncSupport = false;
@@ -62,6 +68,8 @@
public function set sqlConnection(value:SQLConnection):void
_sqlConnection = value;
+ if(_sqlConnection != null)
+    _sqlConnection.addEventListener(SQLEvent.CLOSE, onSqlConnectionClose);
_introspector = new EntityIntrospector(_schema, value, _entityMap, _debugLevel, _prefs);

@@ -368,5 +376,10 @@
return ((id is int && id > 0) || (id is String && id != null));

+      protected function onSqlConnectionClose( e : SQLEvent ) :void
+      {
+         this.init();
+      }         
\ No newline at end of file

To add a comment to this bug, please login using the link above.