从一对多关系获取列表时出错,字段列表

时间:2017-07-17 15:40:47

标签: java mysql hibernate jpa

我使用intellj,CRUD类和相关实体创建一个简单的Hibernate项目,但是当我尝试从部门检索项目时,这个错误代码就出来了

这里涉及的课程

DepartmentsEntity.java

package database_table;

import javax.persistence.*;
import java.util.List;

 /**
  * Created by Michele on 14/07/2017.
 */
@Entity
@Table(name = "departments", schema = "warehouse")
public class DepartmentsEntity {
private String name;
private int id;

@Basic
@Column(name = "name")
public String getName() {
    return name;
}

public void setName(String name) {
    this.name = name;
}

@Id
@Column(name = "id")
public int getId() {
    return id;
}

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

@OneToMany(mappedBy = "departments",cascade = {CascadeType.ALL},fetch = 
FetchType.LAZY)
private List<ItemsEntity> items;

public List<ItemsEntity> getItems() {
    return this.items;
}
public void setItems (List<ItemsEntity> items){
    this.items = items;
}

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

    DepartmentsEntity that = (DepartmentsEntity) o;

    if (id != that.id) return false;
    if (name != null ? !name.equals(that.name) : that.name != null) return 
 false;

    return true;
}

@Override
public int hashCode() {
    int result = name != null ? name.hashCode() : 0;
    result = 31 * result + id;
    return result;
}

@Override
public String toString(){
    String res = "///Departments///";
    res += "\nID:          "+this.getId();
    res += "\nname:        "+this.getName();
    return res;
    }
}

ItemsEntity.java

package database_table;

import javax.persistence.*;
import java.util.ArrayList;
import java.util.List;

/**
* Created by Michele on 14/07/2017.
*/
@Entity
@Table(name = "items", schema = "warehouse")
public class ItemsEntity {
private String name;
private Integer price;
private Integer size;
private int id;
private String description;

@Basic
@Column(name = "name")
public String getName() {
    return name;
}

public void setName(String name) {
    this.name = name;
}

@Basic
@Column(name = "price")
public Integer getPrice() {
    return price;
}

public void setPrice(Integer price) {
    this.price = price;
}

@Basic
@Column(name = "size")
public Integer getSize() {
    return size;
}

public void setSize(Integer size) {
    this.size = size;
}

@Id
@Column(name = "id")
public int getId() {
    return id;
}

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

@Basic
@Column(name = "description")
public String getDescription() {
    return description;
}

public void setDescription(String description) {
    this.description = description;
}

@ManyToOne
@JoinColumn (name = "dep" , nullable = false)//nome colonna della table items nel database warehouse
private DepartmentsEntity departments;//nome oggetto nel mappedBy di DepartmentsEntity(l'entita di destinazione)
                                      //che contiene una List di Item
public DepartmentsEntity getDepartments(){return this.departments;}
public void setDepartments(DepartmentsEntity departments){this.departments = departments;}


@OneToMany (mappedBy = "items",fetch = FetchType.LAZY)
@Column (name = "id")
private List<MovementsEntity> movements;
/*public ArrayList<MovementsEntity> getMovements(){return this.movements;}
public void setMovements(ArrayList<MovementsEntity> movements){this.movements = movements;}*/


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

    ItemsEntity that = (ItemsEntity) o;

    if (id != that.id) return false;
    if (name != null ? !name.equals(that.name) : that.name != null) return false;
    if (price != null ? !price.equals(that.price) : that.price != null) return false;
    if (size != null ? !size.equals(that.size) : that.size != null) return false;
    if (description != null ? !description.equals(that.description) : that.description != null) return false;

    return true;
}

@Override
public int hashCode() {
    int result = name != null ? name.hashCode() : 0;
    result = 31 * result + (price != null ? price.hashCode() : 0);
    result = 31 * result + (size != null ? size.hashCode() : 0);
    result = 31 * result + id;
    result = 31 * result + (description != null ? description.hashCode() : 0);
    return result;
}

