How to use the @TableGenerator annotation for a non-PK id

Neilio

New Member
This is an extract of the JPA entities schema\[code\] @Entity @Table(name="customer") public class Customer implements Serializable { @Id @GeneratedValue(strategy = GenerationType.AUTO) @Column(name="customer_id") private Long id; @ManyToOne @JoinColumn(name="company_id",nullable=false) private Company company; //... } @Entity @Table(name="company") public class Company implements Serializable { @Id @GeneratedValue(strategy = GenerationType.AUTO) @Column(name="company_id") private Long id; //... } @Entity @Table(name="order_header") public class OrderHeader implements Serializable { @Id @GeneratedValue(strategy = GenerationType.AUTO) @Column(name="order_id") private Long id; @ManyToOne @JoinColumn(name="customer_id",nullable=false) private Customer customer; private Long internalCompanyOrderId; //... }\[/code\]I need to retreive an unique internalCompanyOrderId sequence for each Company_id. It means that nevertheless the Order PK will be 'order_id', I need an "internal" order_id for each Company.
 
Top