Guest User

Untitled

a guest
Mar 27th, 2018
497
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.43 KB | None | 0 0
  1. package org.hibernatetest;
  2.  
  3. public class Student {
  4. private int id;
  5. private String name;
  6. private String email;
  7. public int getId() {
  8. return id;
  9. }
  10. public void setId(int id) {
  11. this.id = id;
  12. }
  13. public String getName() {
  14. return name;
  15. }
  16. public void setName(String name) {
  17. this.name = name;
  18. }
  19. public String getEmail() {
  20. return email;
  21. }
  22. public void setEmail(String email) {
  23. this.email = email;
  24. }
  25. }
  26.  
  27. <!DOCTYPE hibernate-mapping PUBLIC
  28. "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
  29. "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
  30. <hibernate-mapping>
  31. <class name="org.hibernatetest.Student" table="STUDENT_2018">
  32. <id name="id" column="STUDENT_ID"/>
  33. <property name="name" column="STUDENT_NAME"></property>
  34. <property name="email" column="STUDENT_EMAIL"></property>
  35. </class>
  36. </hibernate-mapping>
  37.  
  38. <!DOCTYPE hibernate-configuration PUBLIC
  39. "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
  40. "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
  41. <hibernate-configuration>
  42. <session-factory>
  43. <property name="hibernate.dialect">org.hibernate.dialect.OracleDialect</property>
  44. <property name="hibernate.connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
  45. <property name="hibernate.connection.username">Test</property>
  46. <property name="hibernate.connection.password">Test</property>
  47. <property name="hibernate.connection.url">jdbc:oracle:thin:@localhost:1521:XE</property>
  48. <property name="hibernate.hbm2ddl.auto">create-drop</property>
  49. <property name="show_sql">true</property>
  50. <mapping resource="resource/Student.hbm.xml"/>
  51. </session-factory>
  52. </hibernate-configuration>
  53.  
  54. package org.hibernatetest;
  55.  
  56. import org.hibernate.Session;
  57. import org.hibernate.SessionFactory;
  58. import org.hibernate.cfg.Configuration;
  59.  
  60. public class Test {
  61.  
  62. public static void main(String[] args) {
  63. Student st = new Student();
  64. st.setId(1);
  65. st.setName("Mohan");
  66. st.setEmail("mmohan668@gmail.com");
  67.  
  68. Configuration cfg = new Configuration();
  69. SessionFactory sf = cfg.configure("resource/hibernate.cfg.xml").buildSessionFactory();
  70. Session s = sf.openSession();
  71. s.save(st);
  72. s.beginTransaction().commit();
  73. s.evict(st);
  74. }
  75.  
  76. }
Add Comment
Please, Sign In to add comment