Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/spring-mvc/2.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
hibernate.hbm2ddl.auto不';不要创建表_Hibernate_Spring Mvc_Jpa_Jboss - Fatal编程技术网

hibernate.hbm2ddl.auto不';不要创建表

hibernate.hbm2ddl.auto不';不要创建表,hibernate,spring-mvc,jpa,jboss,Hibernate,Spring Mvc,Jpa,Jboss,我遇到了一些麻烦,希望有人能帮助我:hibernate不会创造我。 这里是我的配置文件: datasource config.xml <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns

我遇到了一些麻烦,希望有人能帮助我:hibernate不会创造我。 这里是我的配置文件: datasource config.xml

<?xml version="1.0" encoding="UTF-8"?>
   <beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:tx="http://www.springframework.org/schema/tx"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd         
                    http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd">


    <bean 
        class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
        <property name="location">
            <value>classpath:database.properties</value>
        </property>
    </bean>

    <bean id="dataSource" 
            class="org.springframework.jdbc.datasource.DriverManagerDataSource">
        <property name="driverClassName" value="${jdbc.driverClassName}" />
        <property name="url" value="${jdbc.url}" />
        <property name="username" value="${jdbc.username}" />
        <property name="password" value="${jdbc.password}" />

    </bean>


    <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">

         <property name="jpaProperties">
            <props>
                <prop key="hibernate.hbm2ddl.auto">create</prop>
            </props>
        </property>


            <property name="jpaVendorAdapter">
                    <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
                            <property name="showSql" value="true" />
                            <property name="generateDdl" value="true" />
                            <property name="databasePlatform" value="org.hibernate.dialect.MySQLDialect" />

                    </bean>
            </property> 
            <property name="dataSource" ref="dataSource" />
    </bean>

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

    <tx:annotation-driven transaction-manager="transactionManager" />

    <bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor" /> 
<persistence-unit name="UsersBD" transaction-type="RESOURCE_LOCAL">

   <properties>
      <property name="jboss.as.jpa.managed" value="false"/>
   </properties>   
 </persistence-unit>

classpath:database.properties
创造

persistence.xml

<?xml version="1.0" encoding="UTF-8"?>
   <beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:tx="http://www.springframework.org/schema/tx"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd         
                    http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd">


    <bean 
        class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
        <property name="location">
            <value>classpath:database.properties</value>
        </property>
    </bean>

    <bean id="dataSource" 
            class="org.springframework.jdbc.datasource.DriverManagerDataSource">
        <property name="driverClassName" value="${jdbc.driverClassName}" />
        <property name="url" value="${jdbc.url}" />
        <property name="username" value="${jdbc.username}" />
        <property name="password" value="${jdbc.password}" />

    </bean>


    <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">

         <property name="jpaProperties">
            <props>
                <prop key="hibernate.hbm2ddl.auto">create</prop>
            </props>
        </property>


            <property name="jpaVendorAdapter">
                    <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
                            <property name="showSql" value="true" />
                            <property name="generateDdl" value="true" />
                            <property name="databasePlatform" value="org.hibernate.dialect.MySQLDialect" />

                    </bean>
            </property> 
            <property name="dataSource" ref="dataSource" />
    </bean>

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

    <tx:annotation-driven transaction-manager="transactionManager" />

    <bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor" /> 
<persistence-unit name="UsersBD" transaction-type="RESOURCE_LOCAL">

   <properties>
      <property name="jboss.as.jpa.managed" value="false"/>
   </properties>   
 </persistence-unit>

应用程序上下文:

<?xml version="1.0" encoding="UTF-8"?>
   <beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:context="http://www.springframework.org/schema/context"
    xsi:schemaLocation="http://www.springframework.org/schema/beans 
    http://www.springframework.org/schema/beans/spring-beans.xsd
    http://www.springframework.org/schema/context
    http://www.springframework.org/schema/context/spring-context-3.0.xsd">  

    <context:component-scan base-package="com.app" />

    <import resource="datasource-config.xml" />

 </beans>
package com.app.model;

