Hi,
Im trying to fix one bug for couple days and I cant find in Internet any solution. So I decided to write here.
I will try to explain the issue:
So I have Class which is called Equipment:
Code:
public class Equipment{
private Integer _id;
private String _serialNo;
private Employee _owner;
private Status _status;
private Equipment _extension;
(..)
@ManyToOne(cascade = CascadeType.MERGE)
@JoinColumn(name = "status")
public Status getStatus() {
return _status;
}
public void setStatus(Status status) {
_status = status;
}
}
and the Class which is called Status
Code:
@Entity
@Table(name = "status")
public class Status {
private Integer _id;
private String _statusName;
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "id")
public Integer getId() {
return _id;
}
public void setId(Integer id) {
_id = id;
}
@Basic
@Column(name = "status_name")
public String getStatusName() {
return _statusName;
}
public void setStatusName(String statusName) {
_statusName = statusName;
}
}
Im trying to find every Equipment which statusName is "IN_STORE_HOUSE" so I wrote method in DAO:
Code:
@SuppressWarnings("unchecked")
public List<Equipment> findAllEquipmentsInStoreHouseByEmployee(
Employee employee) {
DetachedCriteria criteria = DetachedCriteria.forClass(Equipment.class);
criteria.setFetchMode("status", FetchMode.JOIN);
criteria.add(Property.forName("owner").eq(employee));
criteria.add(Property.forName("status.statusName").eq("IN_STORE_HOUSE"));
criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
return getHibernateTemplate().findByCriteria(criteria);
}
When I use this method I get an error:
Code:
org.springframework.orm.hibernate3.HibernateQueryException: could not resolve property: statusName of: com.nsn.equipment.model.Equipment; nested exception is org.hibernate.QueryException: could not resolve property: statusName of: com.nsn.equipment.model.Equipment
at org.springframework.orm.hibernate3.SessionFactoryUtils.convertHibernateAccessException(SessionFactoryUtils.java:647)
at org.springframework.orm.hibernate3.HibernateAccessor.convertHibernateAccessException(HibernateAccessor.java:413)
at org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:371)
at org.springframework.orm.hibernate3.HibernateTemplate.findByCriteria(HibernateTemplate.java:956)
at org.springframework.orm.hibernate3.HibernateTemplate.findByCriteria(HibernateTemplate.java:949)
at com.nsn.equipment.DAO.EquipmentDAO.findAllEquipmentsInStoreHouseByEmployee(EquipmentDAO.java:217)
My question is how can I get inside object like Status?
I know that I can walk around this:
Code:
DetachedCriteria criteria = DetachedCriteria.forClass(Status.class);
criteria.add(Property.forName("statusName").eq("IN_STORE_HOUSE"));
List<Status> statuses = getHibernateTemplate().findByCriteria(criteria);
and then
DetachedCriteria criteria = DetachedCriteria.forClass(Equipment.class);
(..)
criteria.add(Property.forName("status").eq(statuses.get(0)));
But its not my goal. And I have many issues because of this problem. And I need to make them by hand and filter lists in for loops... which i would like to avoid. I would be greatful for any help n tips.