2

我有一些麻烦,希望有人帮助我:hibernate doesnt create mysql sceme。这是我的配置文件: 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" /> 

持久性.xml

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

}



}

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

4

0 回答 0