【问题标题】:OpenJPA executing prepared statement when none exist in the project当项目中不存在时,OpenJPA 执行准备好的语句
【发布时间】:2023-04-08 07:41:01
【问题描述】:

我有一个使用 OpenJAP 进行数据库连接的 Web 项目。我已经配置了 persistence.xml,并且能够连接到数据库并检索数据。但是在控制台输出中我看到了这个条目

1953  OpenJPA  TRACE  [main] openjpa.jdbc.SQL - <t 31156635, conn 6888942> executing prepstmnt 9690924 

UPDATE student 
    SET scourse = ?, sname = ?, sroll = ? 
    WHERE id = ? 
[params=?, ?, ?, ?]

到目前为止,在我的整个项目中,我还没有添加任何准备好的语句或任何更新语句。我想知道为什么 OpenJPA 会执行此语句,以及当我获取数百万范围内的大数据时会对性能产生什么影响?

【问题讨论】:

  • 也许项目在文件系统的某个地方引用了一些配置文件?您是如何在您的项目中搜索到上述语句的?也许搜索整台机器。此外,如果可能,调试将提供有关更新语句来自何处的想法
  • 不,该声明不存在。该语句根据访问的表进行更改,这意味着如果表是“学生”,则执行上述语句,否则如果表是“用户”,则使用“用户”表的列执行更新语句。这是 OpenJPA 中一个非常知名的问题。这与数据对象类文件的增强有关。一旦完成,我会尝试一些事情并且它正在工作,然后我会发布答案。

标签: openjpa


【解决方案1】:

我在 build.xml 文件中添加了以下代码

<!-- ***************************************************************************************************************** -->
<!-- DO NOT DELETE FOLLOWING CODE. THIS IS ADDED FOR ENCHANCING THE CLASSES AT COMPILE TIME. IT IS REQUIRED BY OPENJPA -->
<!-- Define the classpath to include the necessary files. -->
<!-- ex. openjpa jars, persistence.xml, orm.xml, and target classes  -->
<path id="jpa.enhancement.classpath">
    <!-- Assuming persistence.xml/orm.xml are in WebContent/WEB-INF/classes/META-INF -->
    <pathelement location="WebContent/WEB-INF/classes" />

    <!-- Location of the .class files -->
    <pathelement location="build/classes" />

    <!-- Add the openjpa jars -->
    <fileset dir=".">
        <include name="**/lib/*.jar" />
    </fileset>
</path>
<!-- define the openjpac task; this can be done at the top of the -->
<!-- build.xml file, so it will be available for all targets -->
<taskdef name="openjpac" classname="org.apache.openjpa.ant.PCEnhancerTask" classpathref="jpa.enhancement.classpath" />

<!-- invoke enhancer on all .class files below the model directory -->
<openjpac>
    <classpath refid="jpa.enhancement.classpath" />
    <fileset dir=".">
        <include name="**/model/*.class" />
    </fileset>
</openjpac>
<echo message="Enhancement complete" />
<!-- ***************************************************************************************************************** -->

添加这个并设置 Eclipse 以使用这个 build.xml 文件来创建 WAR 文件。对象正在得到增强,我的日志中没有“执行准备好的语句”跟踪,也没有执行额外的“更新”语句。

【讨论】:

    猜你喜欢
    • 2010-11-06
    • 2013-12-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-12-31
    • 2018-07-11
    • 2020-03-15
    相关资源
    最近更新 更多