0
我是Java EE的初學者,我試圖創建一個在數據庫中保留用戶實體的應用程序。我有以下代碼:無法在數據庫中堅持實體Java EE
用戶實體
@Entity
public class User implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
private int id;
private String department;
@Email
private String email;
@Column(name="`first name`")
private String firstName;
@Column(name="`last name`")
private String lastName;
private String password;
//bi-directional many-to-one association to Unit
@OneToMany(mappedBy="user")
private Set<Unit> units;
public User() {
}
public int getId() {
return this.id;
}
public void setId(int id) {
this.id = id;
}
public String getDepartment() {
return this.department;
}
public void setDepartment(String department) {
this.department = department;
}
public String getEmail() {
return this.email;
}
public void setEmail(String email) {
this.email = email;
}
public String getFirstName() {
return this.firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getlastNameame() {
return this.lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public String getPassword() {
return this.password;
}
public void setPassword(String password) {
this.password = password;
}
public Set<Unit> getUnits() {
return this.units;
}
public void setUnits(Set<Unit> units) {
this.units = units;
}
}
用戶無狀態會話bean
@Stateless
public class userEJB {
@PersistenceContext
private EntityManager em;
/**
* Default constructor.
*/
public userEJB() {
// TODO Auto-generated constructor stub
}
public void createUser(User user)
{
em.persist(user);
}
}
用戶託管Bean(僅create方法來實現)
public class UserMBean {
@EJB
userEJB userSessionBean;
private User user;
public UserMBean() {
this.user = new User();
}
public void save()
{
userSessionBean.createUser(user);
}
}
signUp.xhtml
<h:form>
<h:panelGrid columns = "2">
<h:outputLabel for="firstName" value="First Name"/>
<h:inputText id="firstName" value="#{userMBean.user.firstName}" required = "true"/>
<h:outputLabel for="lastName" value="Last Name"/>
<h:inputText id="lastName" value="#{userMBean.user.lastName}" required = "true" />
<h:outputLabel for="department" value="Department"/>
<h:inputText id="department" value="#{userMBean.user.department}" required = "true"/>
<h:outputLabel for ="email" value="Email"/>
<h:inputText id="email" value="#{userMBean.user.email}" required = "true"/>
<h:outputLabel for="password" value="Password"/>
<h:inputText id="password" value="#{userMBean.user.password}" required = "true"/>
</h:panelGrid>
<h:commandButton action="#{userMBean.save}" value="Submit" />
</h:form>
雖然from正在正確顯示,但單擊Submit按鈕時沒有提供任何內容。沒有服務器錯誤。它只是沒有信號。如果我在代碼中有任何錯誤,你能幫我嗎?
謝謝
使用調試器瞭解當您單擊該按鈕時發生了什麼。或者至少添加日誌語句來查看執行的內容。 –
您的託管bean是否被識別?你使用JSF或CDI的註釋嗎? –