亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

Intellij 拋出 java.lang.NoSuchMethodError:

Intellij 拋出 java.lang.NoSuchMethodError:

神不在的星期二 2021-07-15 18:23:21
我正在嘗試測試一小段代碼,看看我是否可以使用 hibernate 連接到我的本地數據庫并創建一些表并插入數據。package service;import model.CategoryEntry;import model.SubCategoryEntry;import org.hibernate.Session;import org.hibernate.SessionFactory;import org.hibernate.cfg.Configuration;import org.junit.Test;import java.util.ArrayList;import java.util.List;public class DatabaseConnectionTest {    @Test    public void databaseConnectionIsSuccessful() {        SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();        Session session = sessionFactory.openSession();        CategoryEntry categoryEntry = new CategoryEntry();        categoryEntry.setId(2269);        categoryEntry.setAlert(false);        categoryEntry.setLabel("Eat and Drink");        categoryEntry.setSlug("eat-drink");        List<CategoryEntry> subcategories = new ArrayList<>();        CategoryEntry subCategoryEntry1 = new CategoryEntry();        subCategoryEntry1.setId(9);        subCategoryEntry1.setAlert(false);        subCategoryEntry1.setLabel("Food");        subCategoryEntry1.setSlug("food");        subCategoryEntry1.setParent(categoryEntry);        subcategories.add(subCategoryEntry1);        categoryEntry.setSubcategories(subcategories);        try {            session.beginTransaction();            session.persist(categoryEntry);            session.getTransaction().commit();            session.close();        } catch (Exception e) {            e.getLocalizedMessage();        }    }}和實體類:package model;import com.fasterxml.jackson.annotation.JsonInclude;import org.hibernate.annotations.Fetch;import javax.persistence.*;import java.util.ArrayList;import java.util.List;@Entitypublic class CategoryEntry {    @Id    private int id;    private boolean alert = false;    private String label;    private String slug;}
查看完整描述

1 回答

  • 1 回答
  • 0 關注
  • 359 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號