休眠 @Column 注释不起作用

Bee*_*isy 1 sql-server hibernate jpa spring-boot

我有 SqlServer 2008 db 服务器,我使用spring boot+jpa(hibernate)访问数据库。

我已经在实体属性访问方法中添加了@Column 注释,例如:

@Basic
@Column(name = "AdminPickDate", nullable = true)
public Timestamp getAdminPickDate() {
    return adminPickDate;
}
Run Code Online (Sandbox Code Playgroud)

并且hibernate sql 输出显示列名没有使用注释@Colume 中的名称。

sql输出:

Hibernate: select ddforumart0_.articleid as articlei1_95_0_, ddforumart0_.admin_pick_date as admin_pi2_95_0_, ddforumart0_.article_title as article_3_95_0_, ddforumart0_.article_type as article_4_95_0_, ddforumart0_.at_who as at_who5_95_0_, ddforumart0_.brief as brief6_95_0_, ddforumart0_.classifyid as classify7_95_0_, ddforumart0_.classify_title as classify8_95_0_, ddforumart0_.come_from as come_fro9_95_0_, ddforumart0_.comment_count as comment10_95_0_, ddforumart0_.comment_date as comment11_95_0_, ddforumart0_.comment_enable as comment12_95_0_, ddforumart0_.config as config13_95_0_, ddforumart0_.content as content14_95_0_, ddforumart0_.create_by as create_15_95_0_, ddforumart0_.create_date as create_16_95_0_, ddforumart0_.del_flag as del_fla17_95_0_, ddforumart0_.img_url as img_url18_95_0_, ddforumart0_.is_anonymous as is_anon19_95_0_, ddforumart0_.is_del_allow as is_del_20_95_0_, ddforumart0_.is_hot as is_hot21_95_0_, ddforumart0_.isqa as isqa22_95_0_, ddforumart0_.is_top as is_top23_95_0_, ddforumart0_.like_count as like_co24_95_0_, ddforumart0_.modify_by as modify_25_95_0_, ddforumart0_.modify_date as modify_26_95_0_, ddforumart0_.pick_date as pick_da27_95_0_, ddforumart0_.plateid as plateid28_95_0_, ddforumart0_.plate_title as plate_t29_95_0_, ddforumart0_.qatype as qatype30_95_0_, ddforumart0_.tags as tags31_95_0_, ddforumart0_.user_code as user_co32_95_0_, ddforumart0_.user_infoid as user_in33_95_0_, ddforumart0_.user_name as user_na34_95_0_, ddforumart0_.view_count as view_co35_95_0_ from dd_forum_article ddforumart0_ where ddforumart0_.articleid=?
Run Code Online (Sandbox Code Playgroud)

我的代码中是否有一些错误的用法?

我的 pom.xml:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.didi.home.dao</groupId>
    <artifactId>didi-home-dao</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>

    <name>didi-home-dao</name>
    <description>didi home data producer</description>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.4.1.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>1.8</java.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>com.didi.home.model</groupId>
            <artifactId>didi-home-model</artifactId>
            <version>1.0.0-SNAPSHOT</version>
        </dependency>

        <dependency>
            <groupId>com.microsoft.sqlserver</groupId>
            <artifactId>sqljdbc4</artifactId>
            <version>4.0</version>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-jdbc</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>

    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>


</project>
Run Code Online (Sandbox Code Playgroud)

应用程序.yml

spring:
  datasource:
    url: jdbc:sqlserver://1.2.3.4:1433;databaseName=DB_DiDiWeb
    username: u
    password: mypwd
  jpa:
    show-sql: true
    hibernate:
      naming:
#        strategy: org.hibernate.cfg.EJB3NamingStrategy
#        strategy: org.hibernate.cfg.DefaultComponentSafeNamingStrategy
#        strategy: org.hibernate.cfg.DefaultNamingStrategy
#        strategy: org.hibernate.cfg.ImprovedNamingStrategy
#        strategy: org.springframework.boot.orm.jpa.hibernate.SpringNamingStrategy
Run Code Online (Sandbox Code Playgroud)

这是一个演示存储库:DdForumArticleRepository

package com.my.home.dao;

import com.didi.home.model.DdForumArticle;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Component;

/**
 * Created by jacks808@163.com on 2017/1/13.
 */
@Component
public interface DdForumArticleRepository extends JpaRepository<DdForumArticle, Integer> {
}
Run Code Online (Sandbox Code Playgroud)

实体代码:

package com.didi.home.model;

import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
import java.sql.Timestamp;

/**
 * Created by jacks808@163.com on 2017/1/13.
 */
