2 Replies Latest reply on Mar 14, 2013 2:55 PM by Cdelahun-Oracle

    @ManyToOne with Composite Id with AUTO increment

      Hi ,

      Below is scenario where i am facing issue. Please let me know your suggestions.

      Tables :
      OriginalWork - original_work_id, other columns

      Subwork - original_work_id, seq_number, other columns
      primary key (original_work_id, seq_number) -- composite key

      original_work_id in subwork needs to populated from original_work_id in OriginalWork

      seq_number must be incremented by 1 automatically.

      OriginalWork can have many Subwork
      (one to many)

      Configurations in subwork :

      @JoinColumn(name=" original_work_id ")
      private Originalwork originalwork;

      @GeneratedValue(strategy = GenerationType.AUTO)
      private long seq_number;

      I tried using embeddedId , but did not work.

      The above configuration is not working and exception is java.sql.SQLSyntaxErrorException: ORA-02289: sequence does not exist

      This is not thing do with the privileges as I am able to access the sequence.

      Please clarify.

        • 1. Re: @ManyToOne with Composite Id with AUTO increment
          Any update on this guys?
          • 2. Re: @ManyToOne with Composite Id with AUTO increment
            I think you might be jumping ahead here, as the exception states there is a problem with sequencing - not the ManyToOne relationship. First step would be to find out which entity has the issue with sequencing - is it OriginalWork or SubWork. You might try a simple test where both have a simple pk using sequencing. I don't think it is the Subwork entity, as per http://wiki.eclipse.org/EclipseLink/Examples/JPA/PrimaryKey generation mode auto should default to Table sequencing in EclipseLink - the error would be different.

            Looking at the model, this should work as long as Subwork has either an embeddedId class or a PK class defined. Best bet since you are using a relationship mapping in the composite PK is to use a PK class with a long seq_number; and long originalwork; assuming OriginalWork's id is of type long as well.

            Best Regards,