使用Hibernate和Jersey

时间:2016-08-15 08:46:46

标签: java mysql hibernate jersey dropwizard

我第一次尝试使用Jersey和Hibernate和Dropwizard,当我尝试在本地机器上运行Jersey服务器时,我遇到了这个异常:

  

线程中的异常" main" MultiException [com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException:未知数据库' mydb'

这是我的hibernate.cfg.xml:

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-configuration SYSTEM 
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">

<hibernate-configuration>
   <session-factory>
        <property name="hibernate.dialect"> org.hibernate.dialect.MySQLDialect </property>
        <property name="hibernate.connection.driver_class"> com.mysql.jdbc.Driver </property>
        <!-- Assume test is the database name -->
        <property name="hibernate.connection.url"> jdbc:mysql://localhost/mydb </property>
        <property name="hibernate.connection.username"> root </property>
        <property name="hibernate.connection.password"> </property>
        <!-- List of XML mapping files -->
        <mapping class="annotations.Person"></mapping>       
    </session-factory>
</hibernate-configuration>

泽西岛的config.yml包含这一部分:

# Database settings.
database:
    # the name of the JDBC driver, mysql in our case
    driverClass: com.mysql.jdbc.Driver
    # the username
    user: root
    # the password
    password: 
    # the JDBC URL; the database is called DWGettingStarted
    url: jdbc:mysql://localhost:3306/mydb
    # any properties specific to your JDBC driver:
    properties:
      charSet: UTF-8
      hibernate.dialect: org.hibernate.dialect.MySQLDialect

      # the maximum amount of time to wait on an empty pool before throwing an exception
      maxWaitForConnection: 1s

      # the SQL query to run when validating a connection's liveness
      validationQuery: "/* MyApplication Health Check */ SELECT 1"

      # the minimum number of connections to keep open
      minSize: 8

      # the maximum number of connections to keep open
      maxSize: 32

      # whether or not idle connections should be validated
      checkConnectionWhileIdle: false

现在数据库本身就是一个名为mydb.mwb的文件,我甚至不知道它应该在哪里找到连接才能成功。我使用Xampp for MySql。

我需要做什么才能识别数据库文件?我应该把它放在Eclipse项目的根文件夹中吗?

1 个答案:

答案 0 :(得分:0)

在您的情况下,mydb是架构在您的mysql数据库中不可用。为了这, 您需要在mysql中导入mydb.mwb。

这是一个教程:How to import the mwb file in mysql

创建mydb架构后,希望您可以成功运行项目。