
- Spring ORM 教程
- Spring ORM - 主頁
- Spring ORM - 概述
- Spring ORM - 環境設定
- Spring ORM 和 Hibernate
- Spring ORM - 建立專案
- Spring ORM - Maven Hibernate
- Spring ORM - 永續性 Hibernate
- Spring ORM - 更新專案
- Spring ORM - 執行並測試 Hibernate
- Spring ORM 和 EclipseLink
- Spring ORM - Maven EclipseLink
- Spring ORM - 永續性 EclipseLink
- Spring ORM - 更新專案 EclipseLink
- Spring ORM - 執行並測試 EclipseLink
- Spring ORM 實用資源
- Spring ORM - 快速指南
- Spring ORM - 實用資源
- Spring ORM - 討論
Spring ORM - 執行並測試 Hibernate
現在在 eclipse 中,右鍵單擊 MainApp.java,選擇Run As(作為執行)上下文選單,然後選擇Java Application(Java 應用程式)。檢查 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://: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>
廣告