You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@openjpa.apache.org by "Miroslav Nachev (JIRA)" <ji...@apache.org> on 2007/12/19 08:01:43 UTC

[jira] Created: (OPENJPA-469) Generic (user, custom) GeneratedValue

Generic (user, custom) GeneratedValue
-------------------------------------

                 Key: OPENJPA-469
                 URL: https://issues.apache.org/jira/browse/OPENJPA-469
             Project: OpenJPA
          Issue Type: New Feature
          Components: jdbc, kernel
    Affects Versions: 1.1.0
         Environment: The database is MySQL which in principle doesn't support sequences. JDK 1.5 is used as and JDK6. For the test case JDK1.5.
            Reporter: Miroslav Nachev
            Priority: Critical
             Fix For: 1.1.0


I am trying to create a Custom (generic, user) Sequence Generator following the instructions from Patrick Linskey:
    @Id
    @Column(name = "Data_Object_Id", nullable = false)
    @SequenceGenerator(name="DataObjectsSeq", sequenceName="test.DataObjectsGenerator")
    @GeneratedValue(strategy=GenerationType.SEQUENCE, generator="DataObjectsSeq")
    private BigDecimal dataObjectId;

Unfortunately this doesn't works in my case maybe because I am using database which in principle doesn't support sequences or another reason. I dig up the code and see that there is incorrectly logic in class ImplHelper.java:
    private static Object generateValue(StoreContext ctx, ClassMetaData meta, FieldMetaData fmd, int typeCode)\
    {
        ...
        switch (strategy)
        {
             case ValueStrategies.SEQUENCE:
                ...
                return JavaTypes.convert(seq.next(ctx, meta), typeCode);
                break;
             case ValueStrategies.UUID_STRING:
                return UUIDGenerator.nextString();
             case ValueStrategies.UUID_HEX:
                return UUIDGenerator.nextHex();
             default:
                return null;
        }
    }

In my opinion the problem is that when I am creating a custom sequence, in switch statement this custom sequence is treat as native database sequence. This is a general problem. The correct behavior in this sequence to be treat as custom sequences as UUID_STRING and UUID_HEX. To be fixed that problem I will create a new enumeration which will be named CUSTOM or GENERIC or another name. Then I will do the relevant changes in the code. Then in the switch statement will be with one more case as follow:
        switch (strategy)
        {
             case ValueStrategies.SEQUENCE:
                 ...
                 break;
             case ValueStrategies.UUID_STRING:
                 ...
                 break;
             case ValueStrategies.UUID_HEX:
                 ...
                 break;
             case ValueStrategies.CUSTOM:
                 return JavaTypes.convert(seq.next(ctx, meta), typeCode);
             default:
                 ...
                 break;
        }

 

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Resolved: (OPENJPA-469) Generic (user, custom) GeneratedValue

Posted by "Patrick Linskey (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/OPENJPA-469?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Patrick Linskey resolved OPENJPA-469.
-------------------------------------

    Resolution: Duplicate

