версия wildfly: wildfly-15 Версия Hibernate: Hibernate-5
<datasource jndi-name="java:jboss/datasources/MySqlDS" pool-name="MySqlDS" spy="true" tracking="true" enlistment-trace="true" statistics-enabled="true">
<connection-url>jdbc:mysql://localhost:3306/sample</connection-url>
<driver-class>com.mysql.cj.jdbc.Driver</driver-class>
<datasource-class>com.mysql.cj.jdbc.MysqlDataSource</datasource-class>
<connection-property name="useSSL">
false
</connection-property>
<connection-property name="characterEncoding">
UTF-8
</connection-property>
<connection-property name="serverTimezone">
GMT+8
</connection-property>
<driver>mysql</driver>
<security>
<user-name>sample</user-name>
<password>sample</password>
</security>
<validation>
<valid-connection-checker class-name="org.jboss.jca.adapters.jdbc.extensions.mysql.MySQLValidConnectionChecker"/>
<background-validation>true</background-validation>
<exception-sorter class-name="org.jboss.jca.adapters.jdbc.extensions.mysql.MySQLExceptionSorter"/>
</validation>
<statement>
<share-prepared-statements>true</share-prepared-statements>
</statement>
</datasource>
Объект:
@Entity
@Table(schema = "sample", name="person")
@Data
public class Person implements Serializable {
private static final long serialVersionUID = 1L;
/**
* primary key and increment strategy
*/
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
private Integer personId;
/**
* Field Constraint: no-null、length=32
*/
@Column(nullable=false,length=32)
private String name;
@Column(nullable=false)
private Integer age;
@Temporal(value=TemporalType.DATE)
private Date birthday;
}
persitence.xml:
<persistence-unit name="persistenceUnit">
<jta-data-source>java:jboss/datasources/MySqlDS</jta-data-source>
<properties>
<property name="hibernate.show_sql" value="true" />
<property name="hibernate.format_sql" value="true"/>
<property name="hibernate.hbm2ddl.auto" value="update"/>
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQL8Dialect"/>
</properties>
</persistence-unit>
Информация об ошибке:
18:25:26,417 WARN [org.hibernate.tool.schema.internal.ExceptionHandlerLoggedImpl] (ServerService Thread Pool -- 11) GenerationTarget encountered exception accepting command : Error executing DDL "
insert into hibernate_sequence values ( 1 )" via JDBC Statement: org.hibernate.tool.schema.spi.CommandAcceptanceException: Error executing DDL "
insert into hibernate_sequence values ( 1 )" via JDBC Statement
at org.hibernate.tool.schema.internal.exec.GenerationTargetToDatabase.accept(GenerationTargetToDatabase.java:67)
at org.hibernate.tool.schema.internal.AbstractSchemaMigrator.applySqlString(AbstractSchemaMigrator.java:559)
at org.hibernate.tool.schema.internal.AbstractSchemaMigrator.applySqlStrings(AbstractSchemaMigrator.java:504)
at org.hibernate.tool.schema.internal.AbstractSchemaMigrator.createTable(AbstractSchemaMigrator.java:277)
at org.hibernate.tool.schema.internal.GroupedSchemaMigratorImpl.performTablesMigration(GroupedSchemaMigratorImpl.java:71)
at org.hibernate.tool.schema.internal.AbstractSchemaMigrator.performMigration(AbstractSchemaMigrator.java:207)
at org.hibernate.tool.schema.internal.AbstractSchemaMigrator.doMigration(AbstractSchemaMigrator.java:114)
at org.hibernate.tool.schema.spi.SchemaManagementToolCoordinator.performDatabaseAction(SchemaManagementToolCoordinator.java:183)
at org.hibernate.tool.schema.spi.SchemaManagementToolCoordinator.process(SchemaManagementToolCoordinator.java:72)
at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:310)
at org.hibernate.boot.internal.SessionFactoryBuilderImpl.build(SessionFactoryBuilderImpl.java:467)
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:939)
at org.jboss.as.jpa.hibernate5.TwoPhaseBootstrapImpl.build(TwoPhaseBootstrapImpl.java:44)
at org.jboss.as.jpa.service.PersistenceUnitServiceImpl$1$1.run(PersistenceUnitServiceImpl.java:170)
at org.jboss.as.jpa.service.PersistenceUnitServiceImpl$1$1.run(PersistenceUnitServiceImpl.java:128)
at org.wildfly.security.manager.WildFlySecurityManager.doChecked(WildFlySecurityManager.java:649)
at org.jboss.as.jpa.service.PersistenceUnitServiceImpl$1.run(PersistenceUnitServiceImpl.java:212)
at org.jboss.threads.ContextClassLoaderSavingRunnable.run(ContextClassLoaderSavingRunnable.java:35)
at org.jboss.threads.EnhancedQueueExecutor.safeRun(EnhancedQueueExecutor.java:1985)
at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.doRunTask(EnhancedQueueExecutor.java:1487)
at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1378)
at java.lang.Thread.run(Thread.java:748)
at org.jboss.threads.JBossThread.run(JBossThread.java:485)
Caused by: java.sql.SQLException: No database selected
Проблема: Когда я настраиваю источник данных wildfly mysql, когда я вхожу в веб-интерфейс управления wildfly, я могу успешно протестировать источник данных, но когда я упаковываю проект ejb с помощью jpa configure в jar, то появляется информация об ошибкебывает, как я могу это решить?Спасибо