Tuesday, March 25, 2008

Secondary Table not working in EJB

Had a customer and an embedded address. It would not use the EMBEDDED_ADDRESS table, instead it created a column called street in the customer table and used that.


@Entity
@Table(name = "CUSTOMER")
@SecondaryTable(name = "EMBEDDED_ADDRESS", pkJoinColumns = {@PrimaryKeyJoinColumn(name = "addressId")})
public class CustomerBean {

@Id @GeneratedValue(strategy=GenerationType.AUTO)
private int id;
private String name;
private String street;

public CustomerBean(){}

public int getId() {
return id;
}

public void setId(int id) {
this.id = id;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

@Column(name = "street", table = "EMBEDDED_ADDRESS")
public String getStreet()
{
return street;
}

public void setStreet(String street) {
this.street = street;
}



}

No comments: