Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package org.hibernatetest;
- public class Student {
- private int id;
- private String name;
- private String email;
- public int getId() {
- return id;
- }
- public void setId(int id) {
- this.id = id;
- }
- public String getName() {
- return name;
- }
- public void setName(String name) {
- this.name = name;
- }
- public String getEmail() {
- return email;
- }
- public void setEmail(String email) {
- this.email = email;
- }
- }
- <!DOCTYPE hibernate-mapping PUBLIC
- "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
- "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
- <hibernate-mapping>
- <class name="org.hibernatetest.Student" table="STUDENT_2018">
- <id name="id" column="STUDENT_ID"/>
- <property name="name" column="STUDENT_NAME"></property>
- <property name="email" column="STUDENT_EMAIL"></property>
- </class>
- </hibernate-mapping>
- <!DOCTYPE hibernate-configuration PUBLIC
- "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
- "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
- <hibernate-configuration>
- <session-factory>
- <property name="hibernate.dialect">org.hibernate.dialect.OracleDialect</property>
- <property name="hibernate.connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
- <property name="hibernate.connection.username">Test</property>
- <property name="hibernate.connection.password">Test</property>
- <property name="hibernate.connection.url">jdbc:oracle:thin:@localhost:1521:XE</property>
- <property name="hibernate.hbm2ddl.auto">create-drop</property>
- <property name="show_sql">true</property>
- <mapping resource="resource/Student.hbm.xml"/>
- </session-factory>
- </hibernate-configuration>
- package org.hibernatetest;
- import org.hibernate.Session;
- import org.hibernate.SessionFactory;
- import org.hibernate.cfg.Configuration;
- public class Test {
- public static void main(String[] args) {
- Student st = new Student();
- st.setId(1);
- st.setName("Mohan");
- st.setEmail("mmohan668@gmail.com");
- Configuration cfg = new Configuration();
- SessionFactory sf = cfg.configure("resource/hibernate.cfg.xml").buildSessionFactory();
- Session s = sf.openSession();
- s.save(st);
- s.beginTransaction().commit();
- s.evict(st);
- }
- }
Add Comment
Please, Sign In to add comment