2016-02-27 48 views
0

我使用了复合键,但我改变了主意,并在NetBeans的Web应用程序中删除了这种键。但Glassfish说:由于无效的JoinColumns内容,模块尚未部署。Glassfish说不完整JoinColumns

Exception Description: The @JoinColumns on the annotated element [field client] from the entity class [class x.ClientOrder] is incomplete. When the source entity class uses a composite primary key, a @JoinColumn must be specified for each join column using the @JoinColumns. Both the name and the referencedColumnName elements must be specified in each such @JoinColumn. 

我已经删除了所有从数据库中的表中,重新启动容器,被称为“清理并生成”命令添加到项目(这是成功的)。但是EJB部署失败。我应该怎样为容器忘记过去?

实体的源代码:

@Entity 
@Getter 
@Setter 
@Inheritance(strategy = InheritanceType.JOINED) 
@DiscriminatorColumn(name = "roleType", discriminatorType = DiscriminatorType.STRING, length = 10) 
@NamedQuery(name=UserRole.QUERYNAME_GET_ROLE_BY_USERID_AND_TYPE, query = "SELECT ur FROM UserRole ur WHERE ur.userWR.id = :userID AND ur.roleType = :roleType") 
abstract public class UserRole implements Serializable 
{ 
    private static final long serialVersionUID = 1L; 
    public static final String QUERYNAME_GET_ROLE_BY_USERID_AND_TYPE = "userRole_getRoleByUserIDAndType"; 

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

    @Column 
    private String roleType; 

    @Id 
    @ManyToOne 
    @JoinColumn(name="user_id", referencedColumnName = "id") 
    private UserWithRoles userWR; 

} 


@Entity 
@Data 
@NamedQuery(name = Client.QUERYNAME_GET_ALL_CLIENTS, query="SELECT c FROM Client c") 
public abstract class Client extends UserRole 
{ 
    public static final String QUERYNAME_GET_ALL_CLIENTS = "client_GetAllClients"; 

} 


@Entity 
@Data 
@NamedQuery(name=ClientOrder.QUERYNAME_GET_CLIENT_ORDERS, query = "SELECT co FROM ClientOrder co WHERE co.client = :userID") 
public class ClientOrder implements Serializable 
{ 
    private static final long serialVersionUID = 1L; 
    public static final String QUERYNAME_GET_CLIENT_ORDERS = "clientOrders_getClientOrders"; 

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

    private String name; 

    @ManyToOne 
    @JoinColumn(name = "client_id", referencedColumnName = "id") 
    private Client client; 

    @OneToMany(mappedBy = "clientOrder") 
    private List<ClientOrderItem> orderItems; 

} 

回答

0

确定。 UserRole表中存在错误。我忘记了删除userWR字段中的第二个@Id注释。在我删除它并重建应用后,它再次部署。