I'm newest in JSF technology, I need to use JSF and Hibernate. But I have got a question that connected with adequacy of code. How correctly use Hibernate mapping with jsf? Would be good to use hibernate annotations with @ManagedBean
annotation together?
I have got my Field class that needed to be inserted to DB. And I puted here @ManagedBean and @SessionScoped annotations with Hibernate annotations.
@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;
}
}
And in my FieldManageBean class I'm doing something like this
@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();
}
}
Is it a good practicies of using Hibernate with JSF, or not? Or I need to map my entities using .xml? Could you explain me or give some examples of it. Thanx