English 中文(简体)
通过JPA/Hibernate的工厂创建分类的电梯
原标题:Create typed query through the session factory in JPA/Hibernate

我通常想做这样的事情:

CriteriaBuilder qb = em.getCriteriaBuilder();
CriteriaQuery<Person> c = qb.createQuery(Person.class);

但是,通过会议工厂而不是实体经理。

类似:

final TypedQuery<MyType> query = getSessionFactory().getCurrentSession().createTypedQuery(MyType.class, "query");

它应当是三边的,但出于某种原因,我无法找到如何做到这一点(如果它完全有可能,但我认为应该这样做)。

感谢

最佳回答

我不相信在自由会议上有这样的方法。 为什么不使用实体管理? 它是JPA的一部分,因此是Java EE标准?

如果你使用春天(我个人没有选择)的话,你可以使用HibernateTemplate,隐藏在你身上,并提供类型安全的方法。

这一切总是会发生。

问题回答

不可能这样做,因为届会没有采用任何回收 j的方法。 持久性。 类型。 兹特。 执行 j。 持久性。 台风本来会非常令人惊讶,因为它们是不同的信条(Hibernate内部不同受众的一部分)。 就在安全一侧,我也从来文方那里检查。





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签