我使用了复合键,但我改变了主意,在NetBeans中的Web应用程序中删除了这种键。但是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 :(得分:0)
行。 UserRole表中存在错误。我忘了删除userWR字段上的第二个@Id注释。在我删除它并重建应用程序后,它再次部署。