Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 334149 - Collection Type should be user specifiable
Summary: Collection Type should be user specifiable
Status: RESOLVED FIXED
Alias: None
Product: Dali JPA Tools
Classification: WebTools
Component: Diagram Editor (show other bugs)
Version: 0.5   Edit
Hardware: All All
: P3 normal (vote)
Target Milestone: 3.0 M7   Edit
Assignee: Petya Sabeva CLA
QA Contact: Stefan Dimov CLA
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-01-12 13:21 EST by Shaun Smith CLA
Modified: 2011-04-14 12:55 EDT (History)
0 users

See Also:


Attachments
patch (26.53 KB, patch)
2011-01-27 09:14 EST, Petya Sabeva CLA
stefan.dimov: iplog+
Details | Diff
additional patch (4.88 KB, patch)
2011-01-28 03:49 EST, Petya Sabeva CLA
no flags Details | Diff
patch for tests (1.96 KB, patch)
2011-01-28 03:50 EST, Petya Sabeva CLA
no flags Details | Diff
Adds java.util.Map support (86.59 KB, patch)
2011-04-14 10:37 EDT, Stefan Dimov CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Shaun Smith CLA 2011-01-12 13:21:29 EST
The default type of collections defined by the editor should be specifiable by the user.  Currently all collections are defined as type "Collection". JPA supports Collection, List, and Set.
Comment 1 Petya Sabeva CLA 2011-01-27 09:14:23 EST
Created attachment 187732 [details]
patch
Comment 2 Stefan Dimov CLA 2011-01-27 11:56:20 EST
Patch committed ...
Comment 3 Stefan Dimov CLA 2011-01-27 12:08:28 EST
I found a bug coming with this patch.

1. Open Eclipse IDE with clean workspace
2. Create JPA project in it
3. Open diagram and create two entities
4. Create Many-to-many relation between the entities
Result: Inspect the code and you will see that the relation attributes are of type java.util.Set instead of java.util.Collection although the default prefs/props haven't been changed
Comment 4 Petya Sabeva CLA 2011-01-28 02:08:49 EST
This is not a bug or at least it doesn't come with this bug. I noticed, that it has been already implemented that when a Many-to-Many bidirection/unidirectinal relation is created, its attributes will be of type java.util.Set. So I thought that there is something specific for that relation and that's way I didn't change it...
Comment 5 Petya Sabeva CLA 2011-01-28 02:10:02 EST
(In reply to comment #4)
> This is not a bug or at least it doesn't come with this bug. 

Ops I ment it doesn't come with this patch...
Comment 6 Stefan Dimov CLA 2011-01-28 02:58:08 EST
There is nothing specific about it. I don't remember why it was 'java.util.Set' initially, but now it should be fixed because it's not consistent with your patch. Could you please provide one more patch for this, Petya?
Comment 7 Petya Sabeva CLA 2011-01-28 03:49:30 EST
Created attachment 187810 [details]
additional patch
Comment 8 Petya Sabeva CLA 2011-01-28 03:50:07 EST
Created attachment 187811 [details]
patch for tests
Comment 9 Stefan Dimov CLA 2011-01-28 05:27:29 EST
The patch is committed, but I have a question:

Petya pointed out that actually specification allows also java.util.Map to be a type of a relationship attribute.

Shaun, did you omit the 'Map' type intentionally for some reason? If not, perhaps we should implement this too?
Comment 10 Shaun Smith CLA 2011-01-28 11:10:41 EST
I didn't mean to leave out Map intentionally. I should have gone "..." or etc. so we cover all supported collection types.

Can you clarify what the default behavior is when creating a *ToMany relationship and how the collection class default can be specified?  I, and I think most JPA developers, use List as their default so I'd want to be able to set this as my preference.
Comment 11 Stefan Dimov CLA 2011-04-14 10:37:46 EDT
Created attachment 193259 [details]
Adds java.util.Map support
Comment 12 Stefan Dimov CLA 2011-04-14 10:58:25 EDT
(In reply to comment #10)
> ... Can you clarify what the default behavior is when creating a *ToMany
> relationship and how the collection class default can be specified?  I, and I
> think most JPA developers, use List as their default so I'd want to be able to
> set this as my preference ...

"... The most common collection type used in associations is the standard Collection superinterface ..." 

Pro JPA 2 Mastering the Java™ Persistence API (Mike Keith and Merrick Schincariol)
------------------------------------------------------

So, I'm going to leave the default type to be Collection, but if you insist I'll change it to List
Comment 13 Stefan Dimov CLA 2011-04-14 11:10:03 EDT
    One more comment. According to the same book the most common usage for java.util.Map in ...ToMany relations is when the Map is being keyed by an attribute from the the opposite entity. Turns out that from these cases the most common is the one where the key attribute is the id of the (opposite) entity. This case is so common that when we use it we don't need the @MapKey annotation. 

    That's the case I've implemented in this patch.
Comment 14 Stefan Dimov CLA 2011-04-14 11:29:05 EDT
Appears, I've missed something here. The @MapKey is still required although the name (in it) is not necessary
Comment 15 Stefan Dimov CLA 2011-04-14 12:55:28 EDT
Fixed