Advertisement
Guest User

Untitled

a guest
May 6th, 2016
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.62 KB | None | 0 0
  1. public class MainClass {
  2.  
  3. public static void main(String args[]){
  4.  
  5. try{
  6. Session session=HibernateUtil.getSession();
  7. Transaction tx=session.beginTransaction();
  8. Employee ee=new Employee("abx","asd",2000);
  9. session.save(ee);
  10. tx.commit();
  11.  
  12.  
  13. }catch(Exception e){
  14. e.printStackTrace();
  15. }
  16. }
  17. }
  18.  
  19. package sally;
  20.  
  21. public class Employee {
  22. private int id;
  23. private String firstName;
  24. private String lastName;
  25. private int salary;
  26.  
  27. public Employee() {}
  28. public Employee(String fname, String lname, int salary) {
  29. this.firstName = fname;
  30. this.lastName = lname;
  31. this.salary = salary;
  32. }
  33. public int getId() {
  34. return id;
  35. }
  36. public void setId( int id ) {
  37. this.id = id;
  38. }
  39. public String getFirstName() {
  40. return firstName;
  41. }
  42. public void setFirstName( String first_name ) {
  43. this.firstName = first_name;
  44. }
  45. public String getLastName() {
  46. return lastName;
  47. }
  48. public void setLastName( String last_name ) {
  49. this.lastName = last_name;
  50. }
  51. public int getSalary() {
  52. return salary;
  53. }
  54. public void setSalary( int salary ) {
  55. this.salary = salary;
  56. }
  57. }
  58.  
  59.  
  60. <?xml version="1.0" encoding="utf-8"?>
  61. <!DOCTYPE hibernate-mapping PUBLIC
  62. "-//Hibernate/Hibernate Mapping DTD//EN"
  63. "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
  64.  
  65. <hibernate-mapping>
  66. <class name="sally.Employee" table="EMPLOYEE">
  67. <meta attribute="class-description">
  68. This class contains the employee detail.
  69. </meta>
  70. <id name="id" type="int" column="id">
  71. <generator class="native"/>
  72. </id>
  73. <property name="firstName" column="first_name" type="string"/>
  74. <property name="lastName" column="last_name" type="string"/>
  75. <property name="salary" column="salary" type="int"/>
  76. </class>
  77. </hibernate-mapping>
  78.  
  79. <?xml version="1.0" encoding="utf-8"?>
  80. <!DOCTYPE hibernate-configuration PUBLIC
  81. "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
  82. "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
  83. <hibernate-configuration>
  84. <session-factory>
  85. <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
  86. <property name="hibernate.connection.url">jdbc:mysql://localhost:3306/test</property>
  87. <property name="hibernate.connection.password"></property>
  88. <property name="hibernate.connection.username">root</property>
  89. <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
  90. <property name="show_sql">true</property>
  91.  
  92.  
  93. <mapping class="sally.Employee"></mapping>
  94. </session-factory>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement