[forge-dev] @GeneratedValue Strategy

George Gastaldi gegastaldi at gmail.com
Fri May 4 10:48:29 EDT 2012


Now I get it. :)

I always believed that this behavior is related to the supported
features on the database you use.

For example, if you use an Oracle DB, you can have a sequence for each
table, but that might mean having to place a @SequenceGenerator on
each entity.

It would be nice to have this feature when creating the JPA entity.
You may want to provide another option in method
org.jboss.forge.spec.javaee.jpa.EntityPlugin.newEntity(String, String)

Hope that helps,

George Gastaldi

2012/5/4 Ryan Bradley <rbradley at redhat.com>:
> Okay, so say we have two different entities in our scaffolded webapp,
> Customer and Account.  Under the current GenerationStrategy:
>
> I create a Customer object, and that will have an ID of 1.
>
> I create an Account object, and that will have an ID of 2, even though
> it is the first (and only) Account in the database.
>
> Using GenerationStrategy.IDENTITY, both objects will have identities of
> 1, i.e. there are separate sets of IDs kept for each table in the
> database.  One useful case that I can think of is that, in the Spring
> scaffold implementation, individual objects can be navigated to in the
> URL using their ID (e.g. /customers/1 would go to the Customer object in
> the database with an ID of 1).  Therefore, it might cause confusion if a
> user was trying to navigate using the URL but not necessarily knowing
> the ID of the object they are looking for (even if they know its ID
> relative to other objects of the same type).
>
> Does that clarify things?
>
> Cheers,
> Ryan
>
> On 05/04/2012 10:19 AM, George Gastaldi wrote:
>>> Thinking of scaffold implementations, it might be best if a separate set
>>> of IDs was generated for each separate entity.
>> I don´t think I get it. Can you give a practical example ?
>>
>> Regards,
>>
>> George Gastaldi
>>
>> 2012/5/4 Ryan Bradley<rbradley at redhat.com>:
>>> Greetings all,
>>>
>>> Currently, the entity plugin annotates the ID primary key with
>>> @GeneratedValue.  This annotation uses the default generation strategy,
>>> GenerationType.AUTO, to generate the values for this key.  Using this
>>> strategy, the same set of values is used for all entity tables.  In
>>> other words, you cannot have two entities with the same value for ID, as
>>> it is incremented with each entity creation rather than with each
>>> creation of an entity of a specific type.
>>>
>>> Thinking of scaffold implementations, it might be best if a separate set
>>> of IDs was generated for each separate entity.  I believe that this can
>>> be accomplished by annotating the field with
>>> @GeneratedValue(strategy=GenerationType.IDENTITY).  I was thinking of
>>> modifying the ScaffoldPlugin to change the GenerationType on this
>>> annotation in the generateFromEntity method (from-entity command).
>>>
>>> Any objections to this change?
>>>
>>> Cheers,
>>> Ryan
>>> _______________________________________________
>>> forge-dev mailing list
>>> forge-dev at lists.jboss.org
>>> https://lists.jboss.org/mailman/listinfo/forge-dev
>> _______________________________________________
>> forge-dev mailing list
>> forge-dev at lists.jboss.org
>> https://lists.jboss.org/mailman/listinfo/forge-dev
> _______________________________________________
> forge-dev mailing list
> forge-dev at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/forge-dev



More information about the forge-dev mailing list