请注意,此代码确实适用于普通 Spring,但不适用于 Spring Boot(v1.3.3),我是否缺少某些内容,因为这是从有效的 Spring 应用程序导入的。下面的代码来自spring boot应用程序
@Entity
@Table(name="project")
public class Project implements Serializable{
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
@Column(name="id")
private int id;
@Column(name="teamId")
private int teamId;
//private String Rentabiliteit;
@Column
//@Index(name="IProject_status",columnNames="Status")
private String status;
@Column
//@Index(name="IProject_naam",columnNames="Naam")
private String naam;
//public Prototype m_Prototype;
//public Team m_Team;
}
SQL
CREATE TABLE IF NOT EXISTS `project` (
`id` int(11) NOT NULL,
`teamId` int(11) DEFAULT NULL,
`status` varchar(255) DEFAULT NULL,
`naam` varchar(255) DEFAULT NULL
) ENGINE=InnoDB AUTO_INCREMENT=43 DEFAULT CHARSET=latin1;
ERROR
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException:
Unknown column 'project0_.team_id' in 'field list'
编辑:Application.yml
spring:
mvc:
view:
prefix: /WEB-INF/jsp/
suffix: .jsp
datasource:
url: jdbc:mysql://localhost:3306/oxyplast
username: oxyplastuser
password: oxyplastuserpw
jpa:
properties:
hibernate:
current_session_context_class: org.springframework.orm.hibernate4.SpringSessionContext
namingStrategy: org.hibernate.cfg.DefaultNamingStrategy
自 Spring-Boot 1.4 起
从1.4开始,因为切换到Hibernate 5,命名策略更新为SpringPhysicalNamingStrategy
which 应该非常接近至 1.3 默认值。
也可以看看:
以前的版本
Spring Boot 提供了ImprovedNamingStrategy作为默认命名策略,这使得 Hibernate 搜索team_id
列(从int teamId
场地)。由于您的表中不存在此列,这就是错误的原因。来自 Hibernate 文档:
改进的命名策略,更喜欢嵌入下划线而不是混合大小写名称
你有两个选择:
明确提供列名称 as @Column(name="teamId")
。曾经有一个bug在早期的 Boot 版本中,现在不再有此功能。
改变命名策略在 Spring Boot 属性中并告诉它使用EJB3NamingStrategy,它不会将camelCase转换为snake_case,而是保持原样。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)