Mysql 未在数据库中创建表
我使用的是下面的hibernate配置,当我从Postman客户端调用create方法时,我得到的是SqlGrameRexception,而不是创建表并将值插入数据库。请检查下面的配置,并让我知道我可以做什么来创建一个表和更新它 配置文件-Mysql 未在数据库中创建表,mysql,hibernate,Mysql,Hibernate,我使用的是下面的hibernate配置,当我从Postman客户端调用create方法时,我得到的是SqlGrameRexception,而不是创建表并将值插入数据库。请检查下面的配置,并让我知道我可以做什么来创建一个表和更新它 配置文件- <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://
<?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"
xmlns:p="http://www.springframework.org/schema/p" xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd">
<bean id="dbPropertyConfigurer"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>/WEB-INF/db_config.properties</value>
</list>
</property>
</bean>
<!-- Database Properties -->
<bean id="dataSource"
class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close"
p:driverClass="${jdbc.driver.className}"
p:jdbcUrl="${jdbc.url}"
p:user="${jdbc.username}"
p:password="${jdbc.password}"
/>
<bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="dataSource">
<ref bean="dataSource" />
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">${jdbc.hibernate.dialect}</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hbm2ddl.auto">update</prop>
</props>
</property>
<property name="packagesToScan" value="com.entity" />
</bean>
<bean id="transactionManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<tx:annotation-driven transaction-manager="transactionManager" />
</beans>
/WEB-INF/db_config.properties
${jdbc.hibernate.dial}
真的
更新
Pojo类包含JPA注释@Id、@Column用于定义列和主键,以及@Entity和@Table用于定义表和实体值。实际上,所提到的配置是不正确的
<prop key="hbm2ddl.auto">update</prop>
更新
以上内容应该是-
<prop key="hibernate.hbm2ddl.auto">update</prop>
更新
如果该表不存在并且您想通过hibernate创建它,那么您应该将
hbm2ddl
值设置为create
(create
)我可能是错的,但是需要引用${jdbc.hibernate.dial}
进行评估吗?否,这不是因为如果我手动创建表,那么一切都正常。添加堆栈跟踪&触发休眠的代码operations@tharindu_DG谢谢你的帮助,但我找到了解决办法。