vlad wrote:
The entity attribute is null, not the entity.
Run the SQL query in the DB console and see what you have there. Makes sense?
Also, you should read our
User Guide, all of it. Then you'll understand what I'm talking about.
yes ,the entity attribute is null,but why ?why only the lastest one 's entity attribute is null ?
I look the sql log
Code:
3117 Query SET autocommit=1
3117 Query SET autocommit=0
3117 Query select message0_.`message_id` as message_1_9_, message0_.`content` as content2_9_, message0_.`from_user` as from_use3_9_, message0_.`to_user` as to_user4_9_, message0_.`date` as date5_9_, message0_.`if_read` as if_read6_9_, message0_.`type` as type7_9_ from `message` message0_ where 1=1 and message0_.`from_user`=3 order by message0_.`message_id` desc limit 1
3117 Query insert into `message` (`content`, `from_user`, `to_user`, `date`, `if_read`, `type`) values ('test', 3, 4, '2017-03-18 10:18:12', 0, 0)
3117 Query select last_insert_id()
3117 Query commit
3117 Query SET autocommit=1
170318 10:18:13 3117 Query SET autocommit=0
3117 Query select message0_.`message_id` as message_1_9_, message0_.`content` as content2_9_, message0_.`from_user` as from_use3_9_, message0_.`to_user` as to_user4_9_, message0_.`date` as date5_9_, message0_.`if_read` as if_read6_9_, message0_.`type` as type7_9_ from `message` message0_ where 1=1 and message0_.`if_read`=0 order by message0_.`message_id` desc limit 10
3117 Query commit
3117 Query SET autocommit=1
i Run the SQL query in the DB console,this is the reslut
Code:
@RequestMapping(value = "/t.do")
public void listMessage(HttpServletRequest request,
HttpServletResponse response, ModelMap model){
//insert new one
String content="test";
int fromUserId=3;
int toUserId=4;
messageService.addMessage(StringEscapeUtils.escapeHtml4(content), fromUserId, toUserId,0);
// if i reduce last four line code , I will get right result (all getFromUser() is not null)
//find out the ten latest
int pageNo=1;
int pageSize=10;
Message m=new Message();
m.setIfRead((byte)0);
List<Message> list =messageService.getMessageByCondition(m, pageNo, pageSize);
for(int i=0;i<list.size();i++){
if(list.get(i).getFromUser()!=null){
System.out.println("fromUser not null");
}else{
System.out.println("null");
}
}
}
may be I misunderstand your answer....