I am trying to save the data entered through REST API's post method() to MySQL Database, but I am getting the org.hibernate.id.IdentifierGenerationException: Unknown integral data type for ids : java.lang.String
Book.java
@Entity
@Table(name = "book")
public class Book {
@Id
@GeneratedValue
@Column(name = "ISBN")
private String ISBN;
@Column(name = "title")
private String title;
@Column(name = "subject")
private String subject;
@Column(name = "publisher")
private String publisher;
@Column(name = "language")
private String language;
@Column(name = "numberOfPages")
private int numberOfPages;
public Book() {
}
public Book(String iSBN, String title, String subject, String publisher, String language, int numberOfPages) {
ISBN = iSBN;
this.title = title;
this.subject = subject;
this.publisher = publisher;
this.language = language;
this.numberOfPages = numberOfPages;
}
public String getISBN() {
return ISBN;
}
public void setISBN(String iSBN) {
ISBN = iSBN;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getSubject() {
return subject;
}
public void setSubject(String subject) {
this.subject = subject;
}
public String getPublisher() {
return publisher;
}
public void setPublisher(String publisher) {
this.publisher = publisher;
}
public String getLanguage() {
return language;
}
public void setLanguage(String language) {
this.language = language;
}
public int getNumberOfPages() {
return numberOfPages;
}
public void setNumberOfPages(int numberOfPages) {
this.numberOfPages = numberOfPages;
}
@Override
public String toString() {
return "Book [ISBN=" + ISBN + ", title=" + title + ", subject=" + subject + ", publisher=" + publisher
+ ", language=" + language + ", numberOfPages=" + numberOfPages + "]";
}
}
LibrarianController.java
@RestController
@RequestMapping("/librarian")
public class LibrarianController {
private static final Logger log = LoggerFactory.getLogger(LibrarianController.class);
@Autowired
LibrarianService librarianService;
@PostMapping
public ResponseEntity<Book> addBooks(@RequestBody Book book) {
log.info("Entering addBooks method ");
librarianService.addBooks(book);
log.info("Exiting addBooks method ");
return ResponseEntity.ok(book);
}
}
LibrarianService.java
@Service
public class LibrarianService {
@Autowired
LibrarianRepository librarianRepository;
public void addBooks(Book book) {
librarianRepository.save(book);
}
}
LibrarianRepository.java
@Repository
public interface LibrarianRepository extends JpaRepository<Book, String> {
}
getting the following error message Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaConfiguration.class]: Invocation of init method failed; nested exception is java.lang.annotation.AnnotationTypeMismatchException: Incorrectly typed data found for annotation element public abstract java.lang.String javax.persistence.GeneratedValue.generator() (Found data of type Ljavax/persistence/GenerationType;.AUTO)