mysql数据库的表中的字段为null,无法在控制层的方法中将这一行查询出来

控制层代码:@RequestMapping("/getBy")publicUsergetByAccount(){Stringaccount="admin";Useruse... 控制层代码:
@RequestMapping("/getBy")
public User getByAccount(){
String account = "admin";
User user = userService.getByAccount(account);
System.out.println(user);
System.out.println("111");
return user;
}
控制台显示代码:

Hibernate: select user0_.id as id1_0_, user0_.account as account2_0_, user0_.code as code3_0_, user0_.createdBy_id as createdB4_0_, user0_.created_at as created_5_0_, user0_.department_id as departme6_0_, user0_.enable as enable7_0_, user0_.group_id as group_id8_0_, user0_.hashed_password as hashed_p9_0_, user0_.jobNumber as jobNumb10_0_, user0_.job_id as job_id11_0_, user0_.name as name12_0_, user0_.post_id as post_id13_0_, user0_.status_id as status_14_0_, user0_.updateBy_id as updateB15_0_, user0_.updated_at as updated16_0_, user0_.version as version17_0_ from users user0_ where user0_.account=?
2015-1-6 21:25:30 org.apache.catalina.core.StandardWrapperValve invoke
严重: Servlet.service() for servlet springmvc threw exception
java.lang.IllegalArgumentException: Can not set int field sh.entity.User.createdBy_id to null value
at sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:146)
at sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:150)
at sun.reflect.UnsafeIntegerFieldAccessorImpl.set(UnsafeIntegerFieldAccessorImpl.java:62)
at java.lang.reflect.Field.set(Field.java:657)
at org.hibernate.property.DirectPropertyAccessor$DirectSetter.set(DirectPropertyAccessor.java:139)
at org.hibernate.tuple.entity.AbstractEntityTuplizer.setPropertyValues(AbstractEntityTuplizer.java:710)
at org.hibernate.tuple.entity.PojoEntityTuplizer.setPropertyValues(PojoEntityTuplizer.java:379)
at org.hibernate.persister.entity.AbstractEntityPersister.setPropertyValues(AbstractEntityPersister.java:4523)
at org.hibernate.engine.internal.TwoPhaseLoad.doInitializeEntity(TwoPhaseLoad.java:186)
at org.hibernate.engine.internal.TwoPhaseLoad.initializeEntity(TwoPhaseLoad.java:137)
at org.hibernate.loader.Loader.initializeEntitiesAndCollections(Loader.java:1108)
at org.hibernate.loader.Loader.processResultSet(Loader.java:964)
at org.hibernate.loader.Loader.doQuery(Loader.java:911)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:342)
at org.hibernate.loader.Loader.doList(Loader.java:2526)
at org.hibernate.loader.Loader.doList(Loader.java:2512)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2342)
at org.hibernate.loader.Loader.list(Loader.java:2337)
at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:495)
at org.hibernate.hql.internal.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:357)
at org.hibernate.engine.query.spi.HQLQueryPlan.performList(HQLQueryPlan.java:195)
展开
 我来答
若以下回答无法解决问题,邀请你更新回答
暮影1994
2015-01-06 · TA获得超过2338个赞
知道大有可为答主
回答量:1215
采纳率:60%
帮助的人:404万
展开全部
看看你userService.getByAccount(account);这里面的那条hql是怎么的?
追问
public User getByAccount(String account) {
String hql = "from User u where u.account=?";
Query query = getSession().createQuery(hql);
query.setParameter(0, account);
return (User) query.uniqueResult();
}
追答
query.setParameter(int index,String yourString);这里面的下标是从1开始的,不是0
本回答被提问者和网友采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 1条折叠回答
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式