Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

spring + hibernate integration Table "table_name " is missing

I'm integrate spring with hibernate , I'm using dropwizard configaration files as : persistence file have the configuration files are in resources folder no issue with loading xml files. There is issue with found table . persistence.xml file as :

<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>

In spring application config xml as : there I show only hibernate configuration

<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>

Table User missing

 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

Please anyone help me how can I resolve this error. I want to configuration of spring with hibernate.I thing it is connect to database but can't found table. Table name and colume name exactly same. Database name also correct and no issue with username and password of database .

like image 768
Anuj Dhiman Avatar asked Mar 21 '16 10:03

Anuj Dhiman


1 Answers

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
}
like image 96
Anuj Dhiman Avatar answered Nov 14 '22 21:11

Anuj Dhiman