【问题标题】:Hibernate: Missing column count休眠:缺少列数
【发布时间】:2013-11-17 15:49:34
【问题描述】:

这是我的实体:

@Entity
@Table(name="log_shop")
public class LogShop {

    @Id
    @GeneratedValue
    private int id;

    private String platform;

    @Type(type="org.jadira.usertype.dateandtime.joda.PersistentDateTime")
    private DateTime logged;

    @ManyToOne
    private Player player;

    private String type;

    @Column(name="type_value")
    private String typeValue;

    @Column(name="shop_source")
    private String shopSource;

    @Column(name="buy_confirm")
    @Type(type="org.hibernate.type.NumericBooleanType")
    private boolean buyConfirm;

    @Column(name="buy_yes")
    @Type(type="org.hibernate.type.NumericBooleanType")
    private boolean buyYes;

    @Column(name="not_enough_coins")
    @Type(type="org.hibernate.type.NumericBooleanType")
    private boolean notEnoughCoins;

    @Column(name="not_enough_coins_yes")
    @Type(type="org.hibernate.type.NumericBooleanType")
    private boolean notEnoughCoinsYes;

    LogShop() {}

    public LogShop(String platform, DateTime logged, Player player, String type, String typeValue, String shopSource, boolean buyConfirm, boolean buyYes,
            boolean notEnoughCoins, boolean notEnoughCoinsYes) {
        this.platform = platform;
        this.logged = logged;
        this.player = player;
        this.type = type;
        this.typeValue = typeValue;
        this.shopSource = shopSource;
        this.buyConfirm = buyConfirm;
        this.buyYes = buyYes;
        this.notEnoughCoins = notEnoughCoins;
        this.notEnoughCoinsYes = notEnoughCoinsYes;
    }

}

在启动时,Hibernate(使用 hbm2ddl validate)抱怨 org.hibernate.HibernateException: Missing column: count in xxxxx.log_shop

但是如你所见,实体类中没有引用名为count 的列。为什么 Hibernate 要求它存在于数据库中?

下表是完整的参考:

CREATE TABLE `log_shop` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `platform` varchar(26) NOT NULL DEFAULT 'web',
  `logged` datetime NOT NULL,
  `player_id` int(11) NOT NULL,
  `type` varchar(26) NOT NULL,
  `type_value` varchar(26) NOT NULL,
  `shop_source` varchar(26) NOT NULL,
  `buy_confirm` int(1) NOT NULL,
  `buy_yes` int(1) NOT NULL,
  `not_enough_coins` int(1) NOT NULL,
  `not_enough_coins_yes` int(1) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

【问题讨论】:

    标签: java hibernate jpa hbm2ddl


    【解决方案1】:

    嗯,那是愚蠢的... 结果我不小心将@Table(name="log_shop") 应用于另一个实体类,它确实引用了count 列。

    Hibernate 最好能提及这是关于哪个类和字段。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-07-21
      • 2016-04-21
      • 2023-03-10
      • 2016-10-08
      • 2015-08-31
      • 2019-01-20
      • 2019-09-29
      • 2011-08-08
      相关资源
      最近更新 更多