Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.mayank.bitmesra.pojo;
- import java.util.Date;
- import javax.persistence.Entity;
- import javax.persistence.GeneratedValue;
- import javax.persistence.GenerationType;
- import javax.persistence.Id;
- import javax.persistence.PrePersist;
- import javax.persistence.PreUpdate;
- import javax.persistence.Temporal;
- import javax.persistence.TemporalType;
- @Entity
- public class Customer {
- @Id
- @GeneratedValue(strategy=GenerationType.AUTO)
- private Long id;
- private String customerId;
- private String name;
- private String phoneNumber;
- @Temporal(TemporalType.DATE)
- private Date dateOfBirth;
- @Temporal(TemporalType.DATE)
- private Date createdDate;
- //for rolling back of Data
- //using date as such of now
- @Temporal(TemporalType.DATE)
- private Date updatedOn;
- //for picking up only the data that is most recent
- //like a customer can have save with same customer id
- //but has different address as his address might have changed up in near future
- //will try to handle this in near future
- /* @Temporal
- private Date lastPickedUpDate;*/
- public String getCustomerId() {
- return customerId;
- }
- public void setCustomerId(String customerId) {
- this.customerId = customerId;
- }
- public Date getDateOfBirth() {
- return dateOfBirth;
- }
- public void setDateOfBirth(Date dateOfBirth) {
- this.dateOfBirth = dateOfBirth;
- }
- public String getName() {
- return name;
- }
- public void setName(String name) {
- this.name = name;
- }
- public String getPhoneNumber() {
- return phoneNumber;
- }
- public Long getId() {
- return id;
- }
- public void setId(Long id) {
- this.id = id;
- }
- public void setPhoneNumber(String phoneNumber) {
- this.phoneNumber = phoneNumber;
- }
- @Override
- public String toString() {
- return "Customer [id=" + id + ", name=" + name + ", phoneNumber=" + phoneNumber + "]";
- }
- public Date getUpdatedOn() {
- return updatedOn;
- }
- public void setUpdatedOn(Date updatedOn) {
- this.updatedOn = updatedOn;
- }
- @PrePersist
- protected void onCreate() {
- createdDate = new Date();
- }
- @PreUpdate
- protected void onUpdate() {
- updatedOn = new Date();
- }
- }
- package com.mayank.bitmesra.pojo;
- import javax.persistence.Entity;
- import javax.persistence.GeneratedValue;
- import javax.persistence.GenerationType;
- import javax.persistence.Id;
- @Entity
- public class OrderDetails {
- @Id
- @GeneratedValue(strategy=GenerationType.AUTO)
- private long id;
- private String customerId;
- private String orderId;
- private String orderName;
- public String getCustomerId() {
- return customerId;
- }
- public void setCustomerId(String customerId) {
- this.customerId = customerId;
- }
- public String getOrderId() {
- return orderId;
- }
- public void setOrderId(String orderId) {
- this.orderId = orderId;
- }
- public String getOrderName() {
- return orderName;
- }
- public void setOrderName(String orderName) {
- this.orderName = orderName;
- }
- }
- @Repository
- @Transactional
- public class OrderDetailsDAOImpl implements OrderDetailsDAO{
- @PersistenceContext
- EntityManager entityManager;
- @Override
- public List getAllOrderDetails() {
- // return entityManager.createQuery("Select order from OrderDetails order ").getResultList();
- return entityManager.createQuery("Select customer.name from OrderDetails order inner join Customer customer on order.customerId=customer.customerId").getResultList();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement