Last active
September 6, 2016 18:37
-
-
Save thjanssen/e2fbe2ed6fd6aa7db1031301b8e0636c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @Entity | |
| public class Customer { | |
| @Id | |
| @GeneratedValue(strategy = GenerationType.AUTO) | |
| @Column(name = “id”, updatable = false, nullable = false) | |
| private Long id; | |
| @Column | |
| private String firstName; | |
| @Column | |
| private String lastName; | |
| @Column | |
| @ColumnTransformer(read = “pgp_sym_decrypt(creditCardNumber, ‘mySecretKey’)”, write = “pgp_sym_encrypt(?, ‘mySecretKey’)”) | |
| private String creditCardNumber; | |
| @Version | |
| @Column(name = “version”) | |
| private int version; | |
| … | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| insert into Customer (creditCardNumber, firstName, lastName, version, id) values (pgp_sym_encrypt(‘1234 5678 9012 3456’, ‘mySecretKey’), ‘Jane’, ‘Doe’, 0, 2); | |
| SELECT pgp_sym_decrypt(creditCardNumber, ‘mySecretKey’) FROM customer; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Customer c = new Customer(); | |
| c.setFirstName(“John”); | |
| c.setLastName(“Doe”); | |
| c.setCreditCardNumber(“1234 5678 9012 3456”); | |
| em.persist(c); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 13:13:03,840 DEBUG SQL:92 – insert into Customer (creditCardNumber, firstName, lastName, version, id) values (pgp_sym_encrypt(?, ‘mySecretKey’), ?, ?, ?, ?) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Customer c2 = em.find(Customer.class, c.getId()); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 13:13:03,992 DEBUG SQL:92 – select customer0_.id as id1_0_0_, pgp_sym_decrypt(customer0_.creditCardNumber, ‘mySecretKey’) as creditCa2_0_0_, customer0_.firstName as firstNam3_0_0_, customer0_.lastName as lastName4_0_0_, customer0_.version as version5_0_0_ from Customer customer0_ where customer0_.id=? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment