我有这个Bean可行。我想实现一个方法,以便从JSF搜索表单接收参数,执行搜索并返回结果。
所以,我的问题是: - 包装我的搜索参数的方法签名是什么? - 有没有办法配置Hibernate / JPA行为来生成一个SELECT,它返回所有适合我的搜索参数的注册表而不是我的实际行为(每行返回1个查询)?
import java.util.List;
import javax.ejb.Stateful;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.PersistenceContextType;
import javax.persistence.TypedQuery;
import my.package.entity.Address;
@Stateful
public class AddressEJB {
@PersistenceContext(unitName = "RentACar-persistence-unit",type=PersistenceContextType.EXTENDED)
private EntityManager entityManager;
public List<Address> findAll() {
TypedQuery<Address> query = entityManager.createNamedQuery(
"Address.findAll", Address.class);
return query.getResultList();
}
/*This is the method I want to write*/
public List<Address> findByParameter() {
TypedQuery<Address> query = entityManager.createNamedQuery(
"Address.findAll", Address.class);
return query.getResultList();
}
public Address addNew(Address address) {
entityManager.persist(address);
return address;
}
public Address update(Address address) {
entityManager.merge(address);
return address;
}
public void delete(Address country) {
entityManager.remove(country);
}
}