栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

为什么编译器无法识别元模型属性?

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

为什么编译器无法识别元模型属性?

关于您的代码

我没有检查条件查询本身的正确性,但是,正如克里斯所提到的,您正在将静态元模型类与

EntityType
不会暴露您所要查找的混合在一起。假设已经生成了元模型类,请删除第一行并导入生成的
Meaning_

// final EntityType<Meaning> Meaning_ = em.getmetamodel().entity(Meaning.class); final CriteriaBuilder cb = em.getCriteriaBuilder();CriteriaQuery<Integer> cq = cb.createQuery(Integer.class);final Root<Meaning> meng = cq.from(Meaning.class);cq.where(meng.get(Meaning_.lastPublishedDate)); // add the appropriate import cq.select(meng.get(Meaning_.objId)); TypedQuery<Integer> q = em.createQuery(cq); return q.getResultList();

关于静态(规范)元模型类的生成

这是我用来通过Eclipselink生成规范元模型类的Maven设置:

<project>  ...  <repositories>    <!-- Repository for Eclipselink artifacts -->    <repository>      <id>Eclipselink Repo</id>      <url>http://www.eclipse.org/downloads/download.php?r=1&amp;nf=1&amp;file=/rt/eclipselink/maven.repo/</url>    </repository>        ...  </repositories>  ...  <pluginRepositories>    <!-- For the annotation processor plugin -->    <pluginRepository>      <id>maven-annotation-plugin</id>      <url>http://maven-annotation-plugin.googlepre.com/svn/trunk/mavenrepo</url>    </pluginRepository>  </pluginRepositories>  ...  <dependencies>    <dependency>      <groupId>org.eclipse.persistence</groupId>      <artifactId>eclipselink</artifactId>      <version>2.1.0</version>    </dependency>    <!-- optional - only needed if you are using JPA outside of a Java EE container-->    <dependency>      <groupId>org.eclipse.persistence</groupId>      <artifactId>javax.persistence</artifactId>      <version>2.0.2</version>    </dependency>  <dependencies>  ...  <build>    <plugins>      <plugin>        <groupId>org.bsc.maven</groupId>        <artifactId>maven-processor-plugin</artifactId>        <version>1.3.1</version>        <executions>          <execution> <id>process</id> <goals>   <goal>process</goal> </goals> <phase>generate-sources</phase> <configuration>   <!-- Without this, the annotation processor complains about persistence.xml not being present and fail -->   <compilerArguments>-Aeclipselink.persistencexml=src/main/resources/meta-INF/persistence.xml</compilerArguments>   <!-- For an unknown reason, the annotation processor is not discovered, have to list it explicitly -->   <processors>     <processor>org.eclipse.persistence.internal.jpa.modelgen.CanonicalModelProcessor</processor>   </processors>   <!-- source output directory -->   <outputDirectory>${project.build.directory}/generated-sources/meta-model</outputDirectory> </configuration>          </execution>        </executions>      </plugin>      <plugin>        <groupId>org.apache.maven.plugins</groupId>        <artifactId>maven-compiler-plugin</artifactId>        <inherited>true</inherited>        <configuration>          <source>1.6</source>          <target>1.6</target>          <compilerArgument>-proc:none</compilerArgument>        </configuration>      </plugin>      ...    </plugins>  </build></project>

一些评论:

  • Eclipselink注释处理器由主要工件提供,没有要添加的额外依赖项。
  • 由于未知原因,未发现注释处理器,我必须将其显式列出为
    <processor>
  • 没有
    -Aeclipselink.persistencexml
    ,注释处理器会抱怨
    persistence.xml
    不存在并失败。
  • 我更喜欢在
    target
    (我想要
    clean
    清理它)下生成源代码。

使用此配置,将生成并适当地编译静态元模型类。



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/574400.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号