reset password
Author Message
Vanquish39
Posts: 134
Posted 10:14 Nov 02, 2011 |

How does one cascade a collection of simple types? 

I.E @ElementCollection

I found out a way to delete an object and the simple collection with it, but I think there should be an easier way than what I've done.

Also let's say you have class A

Class A has List<B>

Class A has List<C>

If the mappings for B and C both have CascadeType.ALL, deleting A will result in the deletion of B and C right from the database right?

Thanks.

cysun
Posts: 2935
Posted 10:21 Nov 02, 2011 |

@ElementCollection doesn't have a cascade option because all operations (i.e. persist, merge, delete etc.) are always cascaded, so yes, you can delete A, and B and C will be deleted.

Vanquish39
Posts: 134
Posted 14:04 Nov 02, 2011 |

That's strange.

I have a Criterion object with a List<String> descriptions in it.  When I delete the criterion, the descriptions table doesn't get deleted.  Am I doing something wrong?

cysun
Posts: 2935
Posted 14:05 Nov 02, 2011 |
Vanquish39 wrote:

That's strange.

I have a Criterion object with a List<String> descriptions in it.  When I delete the criterion, the descriptions table doesn't get deleted.  Am I doing something wrong?

Of course the table won't be deleted. The descriptions are.

Vanquish39
Posts: 134
Posted 14:06 Nov 02, 2011 |

Sorry lol, I meant the descriptions in the table don't get deleted.

cysun
Posts: 2935
Posted 14:20 Nov 02, 2011 |
Vanquish39 wrote:

Sorry lol, I meant the descriptions in the table don't get deleted.

That shouldn't be the case. @ElementCollection doesn't have a cascade attribute because CascadeType.ALL is assumed. In your case did the foreign key column of the descriptions became NULL after deletion?

Vanquish39
Posts: 134
Posted 14:42 Nov 02, 2011 |

my descriptions table has only a criterion_id and a description.  Nothing happens, no NULL no anything. 

When I delete the criterion, the criterion information gets deleted but the the descriptions don't.

 

Also there is a lot of talk about Spring Tool Suite or Spring Roo.  I'm downloading Spring Tool Suite to give it a try.  Would you recommend it?  The spring archetypes for maven are giving me errors. 

Last edited by Vanquish39 at 14:44 Nov 02, 2011.
cysun
Posts: 2935
Posted 15:07 Nov 02, 2011 |
Vanquish39 wrote:

my descriptions table has only a criterion_id and a description.  Nothing happens, no NULL no anything. 

When I delete the criterion, the criterion information gets deleted but the the descriptions don't.

 

Also there is a lot of talk about Spring Tool Suite or Spring Roo.  I'm downloading Spring Tool Suite to give it a try.  Would you recommend it?  The spring archetypes for maven are giving me errors. 

If the foreign key column was not null yet the the criterion was deleted, you should have got a constraint violation exception. I think there might be something wrong in your code that the criterion was not deleted properly.

I've used STS and tried a little bit Roo. STS lets you create a Spring MVC application easily, but you can just as easily do that with a good Maven archetype. STS has many other features (e.g. integration with their cloud service) but I don't use them so I can't comment  on those.

Note that creating a Spring MVC application seems complicated not because of Spring, which is really just a standard Java webapp with a DispatcherServer and a bean configuration files - it's complicated because of all the other libraries you typically use in a Spring MVC application, like Hibernate, EHCache, Log4j, Tiles, Velocity, DisplayTag, JPA, TestNG/JUnit, and so on. If you don't have at least some understanding of those libraries, no archetype/template can help you.

As for Roo, it gives impressive demos, but I'm suspicious of using it in non-trivial non-cookie-cutter projects. In particular, I don't quite like it's extensive use of AOP/code generation behind the scene. It's really cool when everything works, but it's quite hard to debug when something fails.