users@glassfish.java.net

RE: No ID column

From: Kenneth Clark <kenneth_at_rabiddog.co.za>
Date: Tue, 12 Jun 2007 20:48:11 +0200

Thanks very much for the feedback. I am in the process of fixing this and
will give everyone's suggestions a good look through.

 

Again thanks very much guys, you all rock!

 

Kenneth Clark
System Architect / Lead Developer

Rabid Dog Laboratories T
Putting the art back into development

tel: +27 11 475 7409
mobile: +27 82 500 5090
e-mail: kenneth_at_rabiddog.co.za
website: http://www.rabiddog.co.za/

  _____

From: Markus.Fuchs_at_Sun.COM [mailto:Markus.Fuchs_at_Sun.COM]
Sent: 12 June 2007 20:34
To: users_at_glassfish.dev.java.net
Subject: Re: No ID column

 

Hi Kenneth,

1) If your join table, say "CUSTOMERCOMPANYTYPE", has attributes besides
the join columns, you must map it as a separate Entity. Something like

In CompanyType:
@OneToMany

  private Collection<CustomerCompanyType> customerCompanyTypes;

 
In Customer:



  @OneToMany

  private Collection<CustomerCompanyType> customerCompanyTypes;

In CustomerCompanyType:
  @IDClass(name="CustomerCompanyTypeId")
  @Id private int customerId;
  @Id private int companyTypeId;

  @ManyToOne

  @JoinColumn(name = "customer_id", referencedColumnName = "id")

  private Customer customer;

 



  @ManyToOne

  @JoinColumn(name = "company_type_id", referencedColumnName = "id")

  private CompanyType companyType;

public class CustomerCompanyTypeId {
public int customerId;
public int companyTypeId;
}
 
2) If your join table just has the join columns, you should use the
@ManyToMany annotation:

In CompanyType:
  @ManyToMany(mappedBy="companyTypes")

  private Collection<Customer> customers;

 
In Customer:



  @ManyToMany

  @JoinTable(
  name="CUSTOMERCOMPANYTYPE",
   joinColumns=
   @JoinColumn(name="CUSTOMER_ID", referencedColumnName="ID"),
   inverseJoinColumns=
  @JoinColumn(name="COMPANY_TYPE_ID", referencedColumnName="ID")
  )

 private Collection<CompanyType> companyTypes;

-- markus.

Kenneth Clark wrote:

Sorry just to follow up, the verifier returns this message

 

Exception Description: Entity class [class xxx] has no primary key
specified. It should define either an @Id, @EmbeddedId or an @IdClass.

 

Below are the fields

  @ManyToOne

  @JoinColumn(name = "customer_id", referencedColumnName = "id")

  private Customer customer;

 

  @ManyToOne

  @JoinColumn(name = "company_type_id", referencedColumnName = "id")

  private CompanyType companyType;

 

Does anyone have any input or direction? Am I going to have to create a
primary key for this table. I cannot see the point of the primary key other
than to circumvent this error

 

Kenneth Clark
System Architect / Lead Developer

Rabid Dog Laboratories T
Putting the art back into development

tel: +27 11 475 7409
mobile: +27 82 500 5090
e-mail: kenneth_at_rabiddog.co.za
website: http://www.rabiddog.co.za/

  _____

From: Kenneth Clark [mailto:kenneth_at_rabiddog.co.za]
Sent: 12 June 2007 19:23
To: users_at_glassfish.dev.java.net
Subject: No ID column

 

I have a many to many table that designates the relationships between two
entities and I get the following error:

It should define either an @Id, @EmbeddedId or an @IdClass.
javax.persistence.PersistenceException: Exception [TOPLINK-28018] (Oracle
TopLink Essentials - 2.0 (Build b41d-beta2 (04/24/2007))):

 

The table contains no primary keys as it doesn't require any.

 

Anyone have any ideas?

 

Kenneth Clark
System Architect / Lead Developer

Rabid Dog Laboratories T
Putting the art back into development

tel: +27 11 475 7409
mobile: +27 82 500 5090
e-mail: kenneth_at_rabiddog.co.za
website: http://www.rabiddog.co.za/

 

--------------------------------------------------------------------- To
unsubscribe, e-mail: users-unsubscribe_at_glassfish.dev.java.net For additional
commands, e-mail: users-help_at_glassfish.dev.java.net