// , schema = "dbo", catalog = "DB_DiDiWeb"
@Entity
@Table(name = "DD_Forum_Article")
public class DdForumArticle {
    private int articleId;
    private Integer articleType;
    private String articleTitle;
    private String content;
    private String brief;
    private String atWho;
    private String imgUrl;
    private String tags;
    private String config;
    private Integer viewCount;
    private Integer likeCount;
    private Integer commentCount;
    private Integer commentEnable;
    private Timestamp commentDate;
    private Integer isHot;
    private Integer isTop;
    private Integer isQa;
    private String qaType;
    private Timestamp pickDate;
    private Timestamp adminPickDate;
    private Integer plateId;
    private String plateTitle;
    private Integer classifyId;
    private String classifyTitle;
    private Integer userInfoId;
    private String userName;
    private String userCode;
    private Integer delFlag;
    private String createBy;
    private Timestamp createDate;
    private String modifyBy;
    private Timestamp modifyDate;
    private Integer isAnonymous;
    private Integer isDelAllow;
    private String comeFrom;

    @Id
    @Column(name = "ArticleID", nullable = false)
    public int getArticleId() {
        return articleId;
    }

    public void setArticleId(int articleId) {
        this.articleId = articleId;
    }

    @Basic
    @Column(name = "ArticleType", nullable = true)
    public Integer getArticleType() {
        return articleType;
    }

    public void setArticleType(Integer articleType) {
        this.articleType = articleType;
    }

    @Basic
    @Column(name = "ArticleTitle", nullable = true, length = 100)
    public String getArticleTitle() {
        return articleTitle;
    }

    public void setArticleTitle(String articleTitle) {
        this.articleTitle = articleTitle;
    }

    @Basic
    @Column(name = "Content", nullable = true, length = 2147483647)
    public String getContent() {
        return content;
    }

    public void setContent(String content) {
        this.content = content;
    }

    @Basic
    @Column(name = "Brief", nullable = true, length = 255)
    public String getBrief() {
        return brief;
    }

    public void setBrief(String brief) {
        this.brief = brief;
    }

    @Basic
    @Column(name = "AtWho", nullable = true, length = 2147483647)
    public String getAtWho() {
        return atWho;
    }

    public void setAtWho(String atWho) {
        this.atWho = atWho;
    }

    @Basic
    @Column(name = "ImgUrl", nullable = true, length = 2147483647)
    public String getImgUrl() {
        return imgUrl;
    }

    public void setImgUrl(String imgUrl) {
        this.imgUrl = imgUrl;
    }

    @Basic
    @Column(name = "Tags", nullable = true, length = 255)
    public String getTags() {
        return tags;
    }

    public void setTags(String tags) {
        this.tags = tags;
    }

    @Basic
    @Column(name = "Config", nullable = true, length = 2147483647)
    public String getConfig() {
        return config;
    }

    public void setConfig(String config) {
        this.config = config;
    }

    @Basic
    @Column(name = "ViewCount", nullable = true)
    public Integer getViewCount() {
        return viewCount;
    }

    public void setViewCount(Integer viewCount) {
        this.viewCount = viewCount;
    }

    @Basic
    @Column(name = "LikeCount", nullable = true)
    public Integer getLikeCount() {
        return likeCount;
    }

    public void setLikeCount(Integer likeCount) {
        this.likeCount = likeCount;
    }

    @Basic
    @Column(name = "CommentCount", nullable = true)
    public Integer getCommentCount() {
        return commentCount;
    }

    public void setCommentCount(Integer commentCount) {
        this.commentCount = commentCount;
    }

    @Basic
    @Column(name = "CommentEnable", nullable = true)
    public Integer getCommentEnable() {
        return commentEnable;
    }

    public void setCommentEnable(Integer commentEnable) {
        this.commentEnable = commentEnable;
    }

    @Basic
    @Column(name = "CommentDate", nullable = true)
    public Timestamp getCommentDate() {
        return commentDate;
    }

    public void setCommentDate(Timestamp commentDate) {
        this.commentDate = commentDate;
    }

    @Basic
    @Column(name = "IsHot", nullable = true)
    public Integer getIsHot() {
        return isHot;
    }

    public void setIsHot(Integer isHot) {
        this.isHot = isHot;
    }

    @Basic
    @Column(name = "IsTop", nullable = true)
    public Integer getIsTop() {
        return isTop;
    }

    public void setIsTop(Integer isTop) {
        this.isTop = isTop;
    }

    @Basic
    @Column(name = "IsQA", nullable = true)
    public Integer getIsQa() {
        return isQa;
    }

