/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Project/Maven2/JavaApp/src/main/java/${packagePath}/${mainClassName}.java to edit this template
*/
package com.example.jpanetbeans;
import java.util.List;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
/**
*
* @author Administrator
*/
public class Jpanetbeans {
public static void main(String[] args) throws Exception {
System.out.println("Hello World!");
String PERSISTENCE_UNIT_NAME = "com.example_jpanetbeans_jar_1.0-SNAPSHOTPU";
EntityManagerFactory emFactory = Persistence.createEntityManagerFactory(PERSISTENCE_UNIT_NAME);
BooksJpaController bjc = new BooksJpaController(emFactory);
System.out.println("BEGIN: bjc.create(book1)");
Books book1 = new Books();
book1.setAuthor("author1");
book1.setBid("1001");
book1.setTitle("title1");
book1.setStatus("status1");
bjc.create(book1);
System.out.println("BEGIN: bjc.create(book2)");
Books book2 = new Books();
book2.setAuthor("author2");
book2.setBid("1002");
book2.setTitle("title2");
book2.setStatus("status2");
bjc.create(book2);
System.out.println("BEGIN: bjc.edit(book1up)");
Books book1up = new Books();
book1up.setAuthor("author1up");
book1up.setBid("1001");
book1up.setTitle("title1up");
book1up.setStatus("status1up");
bjc.edit(book1up);
System.out.println("BEGIN: getBooksCount");
System.out.println(bjc.getBooksCount());
System.out.println("BEGIN: findBooksEntities");
List<Books> booklist = bjc.findBooksEntities();
for (Books book : booklist) {
System.out.println(book.getBid() + ":" + book.getTitle() + ":" + book.getAuthor() + ":" + book.getStatus());
}
System.out.println("BEGIN: findBooks");
Books bookfind = bjc.findBooks("1001");
System.out.println(bookfind.getBid() + ":" + bookfind.getTitle() + ":" + bookfind.getAuthor() + ":" + bookfind.getStatus());
System.out.println("BEGIN: bjc.destroy(\"1001\")");
bjc.destroy("1001");
System.out.println("BEGIN: findBooksEntities");
booklist = bjc.findBooksEntities();
for (Books book : booklist) {
System.out.println(book.getBid() + ":" + book.getTitle() + ":" + book.getAuthor() + ":" + book.getStatus());
}
}
}
Hibernate
cd C:\Users\Administrator\Documents\NetBeansProjects\jpanetbeans2; "JAVA_HOME=C:\\Program Files\\Java\\jdk1.8.0_202" cmd /c "\"C:\\Program Files\\NetBeans-13\\netbeans\\java\\maven\\bin\\mvn.cmd\" -Dexec.vmArgs= \"-Dexec.args=${exec.vmArgs} -classpath %classpath ${exec.mainClass} ${exec.appArgs}\" \"-Dexec.executable=C:\\Program Files\\Java\\jdk1.8.0_202\\bin\\java.exe\" -Dexec.mainClass=com.example.jpanetbeans2.Jpanetbeans2 -Dexec.classpathScope=runtime -Dexec.appArgs= \"-Dmaven.ext.class.path=C:\\Program Files\\NetBeans-13\\netbeans\\java\\maven-nblib\\netbeans-eventspy.jar\" -Dfile.encoding=UTF-8 org.codehaus.mojo:exec-maven-plugin:3.0.0:exec"
Running NetBeans Compile On Save execution. Phase execution is skipped and output directories of dependency projects (with Compile on Save turned on) will be used instead of their jar artifacts.
Scanning for projects...
----------------------< com.example:jpanetbeans2 >----------------------
Building jpanetbeans2 1.0-SNAPSHOT
--------------------------------[ jar ]---------------------------------
--- exec-maven-plugin:3.0.0:exec (default-cli) @ jpanetbeans2 ---
Hello World!
三月 27, 2022 9:10:44 上午 org.hibernate.jpa.internal.util.LogHelper logPersistenceUnitInformation
INFO: HHH000204: Processing PersistenceUnitInfo [name: com.example_jpanetbeans2_jar_1.0-SNAPSHOTPU]
三月 27, 2022 9:10:44 上午 org.hibernate.Version logVersion
INFO: HHH000412: Hibernate ORM core version 5.6.5.Final
三月 27, 2022 9:10:44 上午 org.hibernate.annotations.common.reflection.java.JavaReflectionManager <clinit>
INFO: HCANN000001: Hibernate Commons Annotations {5.1.2.Final}
三月 27, 2022 9:10:45 上午 org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
WARN: HHH10001002: Using Hibernate built-in connection pool (not for production use!)
三月 27, 2022 9:10:45 上午 org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
INFO: HHH10001005: using driver [com.mysql.cj.jdbc.Driver] at URL [jdbc:mysql://localhost:3306/db?autoReconnect=true&useSSL=false&useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai]
三月 27, 2022 9:10:45 上午 org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
INFO: HHH10001001: Connection properties: {user=root, password=****}
三月 27, 2022 9:10:45 上午 org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
INFO: HHH10001003: Autocommit mode: false
三月 27, 2022 9:10:45 上午 org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl$PooledConnections <init>
INFO: HHH000115: Hibernate connection pool size: 20 (min=1)
三月 27, 2022 9:10:45 上午 org.hibernate.dialect.Dialect <init>
INFO: HHH000400: Using dialect: org.hibernate.dialect.MySQL8Dialect
Hibernate: drop table if exists books
三月 27, 2022 9:10:46 上午 org.hibernate.resource.transaction.backend.jdbc.internal.DdlTransactionIsolatorNonJtaImpl getIsolatedConnection
INFO: HHH10001501: Connection obtained from JdbcConnectionAccess [org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator$ConnectionProviderJdbcConnectionAccess@1556f2dd] for (non-JTA) DDL execution was not in auto-commit mode; the Connection 'local transaction' will be committed and the Connection will be set into auto-commit mode.
Hibernate: create table books (bid varchar(255) not null, author varchar(255), status varchar(255), title varchar(255), primary key (bid)) engine=InnoDB
三月 27, 2022 9:10:46 上午 org.hibernate.resource.transaction.backend.jdbc.internal.DdlTransactionIsolatorNonJtaImpl getIsolatedConnection
INFO: HHH10001501: Connection obtained from JdbcConnectionAccess [org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator$ConnectionProviderJdbcConnectionAccess@4837595f] for (non-JTA) DDL execution was not in auto-commit mode; the Connection 'local transaction' will be committed and the Connection will be set into auto-commit mode.
三月 27, 2022 9:10:46 上午 org.hibernate.engine.transaction.jta.platform.internal.JtaPlatformInitiator initiateService
INFO: HHH000490: Using JtaPlatform implementation: [org.hibernate.engine.transaction.jta.platform.internal.NoJtaPlatform]
BEGIN: bjc.create(book1)
Hibernate: insert into books (author, status, title, bid) values (?, ?, ?, ?)
BEGIN: bjc.create(book2)
Hibernate: insert into books (author, status, title, bid) values (?, ?, ?, ?)
BEGIN: bjc.edit(book1up)
Hibernate: select books0_.bid as bid1_0_0_, books0_.author as author2_0_0_, books0_.status as status3_0_0_, books0_.title as title4_0_0_ from books books0_ where books0_.bid=?
Hibernate: update books set author=?, status=?, title=? where bid=?
BEGIN: getBooksCount
Hibernate: select count(books0_.bid) as col_0_0_ from books books0_
2
BEGIN: findBooksEntities
Hibernate: select books0_.bid as bid1_0_, books0_.author as author2_0_, books0_.status as status3_0_, books0_.title as title4_0_ from books books0_
1001:title1up:author1up:status1up
1002:title2:author2:status2
BEGIN: findBooks
Hibernate: select books0_.bid as bid1_0_0_, books0_.author as author2_0_0_, books0_.status as status3_0_0_, books0_.title as title4_0_0_ from books books0_ where books0_.bid=?
1001:title1up:author1up:status1up
BEGIN: bjc.destroy("1001")
Hibernate: select books0_.bid as bid1_0_0_, books0_.author as author2_0_0_, books0_.status as status3_0_0_, books0_.title as title4_0_0_ from books books0_ where books0_.bid=?
Hibernate: delete from books where bid=?
BEGIN: findBooksEntities
Hibernate: select books0_.bid as bid1_0_, books0_.author as author2_0_, books0_.status as status3_0_, books0_.title as title4_0_ from books books0_
1002:title2:author2:status2
------------------------------------------------------------------------
BUILD SUCCESS
------------------------------------------------------------------------
Total time: 4.314 s
Finished at: 2022-03-27T09:10:47+08:00
------------------------------------------------------------------------
EclipseLink
cd C:\Users\Administrator\Documents\NetBeansProjects\jpanetbeans; "JAVA_HOME=C:\\Program Files\\Java\\jdk1.8.0_202" cmd /c "\"C:\\Program Files\\NetBeans-13\\netbeans\\java\\maven\\bin\\mvn.cmd\" -Dexec.vmArgs= \"-Dexec.args=${exec.vmArgs} -classpath %classpath ${exec.mainClass} ${exec.appArgs}\" \"-Dexec.executable=C:\\Program Files\\Java\\jdk1.8.0_202\\bin\\java.exe\" -Dexec.mainClass=com.example.jpanetbeans.Jpanetbeans -Dexec.classpathScope=runtime -Dexec.appArgs= \"-Dmaven.ext.class.path=C:\\Program Files\\NetBeans-13\\netbeans\\java\\maven-nblib\\netbeans-eventspy.jar\" -Dfile.encoding=UTF-8 org.codehaus.mojo:exec-maven-plugin:3.0.0:exec"
Running NetBeans Compile On Save execution. Phase execution is skipped and output directories of dependency projects (with Compile on Save turned on) will be used instead of their jar artifacts.
Scanning for projects...
----------------------< com.example:jpanetbeans >-----------------------
Building jpanetbeans 1.0-SNAPSHOT
--------------------------------[ jar ]---------------------------------
--- exec-maven-plugin:3.0.0:exec (default-cli) @ jpanetbeans ---
Hello World!
[EL Fine]: server: 2022-03-27 09:00:39.841--Thread(Thread[main,5,main])--Configured server platform: org.eclipse.persistence.platform.server.NoServerPlatform
[EL Config]: metadata: 2022-03-27 09:00:40.004--ServerSession(695682681)--Thread(Thread[main,5,main])--The access type for the persistent class [class com.example.jpanetbeans.Books] is set to [FIELD].
[EL Config]: metadata: 2022-03-27 09:00:40.026--ServerSession(695682681)--Thread(Thread[main,5,main])--The alias name for the entity class [class com.example.jpanetbeans.Books] is being defaulted to: Books.
[EL Info]: 2022-03-27 09:00:40.719--ServerSession(695682681)--Thread(Thread[main,5,main])--EclipseLink, version: Eclipse Persistence Services - 2.7.9.v20210604-2c549e2208
[EL Fine]: connection: 2022-03-27 09:00:40.99--Thread(Thread[main,5,main])--Detected database platform: org.eclipse.persistence.platform.database.MySQLPlatform
[EL Fine]: connection: 2022-03-27 09:00:41.002--ServerSession(695682681)--Connection(1777238524)--Thread(Thread[main,5,main])--connecting(DatabaseLogin(
platform=>MySQLPlatform
user name=> "root"
datasource URL=> "jdbc:mysql://localhost:3306/db?autoReconnect=true&useSSL=false&useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai"
))
[EL Config]: connection: 2022-03-27 09:00:41.022--ServerSession(695682681)--Connection(1345900725)--Thread(Thread[main,5,main])--Connected: jdbc:mysql://localhost:3306/db?autoReconnect=true&useSSL=false&useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai
User: root@localhost
Database: MySQL Version: 8.0.22
Driver: MySQL Connector/J Version: mysql-connector-java-8.0.28 (Revision: 7ff2161da3899f379fb3171b6538b191b1c5c7e2)
[EL Fine]: connection: 2022-03-27 09:00:41.154--ServerSession(695682681)--Thread(Thread[main,5,main])--/file:/C:/Users/Administrator/Documents/NetBeansProjects/jpanetbeans/target/classes/_com.example_jpanetbeans_jar_1.0-SNAPSHOTPU login successful
[EL Fine]: sql: 2022-03-27 09:00:41.172--ServerSession(695682681)--Connection(1345900725)--Thread(Thread[main,5,main])--DROP TABLE books
[EL Fine]: sql: 2022-03-27 09:00:41.265--ServerSession(695682681)--Connection(1345900725)--Thread(Thread[main,5,main])--CREATE TABLE books (bid VARCHAR(255) NOT NULL, author VARCHAR(255), status VARCHAR(255), title VARCHAR(255), PRIMARY KEY (bid))
BEGIN: bjc.create(book1)
[EL Fine]: sql: 2022-03-27 09:00:41.417--ClientSession(2108297149)--Connection(1345900725)--Thread(Thread[main,5,main])--INSERT INTO books (bid, author, status, title) VALUES (?, ?, ?, ?)
bind => [1001, author1, status1, title1]
BEGIN: bjc.create(book2)
[EL Fine]: sql: 2022-03-27 09:00:41.441--ClientSession(57241990)--Connection(1345900725)--Thread(Thread[main,5,main])--INSERT INTO books (bid, author, status, title) VALUES (?, ?, ?, ?)
bind => [1002, author2, status2, title2]
BEGIN: bjc.edit(book1up)
[EL Fine]: sql: 2022-03-27 09:00:41.47--ClientSession(1094674892)--Connection(1345900725)--Thread(Thread[main,5,main])--UPDATE books SET author = ?, status = ?, title = ? WHERE (bid = ?)
bind => [author1up, status1up, title1up, 1001]
BEGIN: getBooksCount
[EL Fine]: sql: 2022-03-27 09:00:41.518--ServerSession(695682681)--Connection(1345900725)--Thread(Thread[main,5,main])--SELECT COUNT(bid) FROM books
2
BEGIN: findBooksEntities
[EL Fine]: sql: 2022-03-27 09:00:41.523--ServerSession(695682681)--Connection(1345900725)--Thread(Thread[main,5,main])--SELECT bid, author, status, title FROM books
1001:title1up:author1up:status1up
1002:title2:author2:status2
BEGIN: findBooks
1001:title1up:author1up:status1up
BEGIN: bjc.destroy("1001")
[EL Fine]: sql: 2022-03-27 09:00:41.529--ClientSession(858232531)--Connection(1345900725)--Thread(Thread[main,5,main])--DELETE FROM books WHERE (bid = ?)
bind => [1001]
BEGIN: findBooksEntities
[EL Fine]: sql: 2022-03-27 09:00:41.543--ServerSession(695682681)--Connection(1345900725)--Thread(Thread[main,5,main])--SELECT bid, author, status, title FROM books
1002:title2:author2:status2
------------------------------------------------------------------------
BUILD SUCCESS
------------------------------------------------------------------------
Total time: 3.580 s
Finished at: 2022-03-27T09:00:41+08:00
------------------------------------------------------------------------
可见Hibernate在update和delete之前都发出了多余的select命令;
EclipseLink没有任何多余语句,并且选择一条记录时还减少了一次select
EclipseLink只查询时,进行了select
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Project/Maven2/JavaApp/src/main/java/${packagePath}/${mainClassName}.java to edit this template
*/
package com.example.jpanetbeans;
import java.util.List;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
/**
*
* @author Administrator
*/
public class Jpanetbeansfind {
public static void main(String[] args) throws Exception {
System.out.println("Hello World!");
String PERSISTENCE_UNIT_NAME = "com.example_jpanetbeans_jar_1.0-SNAPSHOTPU";
EntityManagerFactory emFactory = Persistence.createEntityManagerFactory(PERSISTENCE_UNIT_NAME);
BooksJpaController bjc = new BooksJpaController(emFactory);
System.out.println("BEGIN: findBooks");
Books bookfind = bjc.findBooks("1001");
System.out.println(bookfind.getBid() + ":" + bookfind.getTitle() + ":" + bookfind.getAuthor() + ":" + bookfind.getStatus());
}
}
cd C:\Users\Administrator\Documents\NetBeansProjects\jpanetbeans; "JAVA_HOME=C:\\Program Files\\Java\\jdk1.8.0_202" cmd /c "\"C:\\Program Files\\NetBeans-13\\netbeans\\java\\maven\\bin\\mvn.cmd\" -Dexec.vmArgs= \"-Dexec.args=${exec.vmArgs} -classpath %classpath ${exec.mainClass} ${exec.appArgs}\" \"-Dexec.executable=C:\\Program Files\\Java\\jdk1.8.0_202\\bin\\java.exe\" -Dexec.mainClass=com.example.jpanetbeans.Jpanetbeansfind -Dexec.classpathScope=runtime -Dexec.appArgs= \"-Dmaven.ext.class.path=C:\\Program Files\\NetBeans-13\\netbeans\\java\\maven-nblib\\netbeans-eventspy.jar\" -Dfile.encoding=UTF-8 org.codehaus.mojo:exec-maven-plugin:3.0.0:exec"
Running NetBeans Compile On Save execution. Phase execution is skipped and output directories of dependency projects (with Compile on Save turned on) will be used instead of their jar artifacts.
Scanning for projects...
----------------------< com.example:jpanetbeans >-----------------------
Building jpanetbeans 1.0-SNAPSHOT
--------------------------------[ jar ]---------------------------------
--- exec-maven-plugin:3.0.0:exec (default-cli) @ jpanetbeans ---
Hello World!
[EL Fine]: server: 2022-03-27 09:20:13.66--Thread(Thread[main,5,main])--Configured server platform: org.eclipse.persistence.platform.server.NoServerPlatform
[EL Config]: metadata: 2022-03-27 09:20:13.817--ServerSession(695682681)--Thread(Thread[main,5,main])--The access type for the persistent class [class com.example.jpanetbeans.Books] is set to [FIELD].
[EL Config]: metadata: 2022-03-27 09:20:13.837--ServerSession(695682681)--Thread(Thread[main,5,main])--The alias name for the entity class [class com.example.jpanetbeans.Books] is being defaulted to: Books.
[EL Info]: 2022-03-27 09:20:14.496--ServerSession(695682681)--Thread(Thread[main,5,main])--EclipseLink, version: Eclipse Persistence Services - 2.7.9.v20210604-2c549e2208
[EL Fine]: connection: 2022-03-27 09:20:14.751--Thread(Thread[main,5,main])--Detected database platform: org.eclipse.persistence.platform.database.MySQLPlatform
[EL Fine]: connection: 2022-03-27 09:20:14.761--ServerSession(695682681)--Connection(1777238524)--Thread(Thread[main,5,main])--connecting(DatabaseLogin(
platform=>MySQLPlatform
user name=> "root"
datasource URL=> "jdbc:mysql://localhost:3306/db?autoReconnect=true&useSSL=false&useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai"
))
[EL Config]: connection: 2022-03-27 09:20:14.784--ServerSession(695682681)--Connection(1345900725)--Thread(Thread[main,5,main])--Connected: jdbc:mysql://localhost:3306/db?autoReconnect=true&useSSL=false&useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai
User: root@localhost
Database: MySQL Version: 8.0.22
Driver: MySQL Connector/J Version: mysql-connector-java-8.0.28 (Revision: 7ff2161da3899f379fb3171b6538b191b1c5c7e2)
[EL Fine]: connection: 2022-03-27 09:20:14.913--ServerSession(695682681)--Thread(Thread[main,5,main])--/file:/C:/Users/Administrator/Documents/NetBeansProjects/jpanetbeans/target/classes/_com.example_jpanetbeans_jar_1.0-SNAPSHOTPU login successful
[EL Fine]: sql: 2022-03-27 09:20:14.93--ServerSession(695682681)--Connection(1345900725)--Thread(Thread[main,5,main])--DROP TABLE books
[EL Fine]: sql: 2022-03-27 09:20:15.02--ServerSession(695682681)--Connection(1345900725)--Thread(Thread[main,5,main])--CREATE TABLE books (bid VARCHAR(255) NOT NULL, author VARCHAR(255), status VARCHAR(255), title VARCHAR(255), PRIMARY KEY (bid))
BEGIN: findBooks
[EL Fine]: sql: 2022-03-27 09:20:15.178--ServerSession(695682681)--Connection(1345900725)--Thread(Thread[main,5,main])--SELECT bid, author, status, title FROM books WHERE (bid = ?)
bind => [1001]
Exception in thread "main" java.lang.NullPointerException
at com.example.jpanetbeans.Jpanetbeansfind.main(Jpanetbeansfind.java:25)
Command execution failed.
org.apache.commons.exec.ExecuteException: Process exited with an error: 1 (Exit value: 1)
at org.apache.commons.exec.DefaultExecutor.executeInternal (DefaultExecutor.java:404)
at org.apache.commons.exec.DefaultExecutor.execute (DefaultExecutor.java:166)
at org.codehaus.mojo.exec.ExecMojo.executeCommandLine (ExecMojo.java:982)
at org.codehaus.mojo.exec.ExecMojo.executeCommandLine (ExecMojo.java:929)
at org.codehaus.mojo.exec.ExecMojo.execute (ExecMojo.java:457)
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:137)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:210)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:156)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:148)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:117)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:81)
at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:56)
at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:128)
at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:305)
at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:192)
at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:105)
at org.apache.maven.cli.MavenCli.execute (MavenCli.java:972)
at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:293)
at org.apache.maven.cli.MavenCli.main (MavenCli.java:196)
at sun.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke (Method.java:498)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:282)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:225)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:406)
at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:347)
------------------------------------------------------------------------
BUILD FAILURE
------------------------------------------------------------------------
Total time: 3.671 s
Finished at: 2022-03-27T09:20:15+08:00
------------------------------------------------------------------------
Failed to execute goal org.codehaus.mojo:exec-maven-plugin:3.0.0:exec (default-cli) on project jpanetbeans: Command execution failed.: Process exited with an error: 1 (Exit value: 1) -> [Help 1]
To see the full stack trace of the errors, re-run Maven with the -e switch.
Re-run Maven using the -X switch to enable full debug logging.
For more information about the errors and possible solutions, please read the following articles:
[Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
再看如下OpenJPA,可见OpenJPA在update之前发出了多余的select命令;
cd C:\Users\Administrator\Documents\NetBeansProjects\jpanetbeans4; "JAVA_HOME=C:\\Program Files\\Java\\jdk1.8.0_202" cmd /c "\"C:\\Program Files\\NetBeans-13\\netbeans\\java\\maven\\bin\\mvn.cmd\" -Dexec.vmArgs= \"-Dexec.args=${exec.vmArgs} -classpath %classpath ${exec.mainClass} ${exec.appArgs}\" \"-Dexec.executable=C:\\Program Files\\Java\\jdk1.8.0_202\\bin\\java.exe\" -Dexec.mainClass=com.example.jpanetbeans4.Jpanetbeans4 -Dexec.classpathScope=runtime -Dexec.appArgs= \"-Dmaven.ext.class.path=C:\\Program Files\\NetBeans-13\\netbeans\\java\\maven-nblib\\netbeans-eventspy.jar\" -Dfile.encoding=UTF-8 org.codehaus.mojo:exec-maven-plugin:3.0.0:exec"
Running NetBeans Compile On Save execution. Phase execution is skipped and output directories of dependency projects (with Compile on Save turned on) will be used instead of their jar artifacts.
Scanning for projects...
----------------------< com.example:jpanetbeans4 >----------------------
Building jpanetbeans4 1.0-SNAPSHOT
--------------------------------[ jar ]---------------------------------
--- exec-maven-plugin:3.0.0:exec (default-cli) @ jpanetbeans4 ---
Hello World!
200 com.example_jpanetbeans4_jar_1.0-SNAPSHOTPU INFO [main] openjpa.Runtime - OpenJPA dynamically loaded the class enhancer. Any classes that were not enhanced at build time will be enhanced when they are loaded by the JVM.
BEGIN: bjc.create(book1)
457 com.example_jpanetbeans4_jar_1.0-SNAPSHOTPU INFO [main] openjpa.Runtime - Starting OpenJPA 3.2.1
929 com.example_jpanetbeans4_jar_1.0-SNAPSHOTPU TRACE [main] openjpa.jdbc.SQL - <t 120478350, conn 1424082571> executing stmnt 2102368942 DROP TABLE books
978 com.example_jpanetbeans4_jar_1.0-SNAPSHOTPU TRACE [main] openjpa.jdbc.SQL - <t 120478350, conn 1424082571> [49 ms] spent
1000 com.example_jpanetbeans4_jar_1.0-SNAPSHOTPU TRACE [main] openjpa.jdbc.SQL - <t 120478350, conn 656479172> executing stmnt 2017085051 CREATE TABLE books (bid VARCHAR(255) NOT NULL, author VARCHAR(255), status VARCHAR(255), title VARCHAR(255), PRIMARY KEY (bid)) ENGINE = innodb
1094 com.example_jpanetbeans4_jar_1.0-SNAPSHOTPU TRACE [main] openjpa.jdbc.SQL - <t 120478350, conn 656479172> [94 ms] spent
1220 com.example_jpanetbeans4_jar_1.0-SNAPSHOTPU TRACE [main] openjpa.jdbc.SQL - <t 120478350, conn 1139814130> executing prepstmnt 2077742806 INSERT INTO books (bid, author, status, title) VALUES (?, ?, ?, ?) [params=?, ?, ?, ?]
1222 com.example_jpanetbeans4_jar_1.0-SNAPSHOTPU TRACE [main] openjpa.jdbc.SQL - <t 120478350, conn 1139814130> [2 ms] spent
BEGIN: bjc.create(book2)
1250 com.example_jpanetbeans4_jar_1.0-SNAPSHOTPU TRACE [main] openjpa.jdbc.SQL - <t 120478350, conn 1551446957> executing prepstmnt 2030937207 INSERT INTO books (bid, author, status, title) VALUES (?, ?, ?, ?) [params=?, ?, ?, ?]
1250 com.example_jpanetbeans4_jar_1.0-SNAPSHOTPU TRACE [main] openjpa.jdbc.SQL - <t 120478350, conn 1551446957> [0 ms] spent
BEGIN: bjc.edit(book1up)
1285 com.example_jpanetbeans4_jar_1.0-SNAPSHOTPU TRACE [main] openjpa.jdbc.SQL - <t 120478350, conn 554348863> executing prepstmnt 1572256205 SELECT t0.author, t0.bid, t0.status, t0.title FROM books t0 WHERE t0.bid = ? [params=?]
1286 com.example_jpanetbeans4_jar_1.0-SNAPSHOTPU TRACE [main] openjpa.jdbc.SQL - <t 120478350, conn 554348863> [0 ms] spent
1301 com.example_jpanetbeans4_jar_1.0-SNAPSHOTPU TRACE [main] openjpa.jdbc.SQL - <t 120478350, conn 1383519982> executing prepstmnt 1551629761 UPDATE books SET author = ?, status = ?, title = ? WHERE bid = ? [params=?, ?, ?, ?]
1302 com.example_jpanetbeans4_jar_1.0-SNAPSHOTPU TRACE [main] openjpa.jdbc.SQL - <t 120478350, conn 1383519982> [1 ms] spent
BEGIN: getBooksCount
1419 com.example_jpanetbeans4_jar_1.0-SNAPSHOTPU TRACE [main] openjpa.jdbc.SQL - <t 120478350, conn 1272123492> executing prepstmnt 1297189682 SELECT COUNT(t0.bid) FROM books t0
1421 com.example_jpanetbeans4_jar_1.0-SNAPSHOTPU TRACE [main] openjpa.jdbc.SQL - <t 120478350, conn 1272123492> [2 ms] spent
2
BEGIN: findBooksEntities
1432 com.example_jpanetbeans4_jar_1.0-SNAPSHOTPU TRACE [main] openjpa.jdbc.SQL - <t 120478350, conn 176342513> executing prepstmnt 939199469 SELECT t0.bid, t0.author, t0.status, t0.title FROM books t0
1433 com.example_jpanetbeans4_jar_1.0-SNAPSHOTPU TRACE [main] openjpa.jdbc.SQL - <t 120478350, conn 176342513> [1 ms] spent
1001:title1up:author1up:status1up
1002:title2:author2:status2
BEGIN: findBooks
1448 com.example_jpanetbeans4_jar_1.0-SNAPSHOTPU TRACE [main] openjpa.jdbc.SQL - <t 120478350, conn 127702987> executing prepstmnt 698741991 SELECT t0.author, t0.bid, t0.status, t0.title FROM books t0 WHERE t0.bid = ? [params=?]
1449 com.example_jpanetbeans4_jar_1.0-SNAPSHOTPU TRACE [main] openjpa.jdbc.SQL - <t 120478350, conn 127702987> [1 ms] spent
1001:title1up:author1up:status1up
BEGIN: bjc.destroy("1001")
1455 com.example_jpanetbeans4_jar_1.0-SNAPSHOTPU TRACE [main] openjpa.jdbc.SQL - <t 120478350, conn 1263634860> executing prepstmnt 1332757905 DELETE FROM books WHERE bid = ? [params=?]
1458 com.example_jpanetbeans4_jar_1.0-SNAPSHOTPU TRACE [main] openjpa.jdbc.SQL - <t 120478350, conn 1263634860> [2 ms] spent
BEGIN: findBooksEntities
1472 com.example_jpanetbeans4_jar_1.0-SNAPSHOTPU TRACE [main] openjpa.jdbc.SQL - <t 120478350, conn 28094269> executing prepstmnt 511832416 SELECT t0.bid, t0.author, t0.status, t0.title FROM books t0
1472 com.example_jpanetbeans4_jar_1.0-SNAPSHOTPU TRACE [main] openjpa.jdbc.SQL - <t 120478350, conn 28094269> [0 ms] spent
1002:title2:author2:status2
------------------------------------------------------------------------
BUILD SUCCESS
------------------------------------------------------------------------
Total time: 2.829 s
Finished at: 2022-03-27T09:31:59+08:00
------------------------------------------------------------------------
---------------------------------------------------------
在persistance.xml中关闭二级缓存后
<shared-cache-mode>NONE</shared-cache-mode>
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.1" xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
<persistence-unit name="com.example_jpanetbeans_jar_1.0-SNAPSHOTPU" transaction-type="RESOURCE_LOCAL">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<class>com.example.jpanetbeans.Books</class>
<shared-cache-mode>NONE</shared-cache-mode>
<properties>
<property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/db?autoReconnect=true&useSSL=false&useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai"/>
<property name="javax.persistence.jdbc.user" value="root"/>
<property name="javax.persistence.jdbc.driver" value="com.mysql.cj.jdbc.Driver"/>
<property name="javax.persistence.jdbc.password" value="root"/>
<property name="javax.persistence.schema-generation.database.action" value="drop-and-create"/>
<property name="eclipselink.logging.level" value="FINE"/>
</properties>
</persistence-unit>
</persistence>
EclipseLink在update和delete之前都发出了多余的select命令和Hibernate默认情况下一样,说明Hibernate默认关闭了二级缓存,EclipseLink默认打开了二级缓存
cd C:\Users\Administrator\Documents\NetBeansProjects\jpanetbeans; "JAVA_HOME=C:\\Program Files\\Java\\jdk1.8.0_202" cmd /c "\"C:\\Program Files\\NetBeans-13\\netbeans\\java\\maven\\bin\\mvn.cmd\" -Dexec.vmArgs= \"-Dexec.args=${exec.vmArgs} -classpath %classpath ${exec.mainClass} ${exec.appArgs}\" \"-Dexec.executable=C:\\Program Files\\Java\\jdk1.8.0_202\\bin\\java.exe\" -Dexec.mainClass=com.example.jpanetbeans.Jpanetbeans -Dexec.classpathScope=runtime -Dexec.appArgs= \"-Dmaven.ext.class.path=C:\\Program Files\\NetBeans-13\\netbeans\\java\\maven-nblib\\netbeans-eventspy.jar\" -Dfile.encoding=UTF-8 org.codehaus.mojo:exec-maven-plugin:3.0.0:exec"
Running NetBeans Compile On Save execution. Phase execution is skipped and output directories of dependency projects (with Compile on Save turned on) will be used instead of their jar artifacts.
Scanning for projects...
----------------------< com.example:jpanetbeans >-----------------------
Building jpanetbeans 1.0-SNAPSHOT
--------------------------------[ jar ]---------------------------------
--- exec-maven-plugin:3.0.0:exec (default-cli) @ jpanetbeans ---
Hello World!
[EL Fine]: server: 2022-03-29 10:52:14.988--Thread(Thread[main,5,main])--Configured server platform: org.eclipse.persistence.platform.server.NoServerPlatform
[EL Config]: metadata: 2022-03-29 10:52:15.175--ServerSession(644166178)--Thread(Thread[main,5,main])--The access type for the persistent class [class com.example.jpanetbeans.Books] is set to [FIELD].
[EL Config]: metadata: 2022-03-29 10:52:15.206--ServerSession(644166178)--Thread(Thread[main,5,main])--The alias name for the entity class [class com.example.jpanetbeans.Books] is being defaulted to: Books.
[EL Info]: 2022-03-29 10:52:15.894--ServerSession(644166178)--Thread(Thread[main,5,main])--EclipseLink, version: Eclipse Persistence Services - 2.7.9.v20210604-2c549e2208
[EL Fine]: connection: 2022-03-29 10:52:16.206--Thread(Thread[main,5,main])--Detected database platform: org.eclipse.persistence.platform.database.MySQLPlatform
[EL Fine]: connection: 2022-03-29 10:52:16.222--ServerSession(644166178)--Connection(1161322357)--Thread(Thread[main,5,main])--connecting(DatabaseLogin(
platform=>MySQLPlatform
user name=> "root"
datasource URL=> "jdbc:mysql://localhost:3306/db?autoReconnect=true&useSSL=false&useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai"
))
[EL Config]: connection: 2022-03-29 10:52:16.253--ServerSession(644166178)--Connection(672746064)--Thread(Thread[main,5,main])--Connected: jdbc:mysql://localhost:3306/db?autoReconnect=true&useSSL=false&useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai
User: root@localhost
Database: MySQL Version: 8.0.22
Driver: MySQL Connector/J Version: mysql-connector-java-8.0.28 (Revision: 7ff2161da3899f379fb3171b6538b191b1c5c7e2)
[EL Fine]: connection: 2022-03-29 10:52:16.394--ServerSession(644166178)--Thread(Thread[main,5,main])--/file:/C:/Users/Administrator/Documents/NetBeansProjects/jpanetbeans/target/classes/_com.example_jpanetbeans_jar_1.0-SNAPSHOTPU login successful
[EL Fine]: sql: 2022-03-29 10:52:16.409--ServerSession(644166178)--Connection(672746064)--Thread(Thread[main,5,main])--DROP TABLE books
[EL Fine]: sql: 2022-03-29 10:52:16.503--ServerSession(644166178)--Connection(672746064)--Thread(Thread[main,5,main])--CREATE TABLE books (bid VARCHAR(255) NOT NULL, author VARCHAR(255), status VARCHAR(255), title VARCHAR(255), PRIMARY KEY (bid))
BEGIN: bjc.create(book1)
[EL Fine]: sql: 2022-03-29 10:52:16.706--ClientSession(1943634922)--Connection(672746064)--Thread(Thread[main,5,main])--INSERT INTO books (bid, author, status, title) VALUES (?, ?, ?, ?)
bind => [1001, author1, status1, title1]
BEGIN: bjc.create(book2)
[EL Fine]: sql: 2022-03-29 10:52:16.722--ClientSession(1112737073)--Connection(672746064)--Thread(Thread[main,5,main])--INSERT INTO books (bid, author, status, title) VALUES (?, ?, ?, ?)
bind => [1002, author2, status2, title2]
BEGIN: bjc.edit(book1up)
[EL Fine]: sql: 2022-03-29 10:52:16.753--ServerSession(644166178)--Connection(672746064)--Thread(Thread[main,5,main])--SELECT bid, author, status, title FROM books WHERE (bid = ?)
bind => [1001]
[EL Fine]: sql: 2022-03-29 10:52:16.753--ClientSession(967576586)--Connection(672746064)--Thread(Thread[main,5,main])--UPDATE books SET author = ?, status = ?, title = ? WHERE (bid = ?)
bind => [author1up, status1up, title1up, 1001]
BEGIN: getBooksCount
[EL Fine]: sql: 2022-03-29 10:52:16.8--ServerSession(644166178)--Connection(672746064)--Thread(Thread[main,5,main])--SELECT COUNT(bid) FROM books
2
BEGIN: findBooksEntities
[EL Fine]: sql: 2022-03-29 10:52:16.8--ServerSession(644166178)--Connection(672746064)--Thread(Thread[main,5,main])--SELECT bid, author, status, title FROM books
1001:title1up:author1up:status1up
1002:title2:author2:status2
BEGIN: findBooks
[EL Fine]: sql: 2022-03-29 10:52:16.8--ServerSession(644166178)--Connection(672746064)--Thread(Thread[main,5,main])--SELECT bid, author, status, title FROM books WHERE (bid = ?)
bind => [1001]
1001:title1up:author1up:status1up
BEGIN: bjc.destroy("1001")
[EL Fine]: sql: 2022-03-29 10:52:16.8--ServerSession(644166178)--Connection(672746064)--Thread(Thread[main,5,main])--SELECT bid, author, status, title FROM books WHERE (bid = ?)
bind => [1001]
[EL Fine]: sql: 2022-03-29 10:52:16.8--ClientSession(171809144)--Connection(672746064)--Thread(Thread[main,5,main])--DELETE FROM books WHERE (bid = ?)
bind => [1001]
BEGIN: findBooksEntities
[EL Fine]: sql: 2022-03-29 10:52:16.847--ServerSession(644166178)--Connection(672746064)--Thread(Thread[main,5,main])--SELECT bid, author, status, title FROM books
1002:title2:author2:status2
------------------------------------------------------------------------
BUILD SUCCESS
------------------------------------------------------------------------
Total time: 3.725 s
Finished at: 2022-03-29T10:52:16+08:00
------------------------------------------------------------------------