質問: query.list(); return listproduct; } } 私の豆 <!-- scan classpath for annotations (eg: @service, @repository etc) --> <context:component-scan base-package="com.shopmvc"/> <!-- jdbc data source. it is assumed you have mysql running on localhost port 3306 with username root and blank password. change below if it's not the case --> <bean id="mydatasource" class="org.apache.commons.dbcp.basicdatasource" destroy-method="close"> <property name="driverclassname" value="com.mysql.jdbc.driver"/> <property name="url" value="jdbc:mysql://localhost:3306/shoesshopdb?autoreconnect=true"/> <property name="username" value="root"/> <property name="password" value="12345"/> <property name="validationquery" value="select 1"/> </bean> <!-- hibernate session factory --> <bean id="mysessionfactory" class="org.springframework.orm.hibernate4.localsessionfactorybean"> <property name="datasource" ref="mydatasource"/> <property name="packagestoscan"> <array> <value>com.shopmvc.pojo</value> </array> </property> <property name="hibernateproperties"> <value> hibernate.dialect=org.hibernate.dialect.mysqldialect </value> </property> </bean> <!-- hibernate transaction manager --> <bean id="transactionmanager" class="org.springframework.orm.hibernate4.hibernatetransactionmanager"> <property name="sessionfactory" ref="mysessionfactory"/> </bean> <!-- activates annotation based transaction management --> <tx:annotation-driven transaction-manager="transactionmanager"/> 例外:org.springframework.web.util.nestedservletexception: request processing failed; nested exception is org.hibernate.exception.sqlgrammarexception: could not extract resultset org.springframework.web.servlet.frameworkservlet.processrequest(frameworkservlet.java:948) org.springframework.web.servlet.frameworkservlet.doget(frameworkservlet.java:827) javax.servlet.http.httpservlet.service(httpservlet.java:621) org.springframework.web.servlet.frameworkservlet.service(frameworkservlet.java:812) javax.servlet.http.httpservlet.service(httpservlet.java:728) root cause org.hibernate.exception.sqlgrammarexception: could not extract resultset org.hibernate.exception.internal.sqlexceptiontypedelegate.convert(sqlexceptiontypedelegate.java:82) org.hibernate.exception.internal.standardsqlexceptionconverter.convert(standardsqlexceptionconverter.java:49) org.hibernate.engine.jdbc.spi.sqlexceptionhelper.convert(sqlexceptionhelper.java:125) org.hibernate.engine.jdbc.spi.sqlexceptionhelper.convert(sqlexceptionhelper.java:110) org.hibernate.engine.jdbc.internal.resultsetreturnimpl.extract(resultsetreturnimpl.java:61) org.hibernate.loader.loader.getresultset(loader.java:2036) root cause com.mysql.jdbc.exceptions.jdbc4.mysqlsyntaxerrorexception: unknown column 'product0_.id_catalog' in 'field list' sun.reflect.nativeconstructoraccessorimpl.newinstance0(native method) sun.reflect.nativeconstructoraccessorimpl.newinstance(unknown source) sun.reflect.delegatingconstructoraccessorimpl.newinstance(unknown source) java.lang.reflect.constructor.newinstance(unknown source) com.mysql.jdbc.util.handlenewinstance(util.java:411) com.mysql.jdbc.util.getinstance(util.java:386) com.mysql.jdbc.sqlerror.createsqlexception(sqlerror.java:1054) com.mysql.jdbc.mysqlio.checkerrorpacket(mysqlio.java:4187) com.mysql.jdbc.mysqlio.checkerrorpacket(mysqlio.java:4119) com.mysql.jdbc.mysqlio.sendcommand(mysqlio.java:2570) com.mysql.jdbc.mysqlio.sqlquerydirect(mysqlio.java:2731) com.mysql.jdbc.connectionimpl.execsql(connectionimpl.java:2815) com.mysql.jdbc.preparedstatement.executeinternal(preparedstatement.java:2155) com.mysql.jdbc.preparedstatement.executequery(preparedstatement.java:2322) org.apache.commons.dbcp.delegatingpreparedstatement.executequery(delegatingpreparedstatement.java:96) org.apache.commons.dbcp.delegatingpreparedstatement.executequery(delegatingpreparedstatement.java:96) org.hibernate.engine.jdbc.internal.resultsetreturnimpl.extract(resultsetreturnimpl.java:56) org.hibernate.loader.loader.getresultset(loader.java:2036) org.hibernate.loader.loader.executequerystatement(loader.java:1836) org.hibernate.loader.loader.executequerystatement(loader.java:1815) org.hibernate.loader.loader.doquery(loader.java:899) org.hibernate.loader.loader.doqueryandinitializenonlazycollections(loader.java:341) org.hibernate.loader.loader.dolist(loader.java:2522) org.hibernate.loader.loader.dolist(loader.java:2508) org.hibernate.loader.loader.listignorequerycache(loader.java:2338) org.hibernate.loader.loader.list(loader.java:2333) org.hibernate.loader.hql.queryloader.list(queryloader.java:490) 私のデータベース:create table `catalog` ( `id_catalog` int(11) not null auto_increment, `catalog_name` varchar(45) default null, primary key (`id_catalog`) ) create table `product` ( `id_product` int(11) not null auto_increment, `product_name` varchar(45) default null, `date` date default null, `author` varchar(45) default null, `price` int(11) default null, `catalog_id` int(11) default null, `linkimage` varchar(45) default null, primary key (`id_product`), key `fk_product_idx` (`catalog_id`), constraint `fk_product` foreign key (`catalog_id`) references `catalog` (`id_catalog`) on delete no action on update no action )
回答: 別の解決策は@jsonignoreを追加することです:@onetomany(mappedby="catalog", fetch = fetchtype.lazy) @jsonignore private set<product> products = new hashset<product>(0);