user1141785
user1141785

Reputation: 551

How to save a mapping of similar data in DB using JPA

I don't know how to design this rdbms problem:

Let's say, I have a customer, who is making a purchase. By making the purchase he leaves his data. I have a second dataset with real customer data. After collecting the data, I want to find a mapping of the collected customer data to the real customers by an algorithm.

It's still unclear how to save this mapping/these links created by the algorithm.

Proposal:

@Entity
public class Purchase{
    @OneToOne
    private Customerdata customerData;
}

@Entity
public class CustomerData{
    private String firstName;
    private String Lastname;
    private String city;
}

@Entity
public class RealCustomer{

    @OneToMany(cascade=CascadeType.ALL, mappedBy ="RealCustomer")
    private List<CustomerData> customerData = new ArrayList<CustomerData>();
    private String firstName;
    private String Lastname;
    private String city;
}

Now I can save my assumed mapping from RealCustomer data to customer data in the customerData list.

I guess that's not the best idea?

Hoping for nice suggestions from you. Can I take advantage of the similarity of real customer data and obtainer customer data.

Please note that I want to keep inconsistent data e.g. even if city is similar ('Washington D.C.' and 'Washington'. I don't want to lose this information that I can run the matching algorithm later again.

Note: I'm okay, if you provide me the rough idea. Java/JPA-Code not necessary.

Thank you very much in advance!

Upvotes: 0

Views: 46

Answers (1)

Amit Deshpande
Amit Deshpande

Reputation: 19185

You can do something like below

@Entity
public class Purchase{
@OneToOne
private Customer customer;
}

@Entity
public class Customer{
private String firstName;
private String Lastname;
private String city;
//Below association will only come in picture if customer has real customer data       available when you are collecting the data this way you can clearly identify and separate collected vs real customers
@OneToOne
Customer realCustomer;
}

Upvotes: 1

Related Questions