我看一下spring-data-jpa(实际上是我第一次使用entityManager)
我没有看到任何错误,但是entityManager似乎没有为实体类Account
生成一个表。这是我在maven main / resources / META-INF文件夹中的应用程序上下文(project-model-config.xml)
<bean id="propertyConfigurer"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>classpath:mysql.hibernate.properties</value>
<value>classpath:mysql.jdbc.properties</value>
<!--<value>classpath:liquibase.properties</value>-->
</list>
</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="transactionManger" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory"/>
</bean>
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property name="jpaVendorAdapter">
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
<!--<property name="generateDdl" value="true" />-->
</bean>
</property>
<property name="packagesToScan" value="com.bla.bla.model.domain"/>
<property name="persistenceUnitName" value="default"/>
<property name="jpaProperties">
<props>
<prop key="hibernate.dialect">${hibernate.dialect}</prop>
<prop key="hibernate.show_sql">${hibernate.show_sql}</prop>
<prop key="hibernate.format_sql">${hibernate.format_sql}</prop>
<prop key="hibernate.hbm2ddl.auto">${hibernate.hbm2ddl.auto}</prop>
</props>
</property>
</bean>
<jpa:repositories base-package="com.bla.bla.model.dao"/>
persistence.xml(main / resources / META-INF中project-model-config.xml的兄弟)也看起来像这样
<persistence xmlns="http://java.sun.com/xml/ns/persistence" version="2.0">
<persistence-unit name="default" transaction-type="RESOURCE_LOCAL" />
</persistence>
属性mysql.hibernate.properties/ mysql.jdbc.properties
hibernate.dialect=org.hibernate.dialect.MySQLDialect
hibernate.show_sql=false
hibernate.format_sql=false
hibernate.hbm2ddl.auto=create
jdbc.driverClassName=com.mysql.jdbc.Driver
jdbc.username=root
jdbc.password=mypass
jdbc.url=jdbc:mysql://localhost:3306/projectjava
包com.bla.bla.model.domain包含实体帐户
import java.io.Serializable;
import java.util.Date;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
@Entity
@Table(name = "account")
public class Account implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@Basic(optional = false)
@Column(name = "account_id")
private Long ID;
@Basic(optional = false)
@Column(name = "name")
}
成功构建(maven)后,没有生成表格。我甚至使用简单的断言添加了一个测试。
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {"classpath:META-INF/project-model-config.xml"})
public class AccountDAOTest {
@Test
public void testSetup(){
Assert.assertTrue(true);
}
}
所以我对如何获得生成的实体感到困惑,我无法理解为什么它不能生成。 任何人都可以在这看到问题吗?