Advertisement
Guest User

Untitled

a guest
Aug 12th, 2016
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.72 KB | None | 0 0
  1. @Entity
  2. @Table(name ="client")
  3. @NamedQuery(name="Client.getAll", query = "SELECT c FROM Client c")
  4. public class Client {
  5. @Id
  6. @GeneratedValue(strategy = GenerationType.AUTO)
  7. public Long id;
  8.  
  9. @Column(name="first_name", length = 25)
  10. private String firstName;
  11.  
  12. @Column(name="surname", length = 25)
  13. private String surName;
  14.  
  15. @Column(name="password", length = 30)
  16. private String password;
  17. @Column(name="email")
  18. private String email;
  19.  
  20. public void add(Client client){
  21. em.getTransaction().begin();
  22. em.persist(client);
  23. em.getTransaction().commit();
  24.  
  25. }
  26. public List<Client> findClientByEmail(String email){
  27. return em.createQuery(
  28. "SELECT c FROM Client c WHERE c.email LIKE :custEmail")
  29. .setParameter("custEmail", email)
  30. .setMaxResults(1)
  31. .getResultList();
  32. }
  33.  
  34. public Client login(ClientDTO clientDTO){
  35. List<Client> clientList;
  36. clientList = clientDAO.findClientByEmail(clientDTO.getEmail());
  37. validLogin(clientList);
  38. Client client = clientList.get(0);
  39. validLogin(clientDTO, client);
  40. return client;
  41. }
  42.  
  43. <persistence-unit name="Vlad" transaction-type="RESOURCE_LOCAL">
  44. <provider>org.hibernate.ejb.HibernatePersistence</provider>
  45.  
  46. <properties>
  47. <property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver"/>
  48. <property name="hibernate.connection.url" value="jdbc:mysql://localhost:3306/clients"/>
  49. <property name="hibernate.connection.username" value="root"/>
  50. <property name="hibernate.connection.password" value="root"/>
  51. <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/>
  52. <property name="hibernate.hbm2ddl.auto" value="update"/>
  53. </properties>
  54. </persistence-unit>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement