java.sql.SQLException:字段“ otherMenuItems_id”没有默认值

时间:2019-08-25 14:39:26

标签: java mysql hibernate jpa playframework

我试图在具有多对多关系的实体中创建一个字段,但我不断得到fieldname_id没有默认值错误。

在同一模型中,我具有相同类型的不同字段。那不会产生任何错误。

对于新字段,我仅更改了变量名,但是会产生错误。

@Entity
public class OrderItem extends Model {
  @Required
  public String title;

  @Column(length = 3)
  public String currency;

  public double price;

  public double quantity = 1;

  public String size;

  @ManyToOne
  public Category category;

  public String crustType;

  public Long menuItemId;//reference to main or parent menu item from which this order item is based on

  @ManyToMany
  public List<MenuItem> menuItems; No error


  @ManyToMany
public List<MenuItem> othermenuItems; Causes error



@ManyToOne
  public Recipe recipe;

  @ManyToOne
  public Activity status;

  @OneToOne
  public FoodOrder order;
}



@Entity
public class MenuItem extends Model{
  public String description;

  @Required
  public String title;

  public String shortCode;

  @Column(length = 3)
  public String currency;

  public Double price;

  public String weight;



  @ManyToMany
  public List<MenuItem> menuItems;

  public String size;

  @ManyToOne
  public Category category;

  public Boolean isAvailable = true;

  @ManyToOne
  public Recipe recipe;

//  @ManyToOne
//  public RecipeV2 recipeV2;

  public String imageUrl;
  public Blob image;

  @Index(name="menuItemIndex")
  @Column(name="itemIndex", length=255)
  public String itemIndex;

  public Date logDate;
  public Date lastModified;

  public String recipeId;

}

@OnApplicationStart
public class LoadTestData extends Job {

    @Override
    public void doJob() {
        if (play.Play.mode.isDev() && !Play.id.equalsIgnoreCase("production")) {
            Logger.info("Deleting all data");
            Fixtures.deleteAllModels();
            Logger.info("Loading order item...");
            Fixtures.loadModels("test-data/orderItem.yml");
        }
    }
}

从yaml文件加载数据时出现以下错误...

  

由以下原因引起:java.sql.SQLException:字段“ othermenuItems_id”没有默认值

     

在com.mysql.jdbc.SQLError.createSQLException(SQLError.java:964)

     

在com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3970)

     

在com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3906)

     

在com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2524)

     

在com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2677)

     

在com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2549)

0 个答案:

没有答案