> Generic (user, custom) GeneratedValue
> -------------------------------------
>
>                 Key: OPENJPA-469
>                 URL: https://issues.apache.org/jira/browse/OPENJPA-469
>             Project: OpenJPA
>          Issue Type: New Feature
>          Components: jdbc, kernel
>    Affects Versions: 1.1.0
>         Environment: The database is MySQL which in principle doesn't support sequences. JDK 1.5 is used as and JDK6. For the test case JDK1.5.
>            Reporter: Miroslav Nachev
>            Priority: Critical
>             Fix For: 1.1.0
>
>
> I am trying to create a Custom (generic, user) Sequence Generator following the instructions from Patrick Linskey:
>     @Id
>     @Column(name = "Data_Object_Id", nullable = false)
>     @SequenceGenerator(name="DataObjectsSeq", sequenceName="test.DataObjectsGenerator")
>     @GeneratedValue(strategy=GenerationType.SEQUENCE, generator="DataObjectsSeq")
>     private BigDecimal dataObjectId;
> Unfortunately this doesn't works in my case maybe because I am using database which in principle doesn't support sequences or another reason. I dig up the code and see that there is incorrectly logic in class ImplHelper.java:
>     private static Object generateValue(StoreContext ctx, ClassMetaData meta, FieldMetaData fmd, int typeCode)\
>     {
>         ...
>         switch (strategy)
>         {
>              case ValueStrategies.SEQUENCE:
>                 ...
>                 return JavaTypes.convert(seq.next(ctx, meta), typeCode);
>                 break;
>              case ValueStrategies.UUID_STRING:
>                 return UUIDGenerator.nextString();
>              case ValueStrategies.UUID_HEX:
>                 return UUIDGenerator.nextHex();
>              default:
>                 return null;
>         }
>     }
> In my opinion the problem is that when I am creating a custom sequence, in switch statement this custom sequence is treat as native database sequence. This is a general problem. The correct behavior in this sequence to be treat as custom sequences as UUID_STRING and UUID_HEX. To be fixed that problem I will create a new enumeration which will be named CUSTOM or GENERIC or another name. Then I will do the relevant changes in the code. Then in the switch statement will be with one more case as follow:
>         switch (strategy)
>         {
>              case ValueStrategies.SEQUENCE:
>                  ...
>                  break;
>              case ValueStrategies.UUID_STRING:
>                  ...
>                  break;
>              case ValueStrategies.UUID_HEX:
>                  ...
>                  break;
>              case ValueStrategies.CUSTOM:
>                  return JavaTypes.convert(seq.next(ctx, meta), typeCode);
>              default:
>                  ...
>                  break;
>         }
>  

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (OPENJPA-469) Generic (user, custom) GeneratedValue

Posted by "Patrick Linskey (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/OPENJPA-469?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12554128 ] 

Patrick Linskey commented on OPENJPA-469:
-----------------------------------------

Choosing OPENJPA-470 as the non-duplicate as it contains the workaround info.

> Generic (user, custom) GeneratedValue
> -------------------------------------
>
>                 Key: OPENJPA-469
>                 URL: https://issues.apache.org/jira/browse/OPENJPA-469
>             Project: OpenJPA
>          Issue Type: New Feature
>          Components: jdbc, kernel
>    Affects Versions: 1.1.0
>         Environment: The database is MySQL which in principle doesn't support sequences. JDK 1.5 is used as and JDK6. For the test case JDK1.5.
>            Reporter: Miroslav Nachev
>            Priority: Critical
>             Fix For: 1.1.0
>
>
> I am trying to create a Custom (generic, user) Sequence Generator following the instructions from Patrick Linskey:
>     @Id
>     @Column(name = "Data_Object_Id", nullable = false)
>     @SequenceGenerator(name="DataObjectsSeq", sequenceName="test.DataObjectsGenerator")
>     @GeneratedValue(strategy=GenerationType.SEQUENCE, generator="DataObjectsSeq")
>     private BigDecimal dataObjectId;
> Unfortunately this doesn't works in my case maybe because I am using database which in principle doesn't support sequences or another reason. I dig up the code and see that there is incorrectly logic in class ImplHelper.java:
>     private static Object generateValue(StoreContext ctx, ClassMetaData meta, FieldMetaData fmd, int typeCode)\
>     {
>         ...
>         switch (strategy)
>         {
>              case ValueStrategies.SEQUENCE:
>                 ...
>                 return JavaTypes.convert(seq.next(ctx, meta), typeCode);
>                 break;
>              case ValueStrategies.UUID_STRING:
>                 return UUIDGenerator.nextString();
>              case ValueStrategies.UUID_HEX:
>                 return UUIDGenerator.nextHex();
>              default:
>                 return null;
>         }
>     }
> In my opinion the problem is that when I am creating a custom sequence, in switch statement this custom sequence is treat as native database sequence. This is a general problem. The correct behavior in this sequence to be treat as custom sequences as UUID_STRING and UUID_HEX. To be fixed that problem I will create a new enumeration which will be named CUSTOM or GENERIC or another name. Then I will do the relevant changes in the code. Then in the switch statement will be with one more case as follow:
>         switch (strategy)
>         {
>              case ValueStrategies.SEQUENCE:
>                  ...
>                  break;
>              case ValueStrategies.UUID_STRING:
>                  ...
>                  break;
>              case ValueStrategies.UUID_HEX:
>                  ...
>                  break;
>              case ValueStrategies.CUSTOM:
>                  return JavaTypes.convert(seq.next(ctx, meta), typeCode);
>              default:
>                  ...
>                  break;
>         }
>  

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.