在hibernate.cfg.xml中
我正在使用MariaDBDialect类
<hibernate-configuration>
<session-factory>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost:3306/Book</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.connection.password"></property>
<property name="hibernate.connection.pool_size">1</property>
<property name="hibernate.current_session_context_class">thread</property>
<property name="hibernate.show_sql">true</property>
<property name="hibernate.dialect">org.hibernate.dialect.MariaDBDialect</property>
<mapping class="com.yazeed.brain.dto.User" />
</session-factory>
运行代码时,我在控制台中收到此错误
Exception in thread "main" org.hibernate.service.spi.ServiceException: Unable to create requested service [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment]
Caused by: org.hibernate.exception.SQLGrammarException: Error calling Driver#connect
Caused by: java.sql.SQLSyntaxErrorException: Unknown database 'book'
答案 0 :(得分:0)
您应该使用org.hibernate.dialect.MySQLDialect,因为MariaDB与mysql 100%兼容。
答案 1 :(得分:0)
您也可以使用package com.whatamidoingwithmylife.splitbill;
import android.arch.persistence.room.ColumnInfo;
import android.arch.persistence.room.Entity;
import android.arch.persistence.room.PrimaryKey;
@Entity(tableName = "Restaurants")
public class Restaurant {
@PrimaryKey(autoGenerate = true)
private int ResID;
@ColumnInfo(name = "ResName")
private String Name;
@ColumnInfo(name = "ResPicture")
private int PictureID;
public Restaurant(String Name, int PictureID) {
this.Name = Name;
this.PictureID = PictureID;
}
public int getPictureID() {
return PictureID;
}
public void setPictureID(int pictureID) {
PictureID = pictureID;
}
public String getName() {
return Name;
}
public int getResID() {
return ResID;
}
public void setResID(int resID) {
ResID = resID;
}
public void setName(String name) {
Name = name;
}
代替org.hibernate.dialect.MariaDB53Dialect
。