com.fasterxml.jackson.databind.JsonMappingException: failed to lazily initialize a collection of role
<p>I searched for this exception.  Most answer suggest to directly or indirectly fetch data eagerly.  I dont want the child data.  How do I tell the json mapping to return only the parent data and not to look for the child data.</p>

<p>Here is the method in the controller :</p>

<pre><code>@RequestMapping(value="/user/{id}", method = RequestMethod.GET )
public @ResponseBody User getUserById(@PathVariable("id") Integer id) {
    User user = userService.getUserById(id);
    return user;
}
</code></pre>

<p>DAO has the following method.  Note that the Hibernate.initialize() didnot bring any difference in the output.  The println is able to print the user name.</p>

<pre><code>public User getUserById(int id) {
    User user = hibernateTemplate.get(User.class, id);
    System.out.println("hello " + user.getUserName());
    Hibernate.initialize(user);
    return user;
}
</code></pre>

<p>WebAppInitializer has this filter</p>

<pre><code>@Override
protected Filter[] getServletFilters() {

    return new Filter[]{ new OpenEntityManagerInViewFilter() };
}
</code></pre>

<p>User.java :</p>

<pre><code>import java.util.Date;
import java.util.HashSet;
import java.util.Set;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import static javax.persistence.GenerationType.IDENTITY;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.UniqueConstraint;

@Entity
@Table(name = "tm_user", catalog = "tm", uniqueConstraints = {     @UniqueConstraint(columnNames = "email"),
    @UniqueConstraint(columnNames = "phone") })
public class User implements java.io.Serializable {

private Integer userId;
private String userName;
private String phone;
private String email;
private String password;
private Date dateOfBirth;
private String userNotes;
private Set&lt;AttendanceUser&gt; attendanceUsers = new HashSet&lt;AttendanceUser&gt;(0);
private Set&lt;ProjectUser&gt; projectUsers = new HashSet&lt;ProjectUser&gt;(0);
private Set&lt;RoleUser&gt; roleUsers = new HashSet&lt;RoleUser&gt;(0);

public User() {
}

public User(String userName) {
    this.userName = userName;
}

public User(String userName, String phone, String email, String  password, Date dateOfBirth, String userNotes,
        Set&lt;AttendanceUser&gt; attendanceUsers, Set&lt;ProjectUser&gt; projectUsers, Set&lt;RoleUser&gt; roleUsers) {
    this.userName = userName;
    this.phone = phone;
    this.email = email;
    this.password = password;
    this.dateOfBirth = dateOfBirth;
    this.userNotes = userNotes;
    this.attendanceUsers = attendanceUsers;
    this.projectUsers = projectUsers;
    this.roleUsers = roleUsers;
}

@Id
@GeneratedValue(strategy = IDENTITY)

@Column(name = "user_id", unique = true, nullable = false)
public Integer getUserId() {
    return this.userId;
}

public void setUserId(Integer userId) {
    this.userId = userId;
}

@Column(name = "user_name", nullable = false, length = 200)
public String getUserName() {
    return this.userName;
}

public void setUserName(String userName) {
    this.userName = userName;
}

@Column(name = "phone", unique = true, length = 30)
public String getPhone() {
    return this.phone;
}

public void setPhone(String phone) {
    this.phone = phone;
}

@Column(name = "email", unique = true, length = 100)
public String getEmail() {
    return this.email;
}

public void setEmail(String email) {
    this.email = email;
}

@Column(name = "password", length = 50)
public String getPassword() {
    return this.password;
}

public void setPassword(String password) {
    this.password = password;
}

@Temporal(TemporalType.DATE)
@Column(name = "date_of_birth", length = 10)
public Date getDateOfBirth() {
    return this.dateOfBirth;
}

public void setDateOfBirth(Date dateOfBirth) {
    this.dateOfBirth = dateOfBirth;
}

@Column(name = "user_notes", length = 4000)
public String getUserNotes() {
    return this.userNotes;
}

public void setUserNotes(String userNotes) {
    this.userNotes = userNotes;
}

@OneToMany(fetch = FetchType.LAZY, mappedBy = "user")
public Set&lt;AttendanceUser&gt; getAttendanceUsers() {
    return this.attendanceUsers;
}

public void setAttendanceUsers(Set&lt;AttendanceUser&gt; attendanceUsers) {
    this.attendanceUsers = attendanceUsers;
}

@OneToMany(fetch = FetchType.LAZY, mappedBy = "user")
public Set&lt;ProjectUser&gt; getProjectUsers() {
    return this.projectUsers;
}

public void setProjectUsers(Set&lt;ProjectUser&gt; projectUsers) {
    this.projectUsers = projectUsers;
}

@OneToMany(fetch = FetchType.LAZY, mappedBy = "user")
public Set&lt;RoleUser&gt; getRoleUsers() {
    return this.roleUsers;
}

public void setRoleUsers(Set&lt;RoleUser&gt; roleUsers) {
    this.roleUsers = roleUsers;
}

}
</code></pre>

<p>Any help is appreciated.</p>