java - Which is best way to mapping request bean object to hibernate domain model object? -


for api application development using spring boot , hibernate on java 8, need store bean object values(for example bookid, bookname, bookdescription) db. please find sample classes

beanobject.java

package com.example;  public class beanobject {      private string bookid;     private string bookname;     private string bookdescription;      /**      * @return bookid      */     public string getbookid() {         return bookid;     }     /**      * @param bookid bookid set      */     public void setbookid(string bookid) {         this.bookid = bookid;     }     /**      * @return bookname      */     public string getbookname() {         return bookname;     }     /**      * @param bookname bookname set      */     public void setbookname(string bookname) {         this.bookname = bookname;     }     /**      * @return bookdescription      */     public string getbookdescription() {         return bookdescription;     }     /**      * @param bookdescription bookdescription set      */     public void setbookdescription(string bookdescription) {         this.bookdescription = bookdescription;     } } 

domainobject.java

/**  *   */ package com.example;  import javax.persistence.column; import javax.persistence.entity; import javax.persistence.table;  /**  * @author pandiaraj  *  */ @entity @table(name = "books") public class domainobject {      private string bookid;     private string bookname;     private string bookdescription;      /**      * @return bookid      */     @id     @column(name = "id", unique = true, nullable = false, length = 100)     public string getbookid() {         return bookid;     }     /**      * @param bookid bookid set      */     public void setbookid(string bookid) {         this.bookid = bookid;     }     /**      * @return bookname      */     @column(name = "name", length = 30)     public string getbookname() {         return bookname;     }     /**      * @param bookname bookname set      */     public void setbookname(string bookname) {         this.bookname = bookname;     }     /**      * @return bookdescription      */     @column(name = "description", length = 30)     public string getbookdescription() {         return bookdescription;     }     /**      * @param bookdescription bookdescription set      */     public void setbookdescription(string bookdescription) {         this.bookdescription = bookdescription;     }  } 

which simple , best way mapping request object values hibernate dao object(domain model), indentation fastest way execute line of code means reduce api response time. followed below ways

  1. using getter , setter methods.
  2. using apache commons - beanutils.copyproperties(tobean, frombean);

is there other ways mapping objects!

as know java has multiple mapping frameworks. personaly have experiance dozer mapping. can check this article. suppose frameworks use reflection , may slower setter/getter aproach.

but frameworks can provide better visualisation of fields mapped. , reduse number of builder or mapper classes :)


Comments

Popular posts from this blog

Spring Boot + JPA + Hibernate: Unable to locate persister -

go - Golang: panic: runtime error: invalid memory address or nil pointer dereference using bufio.Scanner -

c - double free or corruption (fasttop) -