Tag: metamodel

使用Criteria API创建查询(JPA 2.0)

我正在尝试使用JPA 2.0中的Criteria API创建查询,但我无法使其工作。 问题在于“之间”条件方法。 我读了一些文档 ,知道我该怎么做,但是因为我发现了JPA,所以我不明白为什么它不起作用。 首先,当我写“Transaction_”时,我看不到应该出现的“creationDate”。 我认为这可能是正常的,因为我读过元模型是在运行时生成的,所以我尝试使用’Foo_.getDeclaredSingularAttribute(“value”)’而不是’Foo_.value’,但它仍然无法正常工作。 这是我的代码: public List getTransactions(Date startDate, Date endDate) { EntityManager em = getEntityManager(); try { CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery cq = cb.createQuery(Transaction.class); Metamodel m = em.getMetamodel(); EntityType Transaction_ = m.entity(Transaction.class); Root transaction = cq.from(Transaction.class); // Error here. cannot find symbol. symbol: variable creationDate cq.where(cb.between(transaction.get(Transaction_.creationDate), startDate, endDate)); // […]

JPA / Metamodel:Sun Docs中的奇怪(不一致?)示例

在Sun Online资源中 ,他们提供了关于Criteria / Metamodel API使用的儿子示例,但据我了解Java,似乎无法工作: CriteriaQuery cq = cb.createQuery(Pet.class); Metamodel m = em.getMetamodel(); EntityType Pet_ = m.entity(Pet.class); EntityType Owner_ = m.entity(Owner.class); Root pet = cq.from(Pet.class); Join address = cq.join(**Pet_.owners**).join(**Owner_.addresses**); Pet_是EntityType类的实例 ,它不定义任何名为owners或addresses属性。 他们确实为元模型定义了名为Pet_和Owner_类,但是在这里输入它们会与变量名称产生冲突……我是对的吗? __ (这个问题也与这个问题有关)

使用maven生成Hibernate元模型时出现IllegalStateException

我正在使用hibernate-jpamodelgen来使用maven生成元模型类。 当我运行mvn clean包时 ,它没有任何问题。 但是如果我第二次运行mvn包 (没有干净),我会得到以下exception: An exception has occurred in the compiler (1.8.0_51). Please file a bug at the Java Developer Connection (http://java.sun.com/webapps/bugreport) after checking the Bug Parade for duplicates. Include your program and the following diagnostic in your report. Thank you. java.lang.IllegalStateException: endPosTable already set at com.sun.tools.javac.util.DiagnosticSource.setEndPosTable(DiagnosticSource.java:136) at com.sun.tools.javac.util.Log.setEndPosTable(Log.java:350) at com.sun.tools.javac.main.JavaCompiler.parse(JavaCompiler.java:667) at com.sun.tools.javac.main.JavaCompiler.parseFiles(JavaCompiler.java:950) […]