Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/hibernate/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
JPA、Hibernate和Spring集成:表不';不存在错误_Spring_Hibernate_Jpa - Fatal编程技术网

JPA、Hibernate和Spring集成:表不';不存在错误

JPA、Hibernate和Spring集成:表不';不存在错误,spring,hibernate,jpa,Spring,Hibernate,Jpa,我刚刚开始学习JPA,我有一个使用hibernate的spring应用程序。 我试图通过在mysql数据库中插入一个简单的日期来进行测试,但我收到了以下错误消息: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table 'banquedb.clients' doesn't exist 这是我的测试代码: public class Test { public static void main(String[] ar

我刚刚开始学习JPA,我有一个使用hibernate的spring应用程序。 我试图通过在mysql数据库中插入一个简单的日期来进行测试,但我收到了以下错误消息:

com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table 'banquedb.clients' doesn't exist
这是我的测试代码:

public class Test {
    public static void main(String[] args) {
        ClassPathXmlApplicationContext context = 
                new ClassPathXmlApplicationContext(new String[]{"applicationContext.xml"});
        IBanqueService service = (IBanqueService) context.getBean("service");
        service.addClient(new Client("Ichigo", "AD1"));
        service.addClient(new Client("Kirito", "AD2"));
    }
}
这些是我的应用程序文件:

persistence.xml:

<persistence-unit name="sample" transaction-type="RESOURCE_LOCAL">
  <provider>org.hibernate.ejb.HibernatePersistence</provider>
  <properties>
    <property name="hibernate.show_sql" value="true"/>
    <property name="hibernate.hbm2ddl.auto" value="create"/>
   </properties>
  </persistence-unit>
</persistence>

org.hibernate.ejb.HibernatePersistence
applicationContext.xml

<bean id="dao" class="org.gestion.banque.dao.BanqueDAOImpl"></bean>
    <bean id="service" class="org.gestion.banque.service.BanqueServiceImpl">
        <property name="dao" ref="dao"></property>
    </bean>
    <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
        <property name="driverClassName" value="com.mysql.jdbc.Driver"></property>
        <property name="url" value="jdbc:mysql://localhost:3306/banquedb"></property>
        <property name="username" value="root"></property>
        <property name="password" value=""></property>
    </bean>
    <bean id="persistenceUnitManager" class="org.springframework.orm.jpa.persistenceunit.DefaultPersistenceUnitManager">
        <property name="persistenceXmlLocations">
            <list>
                <value>classpath*:META-INF/persistence.xml</value>
            </list>
        </property>
        <property name="defaultDataSource" ref="dataSource"></property>
    </bean>
    <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
        <property name="persistenceUnitManager" ref="persistenceUnitManager"></property>
        <property name="persistenceUnitName" value="sample"></property>
    </bean>
    <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
        <property name="entityManagerFactory" ref="entityManagerFactory"></property>
    </bean>
    <tx:annotation-driven transaction-manager="transactionManager"/>
    <context:annotation-config></context:annotation-config>

classpath*:META-INF/persistence.xml
Client.java

@Entity
@Table(name="CLIENTS")
public class Client implements Serializable {
    @Id
    @GeneratedValue(strategy=GenerationType.IDENTITY)
    private Long codeClient;
    private String nomClient;
    private String adresseClient;
    @OneToMany(mappedBy="client",fetch=FetchType.LAZY)
    private Collection<Compte> comptes;
    public Long getCodeClient() {
        return codeClient;
    }
    public void setCodeClient(Long codeClient) {
        this.codeClient = codeClient;
    }
    public String getNomClient() {
        return nomClient;
    }
    public void setNomClient(String nomClient) {
        this.nomClient = nomClient;
    }
    public String getAdresseClient() {
        return adresseClient;
    }
    public void setAdresseClient(String adresseClient) {
        this.adresseClient = adresseClient;
    }
    public Collection<Compte> getComptes() {
        return comptes;
    }
    public void setComptes(Collection<Compte> comptes) {
        this.comptes = comptes;
    }
    public Client() {
        super();
    }
    public Client(String nomClient, String adresseClient) {
        super();
        this.nomClient = nomClient;
        this.adresseClient = adresseClient;
    }

}
@实体
@表(name=“客户”)
公共类客户端实现可序列化{
@身份证
@GeneratedValue(策略=GenerationType.IDENTITY)
私人长期客户;
私有字符串客户端;
私有字符串地址客户端;
@OneToMany(mappedBy=“client”,fetch=FetchType.LAZY)
私人收藏公司;
公共长getCodeClient(){
返回客户;
}
public void setCodeClient(长codeClient){
this.codeClient=codeClient;
}
公共字符串getNomClient(){
返回客户;
}
public void setNomClient(字符串nomClient){
this.nomClient=nomClient;
}
公共字符串getAddresseClient(){
返回给客户;
}
public void setAddresseClient(字符串AddresseClient){
this.adresseClient=adresseClient;
}
公共集合getComptes(){
返回薪酬;
}
公共作废集合费用(集合费用){
这个。comptes=comptes;
}
公共客户机(){
超级();
}
公共客户端(字符串nomClient、字符串adresseClient){
超级();
this.nomClient=nomClient;
this.adresseClient=adresseClient;
}
}

我建议在
客户机
实体类中将表名更改为正确的大小写


使用
@Table(name=“clients”)
而不是
@Table(name=“clients”)

谢谢,但为什么
@Table(name=“clients”)
不起作用呢?在MySQL中,数据库对应于数据目录中的目录。数据库中的每个表至少对应于数据库目录中的一个文件。因此,底层操作系统的大小写敏感度在数据库和表名的大小写敏感度中起着重要作用。