I need to get my 'Comment' (stored in DAO) object from my controller and display it in my JSP but every time I see the error message from the error block.

Why is this happenning and what should I do?

Logic of my code is the next:

1. After clicking on the 'Reply' button data from the form is sent to my controller.
2. Controller saves data in DB and returns 'Comment' entity.
3. I get this 'Comment' entity in my JSP page and use it for publishing on the page.

But I get the error msg from error block instead of msg from the success block.

Here is my form: 

```
<form id="comment_${comment.getCommentId()}">
    <textarea class="textarea" rows="10" name="text"></textarea>
    <input type="hidden" name="bookId" value="${book.getBookId()}" />
    <input type="hidden" name="parentId" />
    <input type="hidden" name="commentId" value="${comment.getCommentId()}" /><br />
    <input type="button" class="button" value="Reply" id="submit_${comment.getCommentId()}" onclick="ajaxsubmit(this.id)"/>
</form>

```

Here is my script:

```
<script type="text/javascript">
    function ajaxsubmit(buttonId){
    var formId = document.getElementById(buttonId).parentNode.id;
    var dataString = $("#" + formId).serialize();

    $.ajax( {
        url: "ajaxcomment.htm",
        type: "post",
        data: dataString,
        dataType: "json",
        success: function(data) {
            alert(data.getCommentAdded());
        },
        error: function() {
            alert("error");
        }
    } );
}

```

Here is my controller

```
@RequestMapping(value = "ajaxcomment.htm", method = RequestMethod.POST)
public @ResponseBody Comment ajaxcomment(
        HttpServletRequest httpServletRequest,
        @RequestParam(value = "bookId", required = false) Long bookId,
        @RequestParam(value = "parentId", required = false) Long parentId,
        @RequestParam(value = "commentId", required = false) Long commentId,
        @RequestParam(value = "text", required = true) String text) {

    String username = httpServletRequest.getRemoteUser();
    User user = userDao.getUserByUsername(username);

    Comment comment = new Comment();

    // DAO logic

    commentDao.addComment(comment);
    return comment;
}

```

Here is my 'Comment' entity:

```
@Entity @Table(name = "COMMENT") public class Comment implements Serializable {

@Id
@GeneratedValue
@Column(name = "COMMENT_ID", nullable = false)
private Long commentId;

@Column(name = "COMMENT_TEXT", length = 512, nullable = true)
private String commentText;

@Column(name = "COMMENT_ADDED", length = 128, nullable = true)
@Temporal(TemporalType.TIMESTAMP)
private Date commentAdded;

@ManyToOne(cascade = CascadeType.REFRESH, fetch = FetchType.EAGER)
@JoinColumn(name = "BOOK_ID")
private Book book;

@ManyToOne(cascade = CascadeType.REFRESH, fetch = FetchType.EAGER)
@JoinColumn(name = "PARENT_ID")
private Comment parentComment;

@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER, mappedBy = "parentComment")
@OrderBy("commentAdded")
private Collection<Comment> subcomments;

public void setCommentText(String commentText) {
    this.commentText = commentText;
}
public String getCommentText() {
    return this.commentText;
}

// other getters and setters are public too

```

And here is my applicationContext.xml:

```
<?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/context
    http://www.springframework.org/schema/context/spring-context-2.5.xsd
    http://www.springframework.org/schema/beans 
    http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
    http://www.springframework.org/schema/mvc 
    http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">

<mvc:annotation-driven />
<context:component-scan base-package="com.demo"/>
<context:component-scan base-package="com.demo.service"/>
<context:annotation-config />

<bean id="viewResolver" class="org.springframework.web.servlet.view.UrlBasedViewResolver">
    <property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/>
    <property name="prefix" value="/WEB-INF/jsp/"/>
    <property name="suffix" value=".jsp"/>
</bean>

<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver"/>

<bean id="jacksonMessageConverter" class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter"/>

<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
    <property name="messageConverters">
        <list>
            <ref bean="jacksonMessageConverter" />
        </list>
    </property>
</bean>

<bean id="exceptionMessageAdapter"
    class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerExceptionResolver">
    <property name="messageConverters">
        <list>
            <!-- Support JSON -->
            <ref bean="jacksonMessageConverter" />  
        </list>
    </property>
</bean>

```