Advertisement
Guest User

Untitled

a guest
Mar 10th, 2016
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.16 KB | None | 0 0
  1. @Entity
  2. @Table(name = "account")
  3. public class Account {
  4.  
  5. transient EntityManager entityManager;
  6.  
  7. @Id
  8. @GeneratedValue
  9. private Long id;
  10.  
  11. @Column(name = "username", nullable = false, unique = true)
  12. private String username;
  13.  
  14. @Column(name = "password", nullable = false)
  15. private String password;
  16.  
  17. ... getters and setters
  18.  
  19. @Transactional
  20. public void persist() {
  21. if (this.entityManager == null) this.entityManager = entityManager();
  22. this.entityManager.persist(this);
  23. }
  24.  
  25. @Transactional
  26. public Account merge() {
  27. if (this.entityManager == null) this.entityManager = entityManager();
  28. Account merged = this.entityManager.merge(this);
  29. this.entityManager.flush();
  30. return merged;
  31. }
  32.  
  33. @Configuration
  34. @ComponentScan
  35. @EnableAutoConfiguration
  36. public class Application {
  37.  
  38. public static void main(String[] args) throws Exception {
  39. SpringApplication.run(Application.class, args);
  40. }
  41.  
  42. }
  43.  
  44. spring.application.name: Test Application
  45.  
  46. spring.datasource.url: jdbc:mysql://localhost/test
  47. spring.datasource.username=root
  48. spring.datasource.password=
  49. spring.datasource.driverClassName=com.mysql.jdbc.Driver
  50. spring.jpa.hibernate.ddl-auto=update
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement