我使用Spring和Hibernet开发Java webapp。
我想声明外键,所以我需要使用INNODB引擎。我已经在datasource.XML上声明了它,但是这个表是由Hibernate使用MYSAM引擎自动创建的。
这是我的实体:
package com.atlantis.atecliente.model;
import java.util.List;
导入javax.persistence。*;
@Entity
@Table(name="Expediente")
public class Expediente {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private int codigo;
@ManyToOne
@JoinColumn(name = "tipoExpediente")
private TipoExpediente tipoExpediente;
@Column(length = 30)
private String estado;
public int getCodigo() {
return codigo;
}
public void setCodigo(int codigo) {
this.codigo = codigo;
}
public TipoExpediente getTipoExpediente() {
return tipoExpediente;
}
public void setTipoExpediente(TipoExpediente tipoExpediente) {
this.tipoExpediente = tipoExpediente;
}
public String getEstado() {
return estado;
}
public void setEstado(String estado) {
this.estado = estado;
}
}
这里是datasource.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" xmlns:jdbc="http://www.springframework.org/schema/jdbc"
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-3.1.xsd http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc.xsd">
<!-- <jdbc:embedded-database id="dataSource" />-->
<!-- data source for our database -->
<bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName"
value="com.mysql.jdbc.jdbc2.optional.MysqlDataSource" />
<property name="url" value="jdbc:mysql://SBPORTALPRE/atclientepre" />
<property name="username" value="********" />
<property name="password" value="********" />
</bean>
<bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property name="packagesToScan">
<list>
<value>com.atlantis.atecliente.model</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="dialect">org.hibernate.dialect.MySQL5InnoDBDialect</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.hbm2ddl.auto">update</prop>
</props>
</property>
</bean>
<tx:annotation-driven transaction-manager="transactionManager"/>
<bean id="transactionManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"/>
</bean>
</beans>
请帮忙吗?
答案 0 :(得分:0)
错误发生在
<prop key="dialect">org.hibernate.dialect.MySQL5InnoDBDialect</prop>
正确的行是:
<prop key="hibernate.dialect">org.hibernate.dialect.MySQL5InnoDBDialect</prop>
由于