Advertisement
Guest User

Untitled

a guest
Sep 3rd, 2016
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.20 KB | None | 0 0
  1. package org.hibernate.pojo;
  2.  
  3. import javax.persistence.Column;
  4. import javax.persistence.Entity;
  5. import javax.persistence.GeneratedValue;
  6. import javax.persistence.Id;
  7. import javax.persistence.Table;
  8.  
  9. @Entity
  10. @Table(name="employee")
  11. public class Employee {
  12.  
  13. @Id
  14. @GeneratedValue
  15. Integer id;
  16. @Column(name="Employee_Name")
  17. String userName;
  18. @Column(name="Address")
  19. String age;
  20.  
  21.  
  22.  
  23. public Integer getId() {
  24. return id;
  25. }
  26. public void setId(Integer id) {
  27. this.id = id;
  28. }
  29. /**
  30. * Hi this is to test java commenting
  31. * @return
  32. */
  33. public String getUserName() {
  34. return userName;
  35. }
  36. public void setUserName(String userName) {
  37. this.userName = userName;
  38. }
  39. public String getAge() {
  40. return age;
  41. }
  42. public void setAge(String age) {
  43. this.age = age;
  44. }
  45.  
  46. }
  47.  
  48. <?xml version="1.0" encoding="utf-8"?>
  49. <!DOCTYPE hibernate-configuration PUBLIC
  50. "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
  51. "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
  52. <hibernate-configuration>
  53. <session-factory>
  54.  
  55. <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
  56. <property name="hibernate.connection.password">$Ailaja12</property>
  57. <property name="hibernate.connection.url">jdbc:mysql://localhost:3306/sessions</property>
  58. <property name="hibernate.connection.username">root</property>
  59. <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
  60.  
  61.  
  62. <property name="hibernate.bytecode.use_reflection_optimizer">false</property>
  63. <!-- <property name="show_sql">true</property> -->
  64.  
  65.  
  66. <!-- <mapping resource="org/hibernate/pojo/Employee.xml"></mapping> -->
  67. <mapping class="org.hibernate.pojo.Employee"/>
  68. <mapping resource="org/hibernate/pojo/Item.xml"></mapping>
  69. </session-factory>
  70. </hibernate-configuration>
  71.  
  72. package org.hibernate.client;
  73.  
  74. import org.hibernate.Session;
  75. import org.hibernate.SessionFactory;
  76. import org.hibernate.Transaction;
  77. import org.hibernate.cfg.AnnotationConfiguration;
  78. import org.hibernate.cfg.Configuration;
  79. import org.hibernate.pojo.Employee;
  80.  
  81.  
  82.  
  83. public class Client {
  84.  
  85. /**
  86. * @param args
  87. */
  88. public static void main(String[] args) {
  89.  
  90. //Starting hibernate environment in your application
  91. Configuration conf = new Configuration();
  92.  
  93. //2 Loading hibernate configuration file
  94. conf.configure("hibernate.cfg.xml");
  95.  
  96. SessionFactory factory=new AnnotationConfiguration().configure("hibernate.cfg.xml").buildSessionFactory();
  97.  
  98.  
  99. //SessionFactory factory = conf.buildSessionFactory();
  100.  
  101. Session session = factory.getCurrentSession();
  102.  
  103. Employee ee = new Employee();
  104. ee.setUserName("Kranthi");
  105. //ee.setId(123);
  106. ee.setAge("Dallas");
  107.  
  108. Transaction tx = session.beginTransaction();
  109. session.save(ee);
  110. tx.commit();
  111.  
  112. session.close();
  113. factory.close();
  114. }
  115.  
  116. }
  117.  
  118. antlr_2.7.6.jar
  119. asm-3.3.1.jar
  120. cglib-2.2.2.jar
  121. domj-1.3.jar
  122. ehcache.jar
  123. hibernate-3.2.jar
  124. javax.persistence.jar
  125. jta.jar
  126. mysql-connector.jar
  127. commonlogging.jar
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement