I’m following the official document and blog post to use POJO mapping to the Entity
. For example, I have a Customer Entity, which has a phone number and address details (other than the name, email, password). If I use the QuickStart guide to get user input would be complaining as it is different from the constructor that declared in the user entity.
Then I tweak it like using the relational database to get all customer input, but it raises another issue on how to append all address details to the customer object? As you might know that the State
and Postcode
is separate as it owns. Should Address be another new entity or how to put it together? What is the right way to use MongoDB in Java Servlet?
MongoCollection<Customer> customerTbl = database.getCollection("Customer", Customer.class);
Customer newCustomer = new Customer(); // that linking to the constructuor of the entity instead
newCustomer.setEmail(customer.getEmail());
newCustomer.setFullName(customer.getFullName());
newCustomer.setPassword(customer.getPassword());
newCustomer.setState(customer.getState());
newCustomer.setPostCode(customer.getPostCode());
newCustomer.setPhone(customer.getPhone());
newCustomer.setRegisterDate(new Date());
customerTbl.insertOne(newCustomer);
Thanks