我有两个类的多对一映射(代码减少):
类别:
@Entity
public class Category {
@Id
@Column(name = "CATEGORY_ID")
Long id;
@NotNull
String name;
子类别:
@Entity
public class Subcategory {
@Id
@Column(name = "SUBCATEGORY_ID")
Long id;
@NotNull
@ManyToOne(targetEntity = Category.class)
@JoinColumn(name = "CATEGORY_ID")
Long categoryId;
@NotNull
String name;
当我尝试将子类别添加到现有类别时,我得到
ERROR [org.jboss.ejb3.invocation] JBAS014134: EJB Invocation failed on component SubcategoryController for method public void %package%.SubcategoryController.add(%package%.Subcategory): javax.ejb.EJBException: javax.persistence.PersistenceException: org.hibernate.PropertyAccessException: could not get a field value by reflection getter of %package%.Category.id
...
at %package%.SubcategoryController$$$view1.add(Unknown Source)
...
at %package%.SubcategoryController$Proxy$_$$_Weld$Proxy$.add(SubcategoryController$Proxy$_$$_Weld$Proxy$.java)
at %package%.SubcategoryService.add(SubcategoryService.java:30)
at %package%.SubcategoryService$Proxy$_$$_WeldClientProxy.add(SubcategoryService$Proxy$_$$_WeldClientProxy.java)
...
Caused by: javax.persistence.PersistenceException: org.hibernate.PropertyAccessException: could not get a field value by reflection getter of %package%.Category.id
我应该怎么做才能避免这个错误?