package no.hvl.dat250.jpa.basicexample; import javax.persistence.*; import java.util.List; @Entity public class Person { @Id @GeneratedValue(strategy = GenerationType.TABLE) private Long id; private String name; private List
adresses; public Person(String name){ this.name = name; } @Embedded private Address address; @Embedded private CreditCard creditCard; public Person() { } public void setAddress(Address address) { this.adresses.add(address); } public void setName(String name){ this.name = name; } public String getName(){ return name; } public Long getId() { return id; } public void setId(Long Id) { this.id = Id; } } package no.hvl.dat250.jpa.basicexample; import javax.persistence.*; @Embeddable public class CreditCard { @Id @GeneratedValue(strategy = GenerationType.TABLE) private int id; private int number; private int limit; private int balance; private Bank bank; @Embedded private Pincode pincode; } package no.hvl.dat250.jpa.basicexample; import javax.persistence.*; public class Bank { @Id @GeneratedValue(strategy = GenerationType.TABLE) private int id; private String name; } package no.hvl.dat250.jpa.basicexample; import javax.persistence.Embeddable; @Embeddable public class Pincode { private String pincode; private int count; public Pincode(){ } public String getPincode() { return pincode; } public void setPincode(String pincode) { this.pincode = pincode; } public int getCount() { return count; } public void setCount(int count) { this.count = count; } } package no.hvl.dat250.jpa.basicexample; import javax.persistence.Embeddable; import javax.persistence.*; @Embeddable public class Address { @Id @GeneratedValue(strategy = GenerationType.TABLE) private Long id; private String street; private int number; public Address() { } public void setStreet(String street) { this.street = street; } public String getStreet() { return street; } public int getNumber() { return number; } public void setNumber(int number) { this.number = number; } public Long getId() { return id; } public void setId(Long Id) { this.id = Id; } }