This discussion is archived
2 Replies Latest reply: Mar 14, 2013 7:55 AM by cdelahun RSS

@ManyToOne with Composite Id with AUTO increment

800839 Newbie
Currently Being Moderated
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
and

seq_number must be incremented by 1 automatically.

OriginalWork can have many Subwork
(one to many)

Configurations in subwork :

@Id
@ManyToOne(fetch=FetchType.LAZY)
@JoinColumn(name=" original_work_id ")
private Originalwork originalwork;

@Id
@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.

Thanks.
  • 1. Re: @ManyToOne with Composite Id with AUTO increment
    800839 Newbie
    Currently Being Moderated
    Any update on this guys?
  • 2. Re: @ManyToOne with Composite Id with AUTO increment
    cdelahun Pro
    Currently Being Moderated
    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,
    Chris

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points