When I am reading the book "Beginning EJB3 Application Development", I write an entity to taste the composite primary key.
package com.mellon.jpa;
@Entity
public class MEnergy implements Serializable {
@Id
private
String year;
@Id
private String month;
private double energy;
public MEnergy(){}
public MEnergy(String year, String month, double value){
this.year = year;
this.month = month;
this.energy = value;
}
@Override
public boolean equals(Object obj) {... }
@Override
public int hashCode() {... }
}
As the above, I did not offer a composite key class and just annotated the year and month field with @Id, but that works. A table named MEnergy was created:
NAME TYPE Nullable
YEARVARCHAR2(255)N
MONTHVARCHAR2(255)N
ENERGYNUMBER(19,4)Y
and the YEAR,MONTH are defined as composited key.
I supposed my code doesn't finished yet and doesn't conform to the specification, can anybody help me to figure it out?
SCJP,SCWCD1.3,SCWCD1.4,SCJD,SCBCD5,SCEA5