Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/file/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何更新命名查询中的多个表?_Java_Eclipselink - Fatal编程技术网

Java 如何更新命名查询中的多个表?

Java 如何更新命名查询中的多个表?,java,eclipselink,Java,Eclipselink,我正在使用Eclipselink v2.3.3 我得到了这个错误 Error compiling the query [Credential.updateExistingCredentialNoPW: UPDATE Credential c SET c.active = :active, c.employee.address.streetAddress = :stadd, c.employee.address.city = :city, c.employee.address.province =

我正在使用Eclipselink v2.3.3

我得到了这个错误

Error compiling the query [Credential.updateExistingCredentialNoPW: UPDATE Credential c SET c.active = :active, c.employee.address.streetAddress = :stadd, c.employee.address.city = :city, c.employee.address.province = :prov, c.employee.address.zip = :zip WHERE c.id = :id], line 1, column 46: invalid navigation expression [c.employee], cannot navigate association field [employee] in the SET clause target.
当我尝试运行代码时

以下是阻止运行我的代码的受影响的命名查询

@NamedQuery(name = "Credential.updateExistingCredentialNoPW",
query = "UPDATE Credential c "
+ "SET c.active = :active, "
+ "c.employee.address.streetAddress = :stadd, "
+ "c.employee.address.city = :city, "
+ "c.employee.address.province = :prov, "
+ "c.employee.address.zip = :zip "
+ "WHERE c.id = :id"),

@NamedQuery(name = "Credential.updateExistingCredential",
query = "UPDATE Credential c "
+ "SET c.password = :pw, "
+ "c.active = :active, "
+ "c.employee.address.streetAddress = :stadd, "
+ "c.employee.address.city = :city, "
+ "c.employee.address.province = :prov, "
+ "c.employee.address.zip = :zip "
+ "WHERE c.id = :id"),

@NamedQuery(name = "Credential.updateSalary",
query = "UPDATE Credential c "
+ "SET c.employee.salary.value = :val WHERE c.id = :id")
下面是我放置上面指定的所有命名查询的类

public class Credential implements Serializable {

private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(generator = "CRED_GEN", strategy = GenerationType.IDENTITY)
@Column(name = "CREDENTIAL_ID")
private long id;
// unique & not nullabe username
@Column(nullable = false, unique = true)
private String username;
@Column(nullable = false, name = "USER_KEY")
private String password;
@Column(nullable = false)
private boolean active;
@Column(nullable = false)
private int userLevel;
@OneToOne(cascade = CascadeType.PERSIST, fetch = FetchType.EAGER)
private Employee employee;

public Credential() {
}

public Credential(String username, String password, boolean active,
        int userLevel, Employee employee) throws NoSuchAlgorithmException {
    this.username = username;
    this.setPassword(password);
    this.active = active;
    this.userLevel = userLevel;
    this.employee = employee;
}

public long getId() {
    return id;
}

public void setId(long id) {
    this.id = id;
}

public int getUserLevel() {
    return userLevel;
}

public void setUserLevel(int userLevel) {
    this.userLevel = userLevel;
}

public boolean isActive() {
    return active;
}

public void setActive(boolean active) {
    this.active = active;
}

public Employee getEmployee() {
    return employee;
}

public void setEmployee(Employee employee) {
    this.employee = employee;
}

public String getPassword() {
    return password;
}

public void setPassword(String password) throws NoSuchAlgorithmException {
    this.password = Cryptography.getHash(password);
}

public String getUsername() {
    return username;
}

public void setUsername(String username) {
    this.username = username;
}

我做错了吗?

不可能用一个sql查询更新多个表

所以这在日食中也是不可能的


您必须将此表拆分为两个查询,或者最好使用setter。

不可能使用单个sql查询更新多个表

所以这在日食中也是不可能的


您必须将此it查询拆分为两个查询,或者最好使用setter。

您不能。使用SQL查询或使用Java代码:

Credential c = em.find(Credential.class, credentialId);
c.setActive(active);
c.getEmployee().getAddress().setStreet(street);
...

你不能。使用SQL查询或使用Java代码:

Credential c = em.find(Credential.class, credentialId);
c.setActive(active);
c.getEmployee().getAddress().setStreet(street);
...

谢谢你的回复和链接。我在网上搜索了一个小时左右,找到了答案。谢谢你的回复和链接。我在网上搜索了一个小时左右,寻找答案。