Facebook
From Sweltering Duck, 3 Years ago, written in Java.
Embed
Download Paste or View Raw
Hits: 202
  1. package no.hvl.dat250.jpa.basicexample;
  2.  
  3. import javax.persistence.*;
  4. import java.util.List;
  5.  
  6. public class Person {
  7.     @Id
  8.     @GeneratedValue(strategy = GenerationType.TABLE)
  9.     private Long id;
  10.     private String name;
  11.     private List<Address> adresses;
  12.  
  13.     public Person(String name){
  14.         this.name = name;
  15.     }
  16.  
  17.     @Embedded
  18.     private Address address;
  19.     @Embedded
  20.     private CreditCard creditCard;
  21.  
  22.  
  23.     public Person() {
  24.     }
  25.  
  26.     public void setAddress(Address address) {
  27.         this.adresses.add(address);
  28.     }
  29.  
  30.     public void setName(String name){
  31.         this.name = name;
  32.     }
  33.  
  34.     public String getName(){
  35.         return name;
  36.     }
  37.  
  38.     public Long getId() {
  39.         return id;
  40.     }
  41.  
  42.     public void setId(Long Id) {
  43.         this.id = Id;
  44.     }
  45. }
  46.  
  47.  
  48. package no.hvl.dat250.jpa.basicexample;
  49.  
  50. import javax.persistence.*;
  51.  
  52. @Embeddable
  53. public class CreditCard {
  54.     @Id
  55.     @GeneratedValue(strategy = GenerationType.TABLE)
  56.     private int id;
  57.  
  58.     private int number;
  59.     private int limit;
  60.     private int balance;
  61.     private Bank bank;
  62.  
  63.     @Embedded
  64.     private Pincode pincode;
  65.  
  66. }
  67.  
  68. package no.hvl.dat250.jpa.basicexample;
  69.  
  70. import javax.persistence.*;
  71.  
  72. public class Bank {
  73.     @Id
  74.     @GeneratedValue(strategy = GenerationType.TABLE)
  75.     private int id;
  76.     private String name;
  77. }
  78.  
  79. package no.hvl.dat250.jpa.basicexample;
  80.  
  81. import javax.persistence.Embeddable;
  82.  
  83. @Embeddable
  84. public class Pincode {
  85.     private String pincode;
  86.     private int count;
  87.  
  88.     public Pincode(){
  89.  
  90.     }
  91.  
  92.     public String getPincode() {
  93.         return pincode;
  94.     }
  95.  
  96.     public void setPincode(String pincode) {
  97.         this.pincode = pincode;
  98.     }
  99.  
  100.     public int getCount() {
  101.         return count;
  102.     }
  103.  
  104.     public void setCount(int count) {
  105.         this.count = count;
  106.     }
  107. }
  108.  
  109. package no.hvl.dat250.jpa.basicexample;
  110.  
  111. import javax.persistence.Embeddable;
  112. import javax.persistence.*;
  113.  
  114. @Embeddable
  115. public class Address {
  116.     @Id
  117.     @GeneratedValue(strategy = GenerationType.TABLE)
  118.     private Long id;
  119.     private String street;
  120.     private int number;
  121.  
  122.     public Address() {
  123.     }
  124.  
  125.     public void setStreet(String street) {
  126.         this.street = street;
  127.     }
  128.  
  129.     public String getStreet() {
  130.         return street;
  131.     }
  132.  
  133.     public int getNumber() {
  134.         return number;
  135.     }
  136.  
  137.     public void setNumber(int number) {
  138.         this.number = number;
  139.     }
  140.  
  141.     public Long getId() {
  142.         return id;
  143.     }
  144.  
  145.     public void setId(Long Id) {
  146.         this.id = Id;
  147.     }
  148. }
  149.