Announcement Announcement Module
No announcement yet.
Problem binding Embedded Class in spring MVC Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Problem binding Embedded Class in spring MVC

    i have a entity class which has a composite key which is nothing but a separate class having two properties.i have embedded this class in the main class using Embedded annotation.
    i am facing problem while binding the values from the JSP page to this embedded class.
    here id my code:

    this is my embeddable class

    package EntityClasses;


    import javax.persistence.Embeddable;

    public class Name implements Serializable {

    String firstName;
    String lastName;

    public String getFirstName() {
    return firstName;
    public void setFirstName(String firstName) {
    this.firstName = firstName;
    public String getLastName() {
    return lastName;
    public void setLastName(String lastName) {
    this.lastName = lastName;

    this my main class just given the required code,not the complete one

    @Table(name ="STUDENT", uniqueConstraints = [email protected](columnNames= {"FIRSTNAME","LASTNAME"})})
    public class Student implements Serializable {

    Name name = new Name();

    and here are setter and getter methods on it:
    public Name getName() {
    return name;

    public void setName(String firstName,String lastName) {


    here is my JSP page:
    <form:form commandName = "newStudent" action = "confirmation" method = "post" >
    <b><font size = "4" color = "#A52A2A">&nbsp;&nbsp;First Name</font></b><br>
    &nbsp;&nbsp;<input type = "text" size = "25" maxlength = "40" name ="name.firstname">
    <b><font size = "4" color = "#A52A2A">&nbsp;&nbsp;Last name</font></b><br>
    &nbsp;&nbsp;<input type = "text" size = "25" maxlength = "35" name = "name.lastname" >
    <b><font size = "4" color = "#A52A2A">&nbsp;&nbsp;Age</font></b><br>
    &nbsp;&nbsp;<input type = "text" size = "25" maxlength = "20" name = "age">

    and here is my controller class:

    public String storeData(@ModelAttribute("newStudent") Student student,Model map)


    map.addAttribute("id", student.getId());
    map.addAttribute("firstname",student.getName().get FirstName());
    map.addAttribute("lastname", student.getName().getLastName());
    map.addAttribute("year", student.getYear());
    map.addAttribute("branch", student.getBranch());
    map.addAttribute("home", student.getStudentHome());
    map.addAttribute("result", student.getResultStatus());
    map.addAttribute("age", student.getAge());

    i am getting all other values but i am getting null in the properties of the embedded class(Name.firstname and Name.lastname).

    Any suggetions??
    Thanks in Advance!!