Hallo,
ich nutze in einem neuen Projekt MariaDB und habe einige Fehlermeldungen, die ich zuvor mit MySQL nicht erhalten habe.
1) Warum werden denn zwei Dialekte geladen? In der Persistance.xml habe ich den mysql dialekt angegeben.
2) Warum wird der Befehl "alter table" ausgeführt? In der Persistance.xml gebe ich "create" an.
Die Fehler:
User:
UserRole:
persistance.xml:
wildfly standalone-full.xml
ich nutze in einem neuen Projekt MariaDB und habe einige Fehlermeldungen, die ich zuvor mit MySQL nicht erhalten habe.
1) Warum werden denn zwei Dialekte geladen? In der Persistance.xml habe ich den mysql dialekt angegeben.
2) Warum wird der Befehl "alter table" ausgeführt? In der Persistance.xml gebe ich "create" an.
Die Fehler:
Code:
...
16:41:50,572 INFO [org.hibernate.dialect.Dialect] (ServerService Thread Pool -- 68) HHH000400: Using dialect: org.hibernate.dialect.MySQLDialect
16:41:50,783 INFO [org.hibernate.hql.internal.ast.ASTQueryTranslatorFactory] (ServerService Thread Pool -- 68) HHH000397: Using ASTQueryTranslatorFactory
16:41:50,999 INFO [org.hibernate.dialect.Dialect] (ServerService Thread Pool -- 69) HHH000400: Using dialect: org.hibernate.dialect.H2Dialect
16:41:51,001 WARN [org.hibernate.dialect.H2Dialect] (ServerService Thread Pool -- 69) HHH000431: Unable to determine H2 database version, certain features may not work
16:41:51,018 INFO [org.hibernate.hql.internal.ast.ASTQueryTranslatorFactory] (ServerService Thread Pool -- 69) HHH000397: Using ASTQueryTranslatorFactory
16:41:51,437 INFO [org.hibernate.tool.hbm2ddl.SchemaExport] (ServerService Thread Pool -- 68) HHH000227: Running hbm2ddl schema export
16:41:51,447 INFO [stdout] (ServerService Thread Pool -- 68) Hibernate: alter table UserRole drop foreign key FK_bjerr6404757aj7n3f7w39p26
16:41:51,461 ERROR [org.hibernate.tool.hbm2ddl.SchemaExport] (ServerService Thread Pool -- 68) HHH000389: Unsuccessful: alter table UserRole drop foreign key FK_bjerr6404757aj7n3f7w39p26
16:41:51,462 ERROR [org.hibernate.tool.hbm2ddl.SchemaExport] (ServerService Thread Pool -- 68) Table 'projecttutorials.userrole' doesn't exist
16:41:51,462 INFO [stdout] (ServerService Thread Pool -- 68) Hibernate: drop table if exists User
16:41:51,464 INFO [stdout] (ServerService Thread Pool -- 68) Hibernate: drop table if exists UserRole
16:41:51,465 INFO [stdout] (ServerService Thread Pool -- 68) Hibernate: create table User (userId integer not null auto_increment, isEnabled bit not null, password varchar(255), userName varchar(255), primary key (userId))
16:41:51,639 INFO [stdout] (ServerService Thread Pool -- 68) Hibernate: create table UserRole (userRoleId integer not null auto_increment, userRoleName varchar(255), userid integer, primary key (userRoleId))
16:41:51,838 INFO [stdout] (ServerService Thread Pool -- 68) Hibernate: alter table UserRole add constraint FK_bjerr6404757aj7n3f7w39p26 foreign key (userid) references User (userId)
16:41:51,989 INFO [org.hibernate.tool.hbm2ddl.SchemaExport] (ServerService Thread Pool -- 68) HHH000230: Schema export complete
...
User:
Java:
@Entity
public class User implements Serializable {
/**
*
*/
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
private int userId;
private String userName;
private String password;
private boolean isEnabled;
@OneToMany(fetch=FetchType.EAGER, cascade=CascadeType.ALL, orphanRemoval=true)
@JoinColumn(name = "userid")
private List<UserRole> userRoles = new ArrayList<UserRole>();
public int getId() {
return userId;
}
public void setId(int id) {
this.userId = 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 boolean isEnabled() {
return isEnabled;
}
public void setEnabled(boolean isEnabled) {
this.isEnabled = isEnabled;
}
public int getUserId() {
return userId;
}
public void setUserId(int userId) {
this.userId = userId;
}
public List<UserRole> getUserRoles() {
return userRoles;
}
public void setUserRoles(List<UserRole> userRoles) {
this.userRoles = userRoles;
}
}
UserRole:
Java:
@Entity
public class UserRole implements Serializable{
/**
*
*/
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
private int userRoleId;
private String userRoleName;
public int getUserRoleId() {
return userRoleId;
}
public void setUserRoleId(int userRoleId) {
this.userRoleId = userRoleId;
}
public String getUserRoleName() {
return userRoleName;
}
public void setUserRoleName(String userRoleName) {
this.userRoleName = userRoleName;
}
}
persistance.xml:
Code:
<?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="ProjectTutorialsEJB">
<jta-data-source>java:jboss/datasources/ProjectTutorialsAppDS</jta-data-source>
<properties>
<property name="hibernate.hbm2ddl.auto" value="create"/>
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/>
<property name="hibernate.show_sql" value="true"/>
</properties>
</persistence-unit>
</persistence>
wildfly standalone-full.xml
Code:
<subsystem xmlns="urn:jboss:domain:datasources:3.0">
<datasources>
<datasource jndi-name="java:jboss/datasources/ExampleDS" pool-name="ExampleDS" enabled="true" use-java-context="true">
<connection-url>jdbc:h2:mem:test;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE</connection-url>
<driver>h2</driver>
<security>
<user-name>sa</user-name>
<password>sa</password>
</security>
</datasource>
<datasource jta="true" jndi-name="java:jboss/datasources/ProjectTutorialsAppDS" pool-name="ProjectTutorialsAppDS" enabled="true" use-ccm="true">
<connection-url>jdbc:mariadb://localhost:3306/projecttutorials</connection-url>
<driver-class>org.mariadb.jdbc.Driver</driver-class>
<driver>mariadb-java-client-1.2.3.jar</driver>
<security>
<user-name>pt-user</user-name>
<password>pt-personal-pw</password>
</security>
</datasource>
<drivers>
<driver name="h2" module="com.h2database.h2">
<xa-datasource-class>org.h2.jdbcx.JdbcDataSource</xa-datasource-class>
</driver>
</drivers>
</datasources>
</subsystem>
Zuletzt bearbeitet: