Advertisement
Guest User

Untitled

a guest
Nov 17th, 2012
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.16 KB | None | 0 0
  1. persistence.xml:
  2. <persistence>
  3. <persistence-unit name="RS">
  4. <provider>org.hibernate.ejb.HibernatePersistence</provider>
  5. <properties>
  6. <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/>
  7. <property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver"/>
  8. <property name="hibernate.connection.url" value="jdbc:mysql://localhost:3306/dp?zeroDateTimeBehavior=convertToNull"/>
  9. <property name="hibernate.connection.username" value="root"/>
  10. <property name="hibernate.connection.password" value="admin"/>
  11. <property name="hibernate.show_sql" value="true"/>
  12. <property name="hibernate.connection.autocommit" value="true"/>
  13. <property name="hibernate.current_session_context_class" value="managed"/>
  14. <property name="hibernate.hbm2ddl.auto" value="update"/>
  15. </properties>
  16. </persistence-unit>
  17. </persistence>
  18.  
  19.  
  20. hibernate.cfg.xml:
  21. <?xml version="1.0" encoding="UTF-8"?>
  22. <!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
  23. <hibernate-configuration>
  24. <session-factory>
  25. <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
  26. <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
  27. <property name="hibernate.connection.url">jdbc:mysql://localhost:3306/dp?zeroDateTimeBehavior=convertToNull</property>
  28. <property name="hibernate.connection.username">root</property>
  29. <property name="hibernate.connection.password">admin</property>
  30. <property name="hibernate.show_sql">true</property>
  31. <property name="hibernate.connection.autocommit">true</property>
  32. <property name="hibernate.current_session_context_class">managed</property>
  33. <property name="hibernate.hbm2ddl.auto">update</property>
  34.  
  35. <mapping class="cz.muni.fi.dp.reservationsystem.dao.Computer"/>
  36. <mapping class="cz.muni.fi.dp.reservationsystem.dao.User"/>
  37. <mapping class="cz.muni.fi.dp.reservationsystem.dao.Reservation"/>
  38. </session-factory>
  39.  
  40.  
  41. UserSessionBean:
  42. @Stateless
  43. @LocalBean
  44. public class UserSessionBean {
  45. @PersistenceContext(unitName = "RS")
  46. private EntityManager em;
  47.  
  48. public void persist(Object obj) {
  49. em.persist(obj);
  50. }
  51. }
  52.  
  53.  
  54. UserBean:
  55. public class UserBean implements Serializable {
  56. private boolean badLogin = false;
  57. private boolean remember;
  58. private UserDAO udao;
  59. private String email;
  60. private String password;
  61. private String name;
  62.  
  63. @EJB
  64. private UserSessionBean usb;
  65.  
  66. public String register() {
  67. User user = new User();
  68. user.setEmail(email.toLowerCase());
  69. user.setPassword(password);
  70. user.setUserName(name);
  71. usb.persist(user);
  72. newUser = true;
  73. ResourceBundle msg = ResourceBundle.getBundle("messages", new Locale(LanguageBean.getLocaleFromCookie()));
  74.  
  75. FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(msg.getString("successfulRegistration")));
  76. return null;
  77. }
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement