OpenJPA
  1. OpenJPA
  2. OPENJPA-469

Generic (user, custom) GeneratedValue

    Details

    • Type: New Feature New Feature
    • Status: Closed
    • Priority: Critical Critical
    • Resolution: Duplicate
    • Affects Version/s: 1.1.0
    • Fix Version/s: 1.1.0
    • Component/s: jdbc, kernel
    • Labels:
      None
    • 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.

      Description

      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; }

        Issue Links

          Activity

          Hide
          Patrick Linskey added a comment -

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

          Show
          Patrick Linskey added a comment - Choosing OPENJPA-470 as the non-duplicate as it contains the workaround info.

            People

            • Assignee:
              Unassigned
              Reporter:
              Miroslav Nachev
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Development