import java.io.Serializable;
import java.util.Collection;
import javax.persistence.*;

@Entity(name="person")
@Table(name="PERSONS")
public class Person implements Serializable {


private static final long serialVersionUID = -4263067774169571725L;  

@Id
@GeneratedValue(strategy = GenerationType.TABLE)
private Long id;

private String name;

private String lastname;

@OneToMany(cascade = CascadeType.ALL, mappedBy = "personId")
private Collection<PersonsInf> infCollection;


public String getLastname() {
    return lastname;
}

public void setLastname(String lastname) {
    this.lastname = lastname;
}


public String getName() {
    return name;
}

public void setName(String name) {
    this.name = name;
}

public Long getId() {
    return id;
}

public void setId(Long id) {
    this.id = id;
}


public Collection<PersonsInf> getInfCollection() {
   return infCollection;
}

public void setInfCollection(Collection<PersonsInf> infCollection) {
    this.infCollection = infCollection;

}



}

实体:

<?xml version="1.0" encoding="UTF-8"?>
   <beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:context="http://www.springframework.org/schema/context"
    xsi:schemaLocation="http://www.springframework.org/schema/beans 
    http://www.springframework.org/schema/beans/spring-beans.xsd
    http://www.springframework.org/schema/context
    http://www.springframework.org/schema/context/spring-context-3.0.xsd">  

    <context:component-scan base-package="com.app" />

    <import resource="datasource-config.xml" />

 </beans>
package com.app.model;

import java.io.Serializable;
import java.util.Collection;
import javax.persistence.*;

@Entity(name="person")
@Table(name="PERSONS")
public class Person implements Serializable {


private static final long serialVersionUID = -4263067774169571725L;  

@Id
@GeneratedValue(strategy = GenerationType.TABLE)
private Long id;

private String name;

private String lastname;

@OneToMany(cascade = CascadeType.ALL, mappedBy = "personId")
private Collection<PersonsInf> infCollection;


public String getLastname() {
    return lastname;
}

public void setLastname(String lastname) {
    this.lastname = lastname;
}


public String getName() {
    return name;
}

public void setName(String name) {
    this.name = name;
}

public Long getId() {
    return id;
}

public void setId(Long id) {
    this.id = id;
}


public Collection<PersonsInf> getInfCollection() {
   return infCollection;
}

public void setInfCollection(Collection<PersonsInf> infCollection) {
    this.infCollection = infCollection;

}



}
package com.app.model;
导入java.io.Serializable;
导入java.util.Collection;
导入javax.persistence.*;
@实体(名称=“人”)
@表(name=“PERSONS”)
公共类Person实现可序列化{
私有静态最终长SerialVersionId=-426306774169571725L;
@身份证
@GeneratedValue(策略=GenerationType.TABLE)
私人长id;
私有字符串名称;
私有字符串lastname;
@OneToMany(cascade=CascadeType.ALL,mappedBy=“personId”)
私人收藏;
公共字符串getLastname(){
返回姓氏;
}
public void setLastname(字符串lastname){
this.lastname=lastname;
}
公共字符串getName(){
返回名称;
}
公共void集合名(字符串名){
this.name=名称;
}
公共长getId(){
返回id;
}
公共无效集合id(长id){
this.id=id;
}
公共集合getInfCollection(){
退货和收款;
}
公共void setInfCollection(Collection infCollection){
this.infCollection=infCollection;
}
}

因此,当我运行jboss服务器并查看mysql db时,它是空的。

您可以显示调试语句吗?您可以在persistence.xml中声明数据源属性值,而不是在beans.xml中定义数据源属性值。我没有看到调用datasource id,所以可能它没有设置与数据库的任何连接。这里是日志文件的链接,耐心地等待您的回答,thxMy目标是配置jpa,没有持久性xml,只有datasource-config.xml?或者这是不可能的?我甚至遇到了这个问题,但不清楚bean id“datasource”的初始化,所以将所有数据库信息都放在persistence.xml中。而且我从未为jpa使用过任何datasource-config.xml(仅persistence.xml)。您可以共享他们使用datasource-config.xml的链接。