On my page I would like to get only one user details. The problem being that I'm having problems with displaying the details of the user on the page. The object that I'm trying to retrieve has a onetomany relationship with another class. So I would like to list the associated objects as well.
Model
@Entity
@Table(name = "user")
@Component
public class UserEntity implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Basic(optional = false)
@Column(name = "user_id")
private Integer userId;
@OneToMany(cascade=CascadeType.ALL, fetch=FetchType.EAGER, mappedBy="setter")
private Set<Module> sModule = new HashSet<Module>();
@OneToMany(cascade=CascadeType.ALL, fetch=FetchType.EAGER, mappedBy="checker")
private Set<Module> cModule = new HashSet<Module>();
Controller
@RequestMapping(value = "/main/user/testing", method = RequestMethod.GET)
public String getRecords(@RequestParam("userId") Integer userId, ModelMap
model) {
if(userId !=null)
{
UserEntity user = userService.getUserByID(userId);
model.addAttribute("user", user);
}
return "/main/user/testing";
}
Jsp page
<table>
<tr>
<th>User Id</th>
<th>Name</th>
<th>Module Code</th>
<th>Module Name</th>
</tr>
<c:forEach items="${user}" var="obj" >
<c:forEach items="${obj.sModule}" var="module" >
<tr>
<td><c:out value="${obj.userId}" escapeXml="true" /></td>
<td><c:out value="${obj.name}" escapeXml="true" /></td>
<td><c:out value="${module.moduleCode}" escapeXml="true" /></td>
<td><c:out value="${module.moduleName}" escapeXml="true" /></td>
</tr>
</c:forEach>
</c:forEach>
</table>
Using the controller code, when I try to access the page. The user details are not included. So I wanted to know if there was a way I would be able to render the object for just one user instead of a list of users.