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.

Reply via email to