public void replaceItem(ItemsEntity item){
    if(item.name!= "" || item.name!=null){
        this.setName(item.name);
    }
    if(item.price!=null){
        this.setPrice(item.price);
    }
    if(item.size!=null){
        this.setSize(item.size);
    }
    if(item.description!= "" || item.description!=null){
        this.setDescription(item.description);
    }
    if(item.departments.getName()!= "" || item.departments!=null){
        this.setDepartments(item.departments);
    }
}

@Override
public String toString(){
    String res = "///Item///";
    res += "\nID:          "+this.getId();
    res += "\nname:        "+this.getName();
    res += "\nprice:       "+this.getDescription();
    res += "\nstored size: "+this.getSize();
    res += "\ndepartment:  "+this.getDepartments().getName();
    return res;
}
}

DepartmentsCRUD.java

package service;

import database_table.DepartmentsEntity;

import javax.persistence.EntityManager;
import javax.persistence.Query;
import javax.persistence.TypedQuery;
import java.util.List;

/**
 * Created by Michele on 14/07/2017.
 */
public class DepartmentsCRUD {

protected EntityManager em;

public DepartmentsCRUD (EntityManager em){
    this.em = em;
}

public List<DepartmentsEntity> getDeps(){
    Query query = em.createQuery("select d from DepartmentsEntity d");
    return (List<DepartmentsEntity>) query.getResultList();
}

public DepartmentsEntity getDepById(int id){
    /*TypedQuery<DepartmentsEntity> query = em.createQuery(
            "Select d from DepartmentsEntity d where d.id = :id", DepartmentsEntity.class);
    return query.setParameter("id",id).getSingleResult();*/
    return em.find(DepartmentsEntity.class,id);
}
}

TestDepartmentsCRUD.java

package service;

/**
 * Created by Michele on 14/07/2017.
 */

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;

import database_table.DepartmentsEntity;
import database_table.ItemsEntity;

import java.util.List;

public class TestDepartmentsCRUD {

public static void main (String args[]) {

    EntityManagerFactory emf = Persistence.createEntityManagerFactory("jpa-example");
    EntityManager em = emf.createEntityManager();

    DepartmentsCRUD departmentsCRUD = new DepartmentsCRUD(em);

    //////////////////////Get list of departments\\\\\\\\\\\\\\\\\\\\\\\
    /*List<DepartmentsEntity> listOfDepartments = departmentsCRUD.getDeps();
    for (DepartmentsEntity dep : listOfDepartments) {
        System.out.println("name : "+dep.getName());
    }*/

    //////////////////////Get dep by id\\\\\\\\\\\\\\\\\\\\\\\
    DepartmentsEntity dep = departmentsCRUD.getDepById(1);
    System.out.println(dep.toString());
    List<ItemsEntity> items = dep.getItems();
    System.out.println("is empty? --> "+items.isEmpty());
    for(ItemsEntity item:items){
        System.out.println(item.toString());
    }
    em.close();
    emf.close();
}

}

这是我的登录控制台

    "C:\Program Files (x86)\Java\jdk1.8.0_131\bin\java" "-javaagent:C:\Program Files\JetBrains\IntelliJ IDEA 2017.1.4\lib\idea_rt.jar=50573:C:\Program Files\JetBrains\IntelliJ IDEA 2017.1.4\bin" -Dfile.encoding=UTF-8 -classpath "C:\Users\Michele\Desktop\Test_Hibernate\bin;C:\Program Files (x86)\Java\jdk1.8.0_131\jre\lib\charsets.jar;C:\Program Files (x86)\Java\jdk1.8.0_131\jre\lib\deploy.jar;C:\Program Files (x86)\Java\jdk1.8.0_131\jre\lib\ext\access-bridge-32.jar;C:\Program Files (x86)\Java\jdk1.8.0_131\jre\lib\ext\cldrdata.jar;C:\Program Files (x86)\Java\jdk1.8.0_131\jre\lib\ext\dnsns.jar;C:\Program Files (x86)\Java\jdk1.8.0_131\jre\lib\ext\jaccess.jar;C:\Program Files (x86)\Java\jdk1.8.0_131\jre\lib\ext\jfxrt.jar;C:\Program Files (x86)\Java\jdk1.8.0_131\jre\lib\ext\localedata.jar;C:\Program Files (x86)\Java\jdk1.8.0_131\jre\lib\ext\nashorn.jar;C:\Program Files (x86)\Java\jdk1.8.0_131\jre\lib\ext\sunec.jar;C:\Program Files (x86)\Java\jdk1.8.0_131\jre\lib\ext\sunjce_provider.jar;C:\Program Files (x86)\Java\jdk1.8.0_131\jre\lib\ext\sunmscapi.jar;C:\Program Files (x86)\Java\jdk1.8.0_131\jre\lib\ext\sunpkcs11.jar;C:\Program Files (x86)\Java\jdk1.8.0_131\jre\lib\ext\zipfs.jar;C:\Program Files (x86)\Java\jdk1.8.0_131\jre\lib\javaws.jar;C:\Program Files (x86)\Java\jdk1.8.0_131\jre\lib\jce.jar;C:\Program Files (x86)\Java\jdk1.8.0_131\jre\lib\jfr.jar;C:\Program Files (x86)\Java\jdk1.8.0_131\jre\lib\jfxswt.jar;C:\Program Files (x86)\Java\jdk1.8.0_131\jre\lib\jsse.jar;C:\Program Files (x86)\Java\jdk1.8.0_131\jre\lib\management-agent.jar;C:\Program Files (x86)\Java\jdk1.8.0_131\jre\lib\plugin.jar;C:\Program Files (x86)\Java\jdk1.8.0_131\jre\lib\resources.jar;C:\Program Files (x86)\Java\jdk1.8.0_131\jre\lib\rt.jar;C:\Users\Michele\Desktop\Test_Hibernate\lib\Hibernate_ORM\envers\hibernate-envers-5.2.1.Final.jar;C:\Users\Michele\Desktop\Test_Hibernate\lib\Hibernate_ORM\jpa-metamodel-generator\hibernate-jpamodelgen-5.2.1.Final.jar;C:\Users\Michele\Desktop\Test_Hibernate\lib\Hibernate_ORM\optional\c3p0\c3p0-0.9.2.1.jar;C:\Users\Michele\Desktop\Test_Hibernate\lib\Hibernate_ORM\optional\c3p0\hibernate-c3p0-5.2.1.Final.jar;C:\Users\Michele\Desktop\Test_Hibernate\lib\Hibernate_ORM\optional\c3p0\mchange-commons-java-0.2.3.4.jar;C:\Users\Michele\Desktop\Test_Hibernate\lib\Hibernate_ORM\optional\ehcache\ehcache-2.10.1.jar;C:\Users\Michele\Desktop\Test_Hibernate\lib\Hibernate_ORM\optional\ehcache\hibernate-ehcache-5.2.1.Final.jar;C:\Users\Michele\Desktop\Test_Hibernate\lib\Hibernate_ORM\optional\ehcache\slf4j-api-1.7.7.jar;C:\Users\Michele\Desktop\Test_Hibernate\lib\Hibernate_ORM\optional\infinispan\hibernate-infinispan-5.2.1.Final-tests.jar;C:\Users\Michele\Desktop\Test_Hibernate\lib\Hibernate_ORM\optional\infinispan\hibernate-infinispan-5.2.1.Final.jar;C:\Users\Michele\Desktop\Test_Hibernate\lib\Hibernate_ORM\optional\infinispan\infinispan-commons-8.1.0.Final.jar;C:\Users\Michele\Desktop\Test_Hibernate\lib\Hibernate_ORM\optional\infinispan\infinispan-core-8.1.0.Final.jar;C:\Users\Michele\Desktop\Test_Hibernate\lib\Hibernate_ORM\optional\infinispan\jboss-marshalling-osgi-1.4.10.Final.jar;C:\Users\Michele\Desktop\Test_Hibernate\lib\Hibernate_ORM\optional\infinispan\jboss-transaction-api_1.1_spec-1.0.1.Final.jar;C:\Users\Michele\Desktop\Test_Hibernate\lib\Hibernate_ORM\optional\infinispan\jgroups-3.6.4.Final.jar;C:\Users\Michele\Desktop\Test_Hibernate\lib\Hibernate_ORM\optional\proxool\hibernate-proxool-5.2.1.Final.jar;C:\Users\Michele\Desktop\Test_Hibernate\lib\Hibernate_ORM\optional\proxool\proxool-0.8.3.jar;C:\Users\Michele\Desktop\Test_Hibernate\lib\Hibernate_ORM\osgi\hibernate-osgi-5.2.1.Final.jar;C:\Users\Michele\Desktop\Test_Hibernate\lib\Hibernate_ORM\osgi\org.osgi.compendium-4.3.1.jar;C:\Users\Michele\Desktop\Test_Hibernate\lib\Hibernate_ORM\osgi\org.osgi.core-4.3.1.jar;C:\Users\Michele\Desktop\Test_Hibernate\lib\Hibernate_ORM\required\antlr-2.7.7.jar;C:\Users\Michele\Desktop\Test_Hibernate\lib\Hibernate_ORM\required\cdi-api-1.1-PFD.jar;C:\Users\Michele\Desktop\Test_Hibernate\lib\Hibernate_ORM\required\classmate-1.3.0.jar;C:\Users\Michele\Desktop\Test_Hibernate\lib\Hibernate_ORM\required\dom4j-1.6.1.jar;C:\Users\Michele\Desktop\Test_Hibernate\lib\Hibernate_ORM\required\el-api-2.2.jar;C:\Users\Michele\Desktop\Test_Hibernate\lib\Hibernate_ORM\required\geronimo-jta_1.1_spec-1.1.1.jar;C:\Users\Michele\Desktop\Test_Hibernate\lib\Hibernate_ORM\required\hibernate-commons-annotations-5.0.1.Final.jar;C:\Users\Michele\Desktop\Test_Hibernate\lib\Hibernate_ORM\required\hibernate-core-5.2.1.Final.jar;C:\Users\Michele\Desktop\Test_Hibernate\lib\Hibernate_ORM\required\hibernate-jpa-2.1-api-1.0.0.Final.jar;C:\Users\Michele\Desktop\Test_Hibernate\lib\Hibernate_ORM\required\jandex-2.0.0.Final.jar;C:\Users\Michele\Desktop\Test_Hibernate\lib\Hibernate_ORM\required\javassist-3.20.0-GA.jar;C:\Users\Michele\Desktop\Test_Hibernate\lib\Hibernate_ORM\required\javax.inject-1.jar;C:\Users\Michele\Desktop\Test_Hibernate\lib\Hibernate_ORM\required\jboss-interceptors-api_1.1_spec-1.0.0.Beta1.jar;C:\Users\Michele\Desktop\Test_Hibernate\lib\Hibernate_ORM\required\jboss-logging-3.3.0.Final.jar;C:\Users\Michele\Desktop\Test_Hibernate\lib\Hibernate_ORM\required\jsr250-api-1.0.jar;C:\Users\Michele\Desktop\Test_Hibernate\lib\mysql-connector-5.1.8.jar;C:\Users\Michele\Desktop\Test_Hibernate\lib\Hibernate_ORM\osgi\hibernate-osgi-5.2.1.Final-karaf.xml;C:\Users\Michele\Downloads\Hibernate_Tools_509.jar" service.TestDepartmentsCRUD
lug 17, 2017 5:10:56 PM org.hibernate.jpa.internal.util.LogHelper logPersistenceUnitInformation
INFO: HHH000204: Processing PersistenceUnitInfo [
    name: jpa-example
    ...]
lug 17, 2017 5:10:56 PM org.hibernate.Version logVersion
INFO: HHH000412: Hibernate Core {5.2.1.Final}
lug 17, 2017 5:10:56 PM org.hibernate.cfg.Environment <clinit>
INFO: HHH000205: Loaded properties from resource hibernate.properties: {hibernate.connection.driver_class=org.h2.Driver, hibernate.service.allow_crawling=false, hibernate.max_fetch_depth=5, hibernate.dialect=org.hibernate.dialect.H2Dialect, hibernate.format_sql=true, hibernate.generate_statistics=true, hibernate.connection.username=sa, hibernate.connection.url=jdbc:h2:mem:db1;DB_CLOSE_DELAY=-1;LOCK_TIMEOUT=10000, hibernate.bytecode.use_reflection_optimizer=false, hibernate.connection.password=****, hibernate.connection.pool_size=5}
lug 17, 2017 5:10:56 PM org.hibernate.cfg.Environment buildBytecodeProvider
INFO: HHH000021: Bytecode provider name : javassist
lug 17, 2017 5:10:57 PM org.hibernate.annotations.common.reflection.java.JavaReflectionManager <clinit>
INFO: HCANN000001: Hibernate Commons Annotations {5.0.1.Final}
lug 17, 2017 5:10:58 PM org.hibernate.c3p0.internal.C3P0ConnectionProvider configure
INFO: HHH010002: C3P0 using driver: com.mysql.jdbc.Driver at URL: jdbc:mysql://localhost:3306/warehouse
lug 17, 2017 5:10:58 PM org.hibernate.c3p0.internal.C3P0ConnectionProvider configure
INFO: HHH10001001: Connection properties: {user=root, password=****}
lug 17, 2017 5:10:58 PM org.hibernate.c3p0.internal.C3P0ConnectionProvider configure
INFO: HHH10001003: Autocommit mode: false
lug 17, 2017 5:10:58 PM com.mchange.v2.log.MLog <clinit>
INFORMAZIONI: MLog clients using java 1.4+ standard logging.
lug 17, 2017 5:10:58 PM com.mchange.v2.c3p0.C3P0Registry banner
INFORMAZIONI: Initializing c3p0-0.9.2.1 [built 20-March-2013 10:47:27 +0000; debug? true; trace: 10]
lug 17, 2017 5:10:58 PM org.hibernate.c3p0.internal.C3P0ConnectionProvider configure
INFO: HHH10001007: JDBC isolation level: <unknown>
lug 17, 2017 5:10:58 PM com.mchange.v2.c3p0.impl.AbstractPoolBackedDataSource getPoolManager
INFORMAZIONI: Initializing c3p0 pool... com.mchange.v2.c3p0.PoolBackedDataSource@a96e5ebc [ connectionPoolDataSource -> com.mchange.v2.c3p0.WrapperConnectionPoolDataSource@f7546cc7 [ acquireIncrement -> 3, acquireRetryAttempts -> 30, acquireRetryDelay -> 1000, autoCommitOnClose -> false, automaticTestTable -> null, breakAfterAcquireFailure -> false, checkoutTimeout -> 0, connectionCustomizerClassName -> null, connectionTesterClassName -> com.mchange.v2.c3p0.impl.DefaultConnectionTester, debugUnreturnedConnectionStackTraces -> false, factoryClassLocation -> null, forceIgnoreUnresolvedTransactions -> false, identityToken -> 1hge8ml9pmi3x8z7v08zo|833051, idleConnectionTestPeriod -> 2000, initialPoolSize -> 5, maxAdministrativeTaskTime -> 0, maxConnectionAge -> 0, maxIdleTime -> 500, maxIdleTimeExcessConnections -> 0, maxPoolSize -> 20, maxStatements -> 50, maxStatementsPerConnection -> 0, minPoolSize -> 5, nestedDataSource -> com.mchange.v2.c3p0.DriverManagerDataSource@5db05a23 [ description -> null, driverClass -> null, factoryClassLocation -> null, identityToken -> 1hge8ml9pmi3x8z7v08zo|16d6c1e, jdbcUrl -> jdbc:mysql://localhost:3306/warehouse, properties -> {user=******, password=******} ], preferredTestQuery -> null, propertyCycle -> 0, statementCacheNumDeferredCloseThreads -> 0, testConnectionOnCheckin -> false, testConnectionOnCheckout -> false, unreturnedConnectionTimeout -> 0, usesTraditionalReflectiveProxies -> false; userOverrides: {} ], dataSourceName -> null, factoryClassLocation -> null, identityToken -> 1hge8ml9pmi3x8z7v08zo|df6e3a, numHelperThreads -> 3 ]
lug 17, 2017 5:10:58 PM org.hibernate.dialect.Dialect <init>
INFO: HHH000400: Using dialect: org.hibernate.dialect.MySQL5InnoDBDialect
lug 17, 2017 5:10:58 PM org.hibernate.engine.jdbc.env.internal.LobCreatorBuilderImpl useContextualLobCreation
INFO: HHH000423: Disabling contextual LOB creation as JDBC driver reported JDBC version [3] less than 4
lug 17, 2017 5:10:58 PM org.hibernate.envers.boot.internal.EnversServiceImpl configure
INFO: Envers integration enabled? : true
///Departments///
ID:          1
name:        E-Items
lug 17, 2017 5:10:59 PM org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptions
WARN: SQL Error: 1054, SQLState: 42S22
lug 17, 2017 5:10:59 PM org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptions
ERROR: Unknown column 'items0_.items_ORDER' in 'field list'
Exception in thread "main" org.hibernate.exception.SQLGrammarException: could not extract ResultSet
    at org.hibernate.exception.internal.SQLExceptionTypeDelegate.convert(SQLExceptionTypeDelegate.java:63)
    at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:42)
    at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:111)
    at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:97)
    at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.extract(ResultSetReturnImpl.java:79)
    at org.hibernate.loader.plan.exec.internal.AbstractLoadPlanBasedLoader.getResultSet(AbstractLoadPlanBasedLoader.java:434)
    at org.hibernate.loader.plan.exec.internal.AbstractLoadPlanBasedLoader.executeQueryStatement(AbstractLoadPlanBasedLoader.java:186)
    at org.hibernate.loader.plan.exec.internal.AbstractLoadPlanBasedLoader.executeLoad(AbstractLoadPlanBasedLoader.java:121)
    at org.hibernate.loader.plan.exec.internal.AbstractLoadPlanBasedLoader.executeLoad(AbstractLoadPlanBasedLoader.java:86)
    at org.hibernate.loader.collection.plan.AbstractLoadPlanBasedCollectionInitializer.initialize(AbstractLoadPlanBasedCollectionInitializer.java:87)
    at org.hibernate.persister.collection.AbstractCollectionPersister.initialize(AbstractCollectionPersister.java:682)
    at org.hibernate.event.internal.DefaultInitializeCollectionEventListener.onInitializeCollection(DefaultInitializeCollectionEventListener.java:75)
    at org.hibernate.internal.SessionImpl.initializeCollection(SessionImpl.java:2142)
    at org.hibernate.collection.internal.AbstractPersistentCollection$4.doWork(AbstractPersistentCollection.java:567)
    at org.hibernate.collection.internal.AbstractPersistentCollection.withTemporarySessionIfNeeded(AbstractPersistentCollection.java:249)
    at org.hibernate.collection.internal.AbstractPersistentCollection.initialize(AbstractPersistentCollection.java:563)
    at org.hibernate.collection.internal.AbstractPersistentCollection.read(AbstractPersistentCollection.java:132)
    at org.hibernate.collection.internal.AbstractPersistentCollection$1.doWork(AbstractPersistentCollection.java:161)
    at org.hibernate.collection.internal.AbstractPersistentCollection$1.doWork(AbstractPersistentCollection.java:146)
    at org.hibernate.collection.internal.AbstractPersistentCollection.withTemporarySessionIfNeeded(AbstractPersistentCollection.java:249)
    at org.hibernate.collection.internal.AbstractPersistentCollection.readSize(AbstractPersistentCollection.java:145)
    at org.hibernate.collection.internal.PersistentList.isEmpty(PersistentList.java:118)
    at service.TestDepartmentsCRUD.main(TestDepartmentsCRUD.java:35)
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown column 'items0_.items_ORDER' in 'field list'
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
    at com.mysql.jdbc.Util.handleNewInstance(Util.java:406)
    at com.mysql.jdbc.Util.getInstance(Util.java:381)
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1030)
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:956)
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3536)
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3468)
    at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1957)
    at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2107)
    at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2648)
    at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:2086)
    at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:2237)
    at com.mchange.v2.c3p0.impl.NewProxyPreparedStatement.executeQuery(NewProxyPreparedStatement.java:116)
    at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.extract(ResultSetReturnImpl.java:70)
    ... 18 more

Process finished with exit code 1

请帮帮我,谢谢你

1 个答案:

答案 0 :(得分:0)

“字段列表”中的未知列“ items0_.items_ORDER”

此错误行表明JPA正在ITEMS表中搜索items_ORDER。这表明您需要在Items表中创建此列。

@OneToMany(mappedBy =“ items”,fetch = FetchType.LAZY) @Column(名称=“ id”)

mappedby = items表示在另一个表中应该有将被绑定的名为field的项。