I'd like to use @Embeddable annotation. So, it suggest to define as Application Identity. I created as the Data Nucleus Documentation. But it still error.
import java.util.List;
import javax.persistence.CascadeType;
import javax.persistence.Embeddable;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToMany;
@Entity
@Embeddable
public class Category{
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
private String id;
private String name;
@OneToMany(mappedBy="category",cascade=CascadeType.ALL)
private List<Product> products;
public List<Product> getProducts() {
return products;
}
public void setProdu开发者_高级运维cts(List<Product> products) {
this.products = products;
}
public Category() {
}
public Category(String id,String name){
this.id=id;
this.name=name;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
Error is
Errors were encountered when initialising the specified MetaData. See the nested exceptions for details SEVERE: Class entity.Category has been specified with 1 primary key fields, but this class is using nondurable identity and should be application identity.
Remove @Id (and @Entity too for that matter) since the class is being embedded.
精彩评论