Spring Orm 简明教程
Spring ORM - Run & Test Hibernate
现在在 Eclipse 中,右键单击 MainApp.java,选择 Run As ,然后选择 Java Application 。检查 Eclipse 中的控制台日志。您会看到以下日志 −
...
Sep 27, 2021 9:16:52 AM org.springframework.orm.jpa.LocalEntityManagerFactoryBean createNativeEntityManagerFactory
INFO: Building JPA EntityManagerFactory for persistence unit 'Hibernate_JPA'
Sep 27, 2021 9:16:52 AM org.hibernate.jpa.internal.util.LogHelper logPersistenceUnitInformation
INFO: HHH000204: Processing PersistenceUnitInfo [name: Hibernate_JPA...]
...
INFO: HHH000400: Using dialect: org.hibernate.dialect.MySQL5Dialect
Hibernate: drop table if exists Employees
Sep 27, 2021 9:16:54 AM org.hibernate.resource.transaction.backend.jdbc.internal.DdlTransactionIsolatorNonJtaImpl getIsolatedConnection
INFO: HHH10001501: Connection obtained from JdbcConnectionAccess [org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator$ConnectionProviderJdbcConnectionAccess@2264ea32] 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 Employees (id integer not null auto_increment, DESIGNATION varchar(255), NAME varchar(255), SALARY double precision, primary key (id)) engine=MyISAM
Sep 27, 2021 9:16:54 AM org.hibernate.resource.transaction.backend.jdbc.internal.DdlTransactionIsolatorNonJtaImpl getIsolatedConnection
INFO: HHH10001501: Connection obtained from JdbcConnectionAccess [org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator$ConnectionProviderJdbcConnectionAccess@58740366] 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.
Sep 27, 2021 9:16:54 AM org.hibernate.tool.schema.internal.SchemaCreatorImpl applyImportSources
INFO: HHH000476: Executing import script 'org.hibernate.tool.schema.internal.exec.ScriptSourceInputNonExistentImpl@4b74b35'
Sep 27, 2021 9:16:54 AM org.springframework.orm.jpa.LocalEntityManagerFactoryBean buildNativeEntityManagerFactory
INFO: Initialized JPA EntityManagerFactory for persistence unit 'Hibernate_JPA'
Hibernate: insert into Employees (DESIGNATION, NAME, SALARY) values (?, ?, ?)
Hibernate: insert into Employees (DESIGNATION, NAME, SALARY) values (?, ?, ?)
Hibernate: insert into Employees (DESIGNATION, NAME, SALARY) values (?, ?, ?)
Sep 27, 2021 9:16:55 AM org.hibernate.hql.internal.QueryTranslatorFactoryInitiator initiateService
INFO: HHH000397: Using ASTQueryTranslatorFactory
Hibernate: select employee0_.id as id1_0_, employee0_.DESIGNATION as DESIGNAT2_0_, employee0_.NAME as NAME3_0_, employee0_.SALARY as SALARY4_0_ from Employees employee0_
Id : 1
Name : Julie
Salary = 10000.0
Designation = Technical Manager
Id : 2
Name : Robert
Salary = 20000.0
Designation = Senior Manager
Id : 3
Name : Anil
Salary = 5000.0
Designation = Software Engineer
Sep 27, 2021 9:16:55 AM org.springframework.context.annotation.AnnotationConfigApplicationContext doClose
INFO: Closing org.springframework.context.annotation.AnnotationConfigApplicationContext@18eed359: startup date [Mon Sep 27 09:16:51 IST 2021]; root of context hierarchy
Sep 27, 2021 9:16:55 AM org.springframework.orm.jpa.LocalEntityManagerFactoryBean destroy
INFO: Closing JPA EntityManagerFactory for persistence unit 'Hibernate_JPA'
Sep 27, 2021 9:16:55 AM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl stop
INFO: HHH10001008: Cleaning up connection pool [jdbc:mysql://localhost:3306/tutorialspoint?useSSL=false]
在此使用 Spring 配置构建并运行项目。创建一个 Employee 表并有三个记录。您可以使用 MySQL 控制台对此进行验证。
Enter password: ********
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 41
Server version: 8.0.23 MySQL Community Server - GPL
Copyright (c) 2000, 2021, Oracle and/or its affiliates.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> use tutorialspoint;
Database changed
mysql> select * from employees;
+----+-------------------+--------+--------+
| id | DESIGNATION | NAME | SALARY |
+----+-------------------+--------+--------+
| 1 | Technical Manager | Julie | 10000 |
| 2 | Senior Manager | Robert | 20000 |
| 3 | Software Engineer | Anil | 5000 |
+----+-------------------+--------+--------+
3 rows in set (0.00 sec)
mysql>