    public void setIsQa(Integer isQa) {
        this.isQa = isQa;
    }

    @Basic
    @Column(name = "QAType", nullable = true, length = 10)
    public String getQaType() {
        return qaType;
    }

    public void setQaType(String qaType) {
        this.qaType = qaType;
    }

    @Basic
    @Column(name = "PickDate", nullable = true)
    public Timestamp getPickDate() {
        return pickDate;
    }

    public void setPickDate(Timestamp pickDate) {
        this.pickDate = pickDate;
    }

    @Basic
    @Column(name = "AdminPickDate", nullable = true)
    public Timestamp getAdminPickDate() {
        return adminPickDate;
    }

    public void setAdminPickDate(Timestamp adminPickDate) {
        this.adminPickDate = adminPickDate;
    }

    @Basic
    @Column(name = "PlateID", nullable = true)
    public Integer getPlateId() {
        return plateId;
    }

    public void setPlateId(Integer plateId) {
        this.plateId = plateId;
    }

    @Basic
    @Column(name = "PlateTitle", nullable = true, length = 32)
    public String getPlateTitle() {
        return plateTitle;
    }

    public void setPlateTitle(String plateTitle) {
        this.plateTitle = plateTitle;
    }

    @Basic
    @Column(name = "ClassifyID", nullable = true)
    public Integer getClassifyId() {
        return classifyId;
    }

    public void setClassifyId(Integer classifyId) {
        this.classifyId = classifyId;
    }

    @Basic
    @Column(name = "ClassifyTitle", nullable = true, length = 32)
    public String getClassifyTitle() {
        return classifyTitle;
    }

    public void setClassifyTitle(String classifyTitle) {
        this.classifyTitle = classifyTitle;
    }

    @Basic
    @Column(name = "UserInfoID", nullable = true)
    public Integer getUserInfoId() {
        return userInfoId;
    }

    public void setUserInfoId(Integer userInfoId) {
        this.userInfoId = userInfoId;
    }

    @Basic
    @Column(name = "UserName", nullable = true, length = 32)
    public String getUserName() {
        return userName;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    @Basic
    @Column(name = "UserCode", nullable = true, length = 32)
    public String getUserCode() {
        return userCode;
    }

    public void setUserCode(String userCode) {
        this.userCode = userCode;
    }

    @Basic
    @Column(name = "DelFlag", nullable = true)
    public Integer getDelFlag() {
        return delFlag;
    }

    public void setDelFlag(Integer delFlag) {
        this.delFlag = delFlag;
    }

    @Basic
    @Column(name = "CreateBy", nullable = true, length = 32)
    public String getCreateBy() {
        return createBy;
    }

    public void setCreateBy(String createBy) {
        this.createBy = createBy;
    }

    @Basic
    @Column(name = "CreateDate", nullable = true)
    public Timestamp getCreateDate() {
        return createDate;
    }

    public void setCreateDate(Timestamp createDate) {
        this.createDate = createDate;
    }

    @Basic
    @Column(name = "ModifyBy", nullable = true, length = 32)
    public String getModifyBy() {
        return modifyBy;
    }

    public void setModifyBy(String modifyBy) {
        this.modifyBy = modifyBy;
    }

    @Basic
    @Column(name = "ModifyDate", nullable = true)
    public Timestamp getModifyDate() {
        return modifyDate;
    }

    public void setModifyDate(Timestamp modifyDate) {
        this.modifyDate = modifyDate;
    }

    @Basic
    @Column(name = "IsAnonymous", nullable = true)
    public Integer getIsAnonymous() {
        return isAnonymous;
    }

    public void setIsAnonymous(Integer isAnonymous) {
        this.isAnonymous = isAnonymous;
    }

    @Basic
    @Column(name = "IsDelAllow", nullable = true)
    public Integer getIsDelAllow() {
        return isDelAllow;
    }

    public void setIsDelAllow(Integer isDelAllow) {
        this.isDelAllow = isDelAllow;
    }

    @Basic
    @Column(name = "ComeFrom", nullable = true, length = 32)
    public String getComeFrom() {
        return comeFrom;
    }

    public void setComeFrom(String comeFrom) {
        this.comeFrom = comeFrom;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        DdForumArticle that = (DdForumArticle) o;

        if (articleId != that.articleId) return false;
        if (articleType != null ? !articleType.equals(that.articleType) : that.articleType != null) return false;
        if (articleTitle != null ? !articleTitle.equals(that.articleTitle) : that.articleTitle != null) return false;
        if (content != null ? !content.equals(that.content) : that.content != null) return false;
        if (brief != null ? !brief.equals(that.brief) : that.brief != null) return false;
        if (atWho != null ? !atWho.equals(that.atWho) : that.atWho != null) return false;
        if (imgUrl != null ? !imgUrl.equals(that.imgUrl) : that.imgUrl != null) return false;
        if (tags != null ? !tags.equals(that.tags) : that.tags != null) return false;
        if (config != null ? !config.equals(that.config) : that.config != null) return false;
        if (viewCount != null ? !viewCount.equals(that.viewCount) : that.viewCount != null) return false;
        if (likeCount != null ? !likeCount.equals(that.likeCount) : that.likeCount != null) return false;
        if (commentCount != null ? !commentCount.equals(that.commentCount) : that.commentCount != null) return false;
        if (commentEnable != null ? !commentEnable.equals(that.commentEnable) : that.commentEnable != null)
            return false;
        if (commentDate != null ? !commentDate.equals(that.commentDate) : that.commentDate != null) return false;
        if (isHot != null ? !isHot.equals(that.isHot) : that.isHot != null) return false;
        if (isTop != null ? !isTop.equals(that.isTop) : that.isTop != null) return false;
        if (isQa != null ? !isQa.equals(that.isQa) : that.isQa != null) return false;
        if (qaType != null ? !qaType.equals(that.qaType) : that.qaType != null) return false;
        if (pickDate != null ? !pickDate.equals(that.pickDate) : that.pickDate != null) return false;
        if (adminPickDate != null ? !adminPickDate.equals(that.adminPickDate) : that.adminPickDate != null)
            return false;
        if (plateId != null ? !plateId.equals(that.plateId) : that.plateId != null) return false;
        if (plateTitle != null ? !plateTitle.equals(that.plateTitle) : that.plateTitle != null) return false;
        if (classifyId != null ? !classifyId.equals(that.classifyId) : that.classifyId != null) return false;
        if (classifyTitle != null ? !classifyTitle.equals(that.classifyTitle) : that.classifyTitle != null)
            return false;
        if (userInfoId != null ? !userInfoId.equals(that.userInfoId) : that.userInfoId != null) return false;
        if (userName != null ? !userName.equals(that.userName) : that.userName != null) return false;
        if (userCode != null ? !userCode.equals(that.userCode) : that.userCode != null) return false;
        if (delFlag != null ? !delFlag.equals(that.delFlag) : that.delFlag != null) return false;
        if (createBy != null ? !createBy.equals(that.createBy) : that.createBy != null) return false;
        if (createDate != null ? !createDate.equals(that.createDate) : that.createDate != null) return false;
        if (modifyBy != null ? !modifyBy.equals(that.modifyBy) : that.modifyBy != null) return false;
        if (modifyDate != null ? !modifyDate.equals(that.modifyDate) : that.modifyDate != null) return false;
        if (isAnonymous != null ? !isAnonymous.equals(that.isAnonymous) : that.isAnonymous != null) return false;
        if (isDelAllow != null ? !isDelAllow.equals(that.isDelAllow) : that.isDelAllow != null) return false;
        if (comeFrom != null ? !comeFrom.equals(that.comeFrom) : that.comeFrom != null) return false;

        return true;
    }

    @Override
    public int hashCode() {
        int result = articleId;
        result = 31 * result + (articleType != null ? articleType.hashCode() : 0);
        result = 31 * result + (articleTitle != null ? articleTitle.hashCode() : 0);
        result = 31 * result + (content != null ? content.hashCode() : 0);
        result = 31 * result + (brief != null ? brief.hashCode() : 0);
        result = 31 * result + (atWho != null ? atWho.hashCode() : 0);
        result = 31 * result + (imgUrl != null ? imgUrl.hashCode() : 0);
        result = 31 * result + (tags != null ? tags.hashCode() : 0);
        result = 31 * result + (config != null ? config.hashCode() : 0);
        result = 31 * result + (viewCount != null ? viewCount.hashCode() : 0);
        result = 31 * result + (likeCount != null ? likeCount.hashCode() : 0);
        result = 31 * result + (commentCount != null ? commentCount.hashCode() : 0);
        result = 31 * result + (commentEnable != null ? commentEnable.hashCode() : 0);
        result = 31 * result + (commentDate != null ? commentDate.hashCode() : 0);
        result = 31 * resu

Bee*_*isy 5

通过将此添加到配置,我的问题解决了:

spring.jpa.hibernate.naming.implicit-strategy=org.hibernate.boot.model.naming.ImplicitNamingStrategyLegacyJpaImpl
spring.jpa.hibernate.naming.physical-strategy=org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl
Run Code Online (Sandbox Code Playgroud)