rss
twitter
Find out what I'm doing, Follow Me :)

ORM entityDelete() bug?

0
 

I'm still trying to wrap my head around the relationships in ORM. Yesterday I wanted to delete all the child entities with the parent is delete. No problem, there is an attribute for that. cascade="all-delete-orphan". Well, it wasn't working for me.

It turned out, in my Mach-II app I was using event-bean (by mistake) to prepare the bean and then calling EntityDelete() on it. The entity was getting deleted but the child entities were not getting deleted. No error either. Once I realized my mistake (event-bean), and changed to call-method to load the entity and then call entityDelete() on it everything worked fine.

So, what is the bug? Here is the code equivalent (artist-art example) of my mumbo-jumbo above:

 

var artist = new Artist();
artist.setArtistID(1);
entityDelete(artist);

 

In the code above artist is a transient object and I believe it should _not_ delete the record from the database. It should either throw error or ignore the delete. As it stands, it will delete the artist but not the arts, even with cascade="all-delete-orphan".  It even behaves a little funcky with inverse="true" option on relationship. 

Here is the code that works properly:

 

var artist = entityLoad("Artist", 1, true);
entityDelete(artist);

 

Here is thread on ORM google groups with examples:

http://groups.google.com/group/cf-orm-dev/browse_thread/thread/1d924dcc28185ddd