2016-03-21 14 views
5

私は春をhibernateと統合しています。私はdropwizard設定ファイルを次のように使用しています:設定ファイルはリソースファイルにあります。見つかったテーブルに問題があります。 persistence.xmlのファイル:私だけspring + hibernate integrationテーブル "table_name"がありません

javax.persistence.PersistenceException: [PersistenceUnit: bfm] Unable to build EntityManagerFactory 
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1562) 
    ... 18 more 
Caused by: org.hibernate.HibernateException: Missing table: user 

が欠落した構成

<context:annotation-config /> 
    <context:component-scan base-package="com.bcits.parkingmanagement.model" /> 

    <jdbc:embedded-database id="dataSource" type="HSQL" /> 


    <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"> 
     <property name="persistenceXmlLocation" value="classpath:spring/persistence.xml" /> 
     <property name="dataSource" ref="dataSource"/> 
    </bean> 

    <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager"> 
     <property name="entityManagerFactory" ref="entityManagerFactory" /> 
    </bean> 

    <bean id="entityManager" 
     class="org.springframework.orm.jpa.support.SharedEntityManagerBean"> 
     <property name="entityManagerFactory" ref="entityManagerFactory" /> 
    </bean> 

テーブルユーザーが休止状態を示してあります誰:

春のアプリケーション設定XMLで
<persistence-unit name="bfm" transaction-type="RESOURCE_LOCAL" > 
<provider>org.hibernate.ejb.HibernatePersistence</provider> 
<class>com.bcits.parkingmanagement.model.User</class> 
    <exclude-unlisted-classes>true</exclude-unlisted-classes> 
<properties> 
     <!-- Configuring JDBC properties --> 
     <property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/anuj" /> 
     <property name="javax.persistence.jdbc.user" value="root" /> 
     <property name="javax.persistence.jdbc.password" value="root" /> 
     <property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver" /> 
</persistence-unit> 
</persistence> 

としてこのエラーを解決する方法を教えてください。私はhibernate.Iと一緒にデータベースに接続しているが、テーブルを見つけることができませんと春の構成にしたい。テーブル名とカラム名はまったく同じです。データベース名も正しく、データベースのユーザー名とパスワードに問題はありません。

+0

ユーザーモデルクラスを表示します。第二に。その中にAnujという名前のDBとuserという名前のテーブルがありますか?表(名= "ユーザー") パブリッククラスユーザー{ \t \tイド \t "@" 列(名前= "USER_ID")プライベート \t "@" "@" エンティティ "@" –

+0

はい int id; \t "@"列(name = "user_name") \tプライベートString name; // getter and setter} –

+0

メインポストを編集して新しいコンテンツを貼り付けます。 –

答えて

4
User model is: Here User is model name and user is table which have two column one is user_id and user_name. Issue is that i had used user instead of User in query. Because User is model name and user is table name .Correct model is given below 

@NamedQueries({ 
    @NamedQuery(name="getUserName" , query="select name from User") 
    }) 

@Entity 
@Table(name ="user") 
public class User { 
    @Id 
    @Column(name="user_id") 
    private int id; 
    @Column(name="user_name") 
    private String name; 

    //getter setter 
} 
関連する問題