Glassfish 说不完整的 JoinColumns
Glassfish says incomplete JoinColumns
我使用了组合键,但我改变了主意并在 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.
我已经从数据库中删除了所有表,重新启动了容器,对项目调用了"Clean and Build"命令(它成功了)。但是 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;
}
好的。 UserRole table 中有错误。我忘记删除 userWR 字段上的第二个 @Id 注释。在我删除它并重建它再次部署的应用程序之后。
我使用了组合键,但我改变了主意并在 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.
我已经从数据库中删除了所有表,重新启动了容器,对项目调用了"Clean and Build"命令(它成功了)。但是 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;
}
好的。 UserRole table 中有错误。我忘记删除 userWR 字段上的第二个 @Id 注释。在我删除它并重建它再次部署的应用程序之后。