我是JSF技术的最新成员,我需要使用JSF和Hibernate。但我有一个与代码充分性相关的问题。如何使用jsf正确使用Hibernate映射?使用带有@ManagedBean
注释的hibernate注释会很好吗?
我有我的Field类需要插入到DB中。我在这里用@ Hibernate注释@ManagedBean和@SessionScoped注释。
@ManagedBean(name = "field")
@SessionScoped
@Entity
@Table(name = "field", catalog = "infostroy", uniqueConstraints = { @UniqueConstraint(columnNames = "label") })
public class Field {
@Id
@Column(name = "label", unique = true, nullable = false, length = 70)
private String label;
@Column(name = "type", nullable = false, length = 70)
private Type type;
@Column(name = "required", nullable = false)
private boolean required;
@Column(name = "isActive", nullable = false)
private boolean isActive;
public String getLabel() {
return label;
}
public void setLabel(String label) {
this.label = label;
}
public Type getType() {
return type;
}
public void setType(Type type) {
this.type = type;
}
public boolean isRequired() {
return required;
}
public void setRequired(boolean required) {
this.required = required;
}
public boolean isActive() {
return isActive;
}
public void setActive(boolean isActive) {
this.isActive = isActive;
}
}
在我的FieldManageBean课程中,我做了类似的事情
@ManagedBean(name = "fieldManageBean")
@RequestScoped
public class FieldManageBean {
@ManagedProperty("#{field}")
private Field field;
@ManagedProperty("#{fieldService}")
private FieldService fieldService;
public FieldService getFieldService() {
return fieldService;
}
public void setFieldService(FieldService fieldService) {
this.fieldService = fieldService;
}
public List<String> getFieldTypes() {
return Type.getStringListOfEnums();
}
}
使用Hibernate和JSF是一个很好的实践吗?或者我需要使用.xml映射我的实体?你能解释一下我的例子吗? 感谢名单