reset password
Author Message
liangxu
Posts: 15
Posted 12:31 May 07, 2009 |

My User model class has an object attribute  Blog,

User {

.........

Blog blog;

}

The database mapping is "blog_id" column in the talbe "users". 

After the system starts and Hibernate retrieves the user object, the following always turns to be true, even if the user

has a valid blog_id in database.

<c:if test="${empty principal.blog}">  .....</c:if> 

Am I wrong in the database mapping?   What should I do to make the blog object linked to the user object?

Thanks.

 

 

 

cysun
Posts: 2935
Posted 13:44 May 07, 2009 |

I'm not sure what's the type of "principle". If it's the variable set by Spring Security, then its type is not csns.model.User, i.e. it does not have a blog property. If you want to access current user in JSP, you need to do something like the following in the controller:

User user = userDao.getUserByName( SecurityUtils.getUsername() );
return (new ModelAndView("viewName")).addObject("user", user);

liangxu
Posts: 15
Posted 14:14 May 07, 2009 |

I see. Thanks for the help.