hibernateを利用したアプリケーション起動時に現れる警告の原因を知りたい
解決したいこと
現在、eclipseでJavaとMySQLを使って、筋トレの共有snsアプリケーションを作っています。
hibernateを利用しているのですが、アプリケーションを起動した際に、eclipseのコンソールに以下の警告文が表示されます。今のところまだ、アプリケーションは設計した通りに動いているのですが、今後影響が出てしまわないように今のうちに原因と対応策を知りたいと考えております。
qiitaやstackoverflowで似たような現象が起こっているケースをいくつか見つけましたが、自分の力で解決できなかった為、皆様のお力をお借りしたいです。
mysqlのバージョンは、「5.7.31」です。
発生している問題・エラー
WARN: GenerationTarget encountered exception accepting command : Error executing DDL via JDBC Statement [木 1 14 19:37:05 JST 2021]
該当していると思われるコード
コンソール画面
INFO: HHH000204: Processing PersistenceUnitInfo [
name: workout_diary_system
...] [木 1 14 20:17:01 JST 2021]
INFO: HHH000412: Hibernate Core {5.2.13.Final} [木 1 14 20:17:01 JST 2021]
INFO: HHH000206: hibernate.properties not found [木 1 14 20:17:01 JST 2021]
INFO: HCANN000001: Hibernate Commons Annotations {5.0.1.Final} [木 1 14 20:17:01 JST 2021]
WARN: HHH10001002: Using Hibernate built-in connection pool (not for production use!) [木 1 14 20:17:02 JST 2021]
INFO: HHH10001005: using driver [com.mysql.jdbc.Driver] at URL [jdbc:mysql://localhost/workout_diary_system?useSSL=false&useUnicode=true&characterEncoding=utf8] [木 1 14 20:17:02 JST 2021]
INFO: HHH10001001: Connection properties: {user=mk, password=****} [木 1 14 20:17:02 JST 2021]
INFO: HHH10001003: Autocommit mode: false [木 1 14 20:17:02 JST 2021]
INFO: HHH000115: Hibernate connection pool size: 20 (min=1) [木 1 14 20:17:02 JST 2021]
INFO: HHH000400: Using dialect: org.hibernate.dialect.MySQL5Dialect [木 1 14 20:17:02 JST 2021]
Hibernate:
create table trainees (
id integer not null auto_increment,
created_at datetime not null,
password varchar(64) not null,
updated_at datetime not null,
username varchar(255) not null,
primary key (id)
) engine=MyISAM
INFO: HHH10001501: Connection obtained from JdbcConnectionAccess [org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator$ConnectionProviderJdbcConnectionAccess@bff588e] 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. [木 1 14 20:17:04 JST 2021]
WARN: GenerationTarget encountered exception accepting command : Error executing DDL via JDBC Statement [木 1 14 20:17:04 JST 2021]
Hibernate:
create table workoutreports (
id integer not null auto_increment,
body_part varchar(255) not null,
created_at datetime not null,
intervals integer not null,
menu varchar(255) not null,
rep integer not null,
report_date date not null,
review longtext not null,
sets integer not null,
updated_at datetime not null,
trainee_id integer not null,
primary key (id)
) engine=MyISAM
WARN: GenerationTarget encountered exception accepting command : Error executing DDL via JDBC Statement [木 1 14 20:17:04 JST 2021]
Hibernate:
alter table workoutreports
add constraint FK6d49b8k9klprfo2bpwks0yy00
foreign key (trainee_id)
references trainees (id)
INFO: HHH000476: Executing import script 'org.hibernate.tool.schema.internal.exec.ScriptSourceInputNonExistentImpl@6f3c3fe1' [木 1 14 20:17:04 JST 2021]
INFO: HHH000397: Using ASTQueryTranslatorFactory [木 1 14 20:17:04 JST 2021]
Hibernate:
select
trainee0_.id as id1_0_,
trainee0_.created_at as created_2_0_,
trainee0_.password as password3_0_,
trainee0_.updated_at as updated_4_0_,
trainee0_.username as username5_0_
from
trainees trainee0_
where
trainee0_.username=?
and trainee0_.password=?
Hibernate:
select
trainee0_.id as id1_0_,
trainee0_.created_at as created_2_0_,
trainee0_.password as password3_0_,
trainee0_.updated_at as updated_4_0_,
trainee0_.username as username5_0_
from
trainees trainee0_
order by
trainee0_.id DESC limit ?
Hibernate:
select
count(trainee0_.id) as col_0_0_
from
trainees trainee0_
Trainee.java
package models;
import java.sql.Timestamp;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
@Table(name = "trainees")
@NamedQueries({
@NamedQuery(
name = "getAllTrainees",
query = "SELECT t FROM Trainee AS t ORDER BY t.id DESC"
),
@NamedQuery(
name = "getAllTraineesCount",
query = "SELECT COUNT(t) FROM Trainee AS t"
),
@NamedQuery(
name = "checkUsername",
query = "SELECT COUNT(t) FROM Trainee AS t WHERE t.username = :username"
),
@NamedQuery(
name = "checkLoginUsernameAndPassword",
query = "SELECT t FROM Trainee AS t WHERE t.username = :username AND t.password = :password"
)
})
@Entity
public class Trainee {
@Id
@Column(name = "id")
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer id;
@Column(name = "username", nullable = false)
private String username;
@Column(name = "password", length = 64, nullable = false)
private String password;
@Column(name = "created_at", nullable = false)
private Timestamp created_at;
@Column(name = "updated_at", nullable = false)
private Timestamp updated_at;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public Timestamp getCreated_at() {
return created_at;
}
public void setCreated_at(Timestamp created_at) {
this.created_at = created_at;
}
public Timestamp getUpdated_at() {
return updated_at;
}
public void setUpdated_at(Timestamp updated_at) {
this.updated_at = updated_at;
}
}
WorkoutReport.java
package models;
import java.sql.Date;
import java.sql.Timestamp;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.Lob;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
@Table(name = "workoutreports")
@NamedQueries({
@NamedQuery(
name = "getAllReports",
query = "SELECT w FROM WorkoutReport AS w ORDER BY w.id DESC"
),
@NamedQuery(
name = "getAllReportsCount",
query = "SELECT COUNT(w) FROM WorkoutReport AS w"
)
})
@Entity
public class WorkoutReport {
@Id
@Column(name = "id")
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer id;
@ManyToOne
@JoinColumn(name = "trainee_id", nullable = false)
private Trainee trainee;
@Column(name = "body_part", nullable = false)
private String body_part;
@Column(name = "menu", nullable = false)
private String menu;
@Column(name = "rep", nullable = false)
private Integer rep;
@Column(name = "sets", nullable = false)
private Integer sets;
@Column(name = "intervals", nullable = false)
private Integer intervals;
@Lob
@Column(name = "review", nullable = false)
private String review;
@Column(name = "report_date", nullable = false)
private Date report_date;
@Column(name = "created_at", nullable = false)
private Timestamp created_at;
@Column(name = "updated_at", nullable = false)
private Timestamp updated_at;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public Trainee getTrainee() {
return trainee;
}
public void setTrainee(Trainee trainee) {
this.trainee = trainee;
}
public String getBody_part() {
return body_part;
}
public void setBody_part(String body_part) {
this.body_part = body_part;
}
public String getMenu() {
return menu;
}
public void setMenu(String menu) {
this.menu = menu;
}
public Integer getRep() {
return rep;
}
public void setRep(Integer rep) {
this.rep = rep;
}
public Integer getSets() {
return sets;
}
public void setSets(Integer sets) {
this.sets = sets;
}
public Integer getIntervals() {
return intervals;
}
public void setIntervals(Integer intervals) {
this.intervals = intervals;
}
public String getReview() {
return review;
}
public void setReview(String review) {
this.review = review;
}
public Date getReport_date() {
return report_date;
}
public void setReport_date(Date report_date) {
this.report_date = report_date;
}
public Timestamp getCreated_at() {
return created_at;
}
public void setCreated_at(Timestamp created_at) {
this.created_at = created_at;
}
public Timestamp getUpdated_at() {
return updated_at;
}
public void setUpdated_at(Timestamp updated_at) {
this.updated_at = updated_at;
}
}
DBUtil.java
package utils;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
public class DBUtil {
private static final String PERSISTENCE_UNIT_NAME = "workout_diary_system";
private static EntityManagerFactory emf;
public static EntityManager createEntityManager() {
return getEntityManagerFactory().createEntityManager();
}
public static EntityManagerFactory getEntityManagerFactory() {
if(emf == null) {
emf = Persistence.createEntityManagerFactory(PERSISTENCE_UNIT_NAME);
}
return emf;
}
}
persistence.xml
<?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="workout_diary_system" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
<class>models.Trainee</class>
<class>models.WorkoutReport</class>
<properties>
<property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver"/>
<property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost/workout_diary_system?useSSL=false&useUnicode=true&characterEncoding=utf8"/>
<property name="javax.persistence.jdbc.user" value="mk"/>
<property name="javax.persistence.jdbc.password" value="***"/>
<property name="javax.persistence.schema-generation.database.action" value="create"/>
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5Dialect"/>
<property name="hibernate.show_sql" value="true"/>
<property name="hibernate.format_sql" value="true"/>
</properties>
</persistence-unit>
</persistence>
pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>jp.example</groupId>
<artifactId>workout_diary_system</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<build>
<sourceDirectory>src</sourceDirectory>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>3.0.0</version>
<configuration>
<warSourceDirectory>WebContent</warSourceDirectory>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.45</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>5.2.13.Final</version>
</dependency>
<dependency>
<groupId>org.apache.taglibs</groupId>
<artifactId>taglibs-standard-impl</artifactId>
<version>1.2.5</version>
</dependency>
<dependency>
<groupId>javax.servlet.jsp.jstl</groupId>
<artifactId>javax.servlet.jsp.jstl-api</artifactId>
<version>1.2.1</version>
</dependency>
</dependencies>
</project>
自分で試したこと
・persistence.xmlとpom.xmlのスペル確認
・エンティティクラスのスペルミスチェック
コードの量が多くなってしまい、申し訳ありません。
その他に必要な情報がありましたら、お声かけください。
ご回答、アドバイスお待ちしております。よろしくお願いいたします。
0