1

I'm making simple Spring MVC library app, using Freemarker, MySQL and Hibernate, i created form for adding new book to the library, it's code:

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Create new user</title>
</head>
<body>
<form name="booker" action="/newBook" method="post" >
<p>Name</p>
<input title="Name" type="text" name="name">
<p>Desc</p>
<input title="Email" type="text" name="desc">
<p>Author</p>
<input title="Age" type="text" name="aut">
<p>Year</p>
<input title="Age" type="text" name="year">
<input type="submit" value="OK">
</form>
</body>
</html>

Also i have Controller, BookDAO, BookService and Book entity

Controller:

@Controller
@RequestMapping("/")
public class BookController {
@Autowired
private BookService service;

@GetMapping("/books")
public String viewAll(Model model){
    model.addAttribute("books",service.findAll());
    return "books";
}
@GetMapping("/addBook")
public String addBook(){

    return "createBook";
}
@PostMapping("/newBook")
public String newBooks(@ModelAttribute("booker") Book book){
    service.add(book);
    return "redirect:/books";
}
}

Entity:

  @Table(name = "booker")
  @Entity
  public class Book {
  private int id;
@Id
@GeneratedValue(strategy= GenerationType.AUTO)
@Column(name = "idbooker")
public int getId() {
    return id;
}
public void setId(int id) {
    this.id = id;
}
private String name;
private String desc;
private String aut;
private int year;
@Column(name = "name")
public String getName() {
    return name;
}
public void setName(String name) {
    this.name = name;
}

@Column(name="desc")
public String getDesc() {
    return desc;
}
public void setDesc(String desc) {
    this.desc = desc;
}

@Column(name = "aut")
public String getAut() {
    return aut;
}
public void setAut(String author) {
    this.aut = author;
}


@Column(name = "year")
public int getYear() {
    return year;
}
public void setYear(int year) {
    this.year = year;
}
}

When i try to post new book, i get this exception, database columns' names are same can somebody tell how to fix it, ty. enter image description here

gg ff
  • 489
  • 1
  • 10
  • 20

1 Answers1

1

Could be you have some issue with desc (reserved word) try using backtics

 @Column(name="`desc`")
ScaisEdge
  • 131,976
  • 10
  • 91
  • 107