我在EJB容器中構建了一個使用JPA的應用程序。 這裏是我的代碼JPA查詢語言標準構建器
@PersistenceContext(unitName = "damate-pu")
private EntityManager em;
@Override
public Workspace find(String username, String path) {
CriteriaBuilder criteriaBuilder = em.getCriteriaBuilder();
CriteriaQuery<Workspace> criteriaQuery = criteriaBuilder.createQuery(Workspace.class);
Root<Workspace> from = criteriaQuery.from(Workspace.class);
Predicate condition = criteriaBuilder.equal(from.get("Username"), username);
Predicate condition2 = criteriaBuilder.equal(from.get("Path"), path);
Predicate condition3 = criteriaBuilder.and(condition, condition2);
criteriaQuery.where(condition3);
Query query = em.createQuery(criteriaQuery);
return (Workspace) query.getSingleResult();
}
當我嘗試從一個Web服務,我得到以下錯誤此方法: java.lang.IllegalArgumentException: The attribute [Username] from the managed type....
可以採取什麼問題嗎?我覺得我有一個問題from.get("Username")
...
你覺得呢?以及如何解決它?
編輯:Workspace.java
package com.ubb.damate.model;
import java.io.Serializable;
import javax.persistence.*;
import java.util.Date;
import java.util.Set;
/**
* The persistent class for the workspace database table.
*
*/
@Entity
@Table(name="workspace")
public class Workspace implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
@Column(name="WorkspaceId", unique=true, nullable=false)
private int workspaceId;
@Temporal(TemporalType.DATE)
@Column(name="CreationDate", nullable=false)
private Date creationDate;
@Lob()
@Column(name="Path", nullable=false)
private String path;
@Column(name="Username", nullable=false, length=20)
private String username;
//bi-directional many-to-one association to Project
@OneToMany(mappedBy="workspace")
private Set<Project> projects;
public Workspace() {
}
public int getWorkspaceId() {
return this.workspaceId;
}
public void setWorkspaceId(int workspaceId) {
this.workspaceId = workspaceId;
}
public Date getCreationDate() {
return this.creationDate;
}
public void setCreationDate(Date creationDate) {
this.creationDate = creationDate;
}
public String getPath() {
return this.path;
}
public void setPath(String path) {
this.path = path;
}
public String getUsername() {
return this.username;
}
public void setUsername(String username) {
this.username = username;
}
public Set<Project> getProjects() {
return this.projects;
}
public void setProjects(Set<Project> projects) {
this.projects = projects;
}
}
我無法從WS獲取用戶名。爲什麼? – 2011-01-19 20:33:18