java - 关键字 'statistics' 附近的语法不正确。 Spring.IO

标签 java sql-server spring maven youtube-api

我正在编写此 API 来获取 YoutubeAPI v3 的一些详细信息并将其发布到数据库。

目前我在创建表时遇到此错误:

2015-09-08 11:22:40.795 ERROR 11384 --- [ost-startStop-1] org.hibernate.tool.hbm2ddl.SchemaExport  : HHH000389: Unsuccessful: create table ccccVideoDetailsItems (dbid numeric(19,0) identity not null, etag varchar(255), id varchar(255), kind varchar(255), statistics numeric(19,0), primary key (dbid))
2015-09-08 11:22:40.795 ERROR 11384 --- [ost-startStop-1] org.hibernate.tool.hbm2ddl.SchemaExport  : Incorrect syntax near the keyword 'statistics'.

我的头上几乎没有头发了,因为我找不到问题所在。

我有这三个类来检索每个对象。 视频详细内容:

@Entity
@Table(name="ccccVideoDetailsContent")
public class VideoDetailsContent {
    @Id
    private String kind;
    private String etag;


    @OneToOne
    @Transient
    private List<DetailsContentItem> items;

    public VideoDetailsContent() {
    }

    public String getKind() {
        return kind;
    }

    public void setKind(String kind) {
        this.kind = kind;
    }

    public String getEtag() {
        return etag;
    }

    public void setEtag(String etag) {
        this.etag = etag;
    }

    public List<DetailsContentItem> getItems() {
        return items;
    }

    public void setItems(List<DetailsContentItem> items) {
        this.items = items;
    }
}

详细内容内容:

@Entity
@Table(name="ccccVideoDetailsItems")
public class DetailsContentItem {
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Column(name = "dbid")
    private Long dbId;

    private String kind;
    private String etag;
    @Column(name = "id")
    private String id;

//    @OneToOne(cascade = CascadeType.ALL,orphanRemoval = true)
//    @JoinColumn(name = "sID")
    @OneToOne
    VideoStatistics statistics;

    public DetailsContentItem() {
    }

    public Long getDbId() {
        return dbId;
    }

    public void setDbId(Long dbId) {
        this.dbId = dbId;
    }

    public String getKind() {
        return kind;
    }

    public void setKind(String kind) {
        this.kind = kind;
    }

    public String getEtag() {
        return etag;
    }

    public void setEtag(String etag) {
        this.etag = etag;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public VideoStatistics getStatistics() {
        return statistics;
    }

    public void setStatistics(VideoStatistics statistics) {
        this.statistics = statistics;
    }
}

视频统计:

@Entity
@Table(name = "ccccVideoStatistics")
public class VideoStatistics {
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Column(name = "id")
    private long id;

    private long viewCount;
    private long likeCount;
    private long dislikeCount;
    private long favoriteCount;
    private long commentCount;

    public VideoStatistics() {
    }

    public VideoStatistics(long id, long viewCount, long likeCount, long dislikeCount, long favoriteCount, long commentCount) {
        this.id = id;
        this.viewCount = viewCount;
        this.likeCount = likeCount;
        this.dislikeCount = dislikeCount;
        this.favoriteCount = favoriteCount;
        this.commentCount = commentCount;
    }

    public long getId() {
        return id;
    }

    public void setId(long id) {
        this.id = id;
    }

    public long getViewCount() {
        return viewCount;
    }

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

    public long getLikeCount() {
        return likeCount;
    }

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

    public long getDislikeCount() {
        return dislikeCount;
    }

    public void setDislikeCount(long dislikeCount) {
        this.dislikeCount = dislikeCount;
    }

    public long getFavoriteCount() {
        return favoriteCount;
    }

    public void setFavoriteCount(long favoriteCount) {
        this.favoriteCount = favoriteCount;
    }

    public long getCommentCount() {
        return commentCount;
    }

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

API 输出为:

{
kind: "youtube#videoListResponse",
etag: ""sGDdEsjSJ_SnACpEvVQ6MtTzkrI/15jlenwUohs80IG8APFsDfw7xb8"",
pageInfo: {
totalResults: 1,
resultsPerPage: 1
},
items: [
{
kind: "youtube#video",
etag: ""sGDdEsjSJ_SnACpEvVQ6MtTzkrI/sCA7RDne1nKYHc3Fiqawl_oS3sk"",
id: "g_AT2djYGmA",
statistics: {
viewCount: "149353",
likeCount: "2369",
dislikeCount: "21",
favoriteCount: "0",
commentCount: "251"
}
}
]
}

为什么我会收到这个错误?

最佳答案

我写代码的时候脑子有问题。

所以我通过重构 VideoStatistics 类解决了这个问题。

将所有输入设置为 String 而不是 Long,因为我从 Youtube api 获取了一个字符串。

关于java - 关键字 'statistics' 附近的语法不正确。 Spring.IO,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32454098/

相关文章:

java - 如何在执行时设置spring bootstrap.properties

java - bean 到 bean 的值(value)

java - 如何将参数从一个选项卡传递到另一个选项卡并使用按钮更改选项卡?

java - 如何将 UTC 字符串转换为具有 DST 调整的 LocalDateTime?

java - android.widget.RelativeLayout android 不正确调用 requestLayout()

mysql - 获取具有分组 SQL 结果的最大总和值的记录

sql - 将两个不同表中的 2 个值插入到一个表中

java - 停止 JOptionPane 上的堆栈跟踪

sql-server - 如何查看 SQL 2000 数据库中最近的关系更改

java - 将 JSON 数据从 JQUERY 传递到 java Controller 时出现异常