Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @Entity
- @Table(name = "account")
- public class Account {
- transient EntityManager entityManager;
- @Id
- @GeneratedValue
- private Long id;
- @Column(name = "username", nullable = false, unique = true)
- private String username;
- @Column(name = "password", nullable = false)
- private String password;
- ... getters and setters
- @Transactional
- public void persist() {
- if (this.entityManager == null) this.entityManager = entityManager();
- this.entityManager.persist(this);
- }
- @Transactional
- public Account merge() {
- if (this.entityManager == null) this.entityManager = entityManager();
- Account merged = this.entityManager.merge(this);
- this.entityManager.flush();
- return merged;
- }
- @Configuration
- @ComponentScan
- @EnableAutoConfiguration
- public class Application {
- public static void main(String[] args) throws Exception {
- SpringApplication.run(Application.class, args);
- }
- }
- spring.application.name: Test Application
- spring.datasource.url: jdbc:mysql://localhost/test
- spring.datasource.username=root
- spring.datasource.password=
- spring.datasource.driverClassName=com.mysql.jdbc.Driver
- spring.jpa.hibernate.ddl-auto=update
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement