Hibernate Search returns 字符串类型
Hibernate Search returns a string type
我在 table、pdfField
和 formField
中有两个不同的实体。如果我们输入 pdfField
.
,我想建立一个 return 是 formField
的搜索
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id")
private Integer id;
@Column(name = "pdf_field")
private String pdfField;
@Column(name = "form_field")
private String formField;
这是我创建的函数,但我不确定如何将字符串设为 return 类型。
public String getPdfFormFieldByPdfField(String PdfField) throws InterruptedException {
Session session = sessionFactory.openSession();
EntityManager entityManager = session.getEntityManagerFactory().createEntityManager();
FullTextEntityManager fullTextEntityManager = Search.getFullTextEntityManager(entityManager);
fullTextEntityManager.createIndexer().startAndWait();
QueryBuilder queryBuilder = fullTextEntityManager.getSearchFactory().buildQueryBuilder().forEntity(PdfMap.class).get();
org.apache.lucene.search.Query wildcardQuery = queryBuilder
.keyword()
.wildcard()
.onField("pdf_field") // name of the field in database
.matching(PdfField)
.createQuery();
String formField = ( how to get the result);
return formField;
}
我认为您切换到 Spring Data JPA 会更容易。使用它可以更轻松地实现您想要的目标:
public interface PdfMapRepository extends JpaRepository<PdfMap, Integer> {
@Query("select pm.pdfField from PdfMap pf where pf.id = :id")
Optional<String> findPdfFieldByPdfMapId(Integer id);
}
没有Spring数据,同样可以用
实现
TypedQuery<String> query = em.createQuery("select pm.pdfField from PdfMap pf where pf.id = :id", String.class);
List<String> results = query.getResultList();
或者您可以使用 Criteria API as
Session session = sessionFactory.openSession();
CriteriaQuery<Double> cr = cb.createQuery(String.class);
Root<PdfMap> root = cr.from(PdfMap.class);
cr.select(root.get("pdfField"));
Query<String> query = session.createQuery(cr);
List<String> formFields = query.getResultList();
我在 table、pdfField
和 formField
中有两个不同的实体。如果我们输入 pdfField
.
formField
的搜索
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id")
private Integer id;
@Column(name = "pdf_field")
private String pdfField;
@Column(name = "form_field")
private String formField;
这是我创建的函数,但我不确定如何将字符串设为 return 类型。
public String getPdfFormFieldByPdfField(String PdfField) throws InterruptedException {
Session session = sessionFactory.openSession();
EntityManager entityManager = session.getEntityManagerFactory().createEntityManager();
FullTextEntityManager fullTextEntityManager = Search.getFullTextEntityManager(entityManager);
fullTextEntityManager.createIndexer().startAndWait();
QueryBuilder queryBuilder = fullTextEntityManager.getSearchFactory().buildQueryBuilder().forEntity(PdfMap.class).get();
org.apache.lucene.search.Query wildcardQuery = queryBuilder
.keyword()
.wildcard()
.onField("pdf_field") // name of the field in database
.matching(PdfField)
.createQuery();
String formField = ( how to get the result);
return formField;
}
我认为您切换到 Spring Data JPA 会更容易。使用它可以更轻松地实现您想要的目标:
public interface PdfMapRepository extends JpaRepository<PdfMap, Integer> {
@Query("select pm.pdfField from PdfMap pf where pf.id = :id")
Optional<String> findPdfFieldByPdfMapId(Integer id);
}
没有Spring数据,同样可以用
实现TypedQuery<String> query = em.createQuery("select pm.pdfField from PdfMap pf where pf.id = :id", String.class);
List<String> results = query.getResultList();
或者您可以使用 Criteria API as
Session session = sessionFactory.openSession();
CriteriaQuery<Double> cr = cb.createQuery(String.class);
Root<PdfMap> root = cr.from(PdfMap.class);
cr.select(root.get("pdfField"));
Query<String> query = session.createQuery(cr);
List<String> formFields = query.getResultList();