Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package org.hibernate.pojo;
- import javax.persistence.Column;
- import javax.persistence.Entity;
- import javax.persistence.GeneratedValue;
- import javax.persistence.Id;
- import javax.persistence.Table;
- @Entity
- @Table(name="employee")
- public class Employee {
- @Id
- @GeneratedValue
- Integer id;
- @Column(name="Employee_Name")
- String userName;
- @Column(name="Address")
- String age;
- public Integer getId() {
- return id;
- }
- public void setId(Integer id) {
- this.id = id;
- }
- /**
- * Hi this is to test java commenting
- * @return
- */
- public String getUserName() {
- return userName;
- }
- public void setUserName(String userName) {
- this.userName = userName;
- }
- public String getAge() {
- return age;
- }
- public void setAge(String age) {
- this.age = age;
- }
- }
- <?xml version="1.0" encoding="utf-8"?>
- <!DOCTYPE hibernate-configuration PUBLIC
- "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
- "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
- <hibernate-configuration>
- <session-factory>
- <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
- <property name="hibernate.connection.password">$Ailaja12</property>
- <property name="hibernate.connection.url">jdbc:mysql://localhost:3306/sessions</property>
- <property name="hibernate.connection.username">root</property>
- <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
- <property name="hibernate.bytecode.use_reflection_optimizer">false</property>
- <!-- <property name="show_sql">true</property> -->
- <!-- <mapping resource="org/hibernate/pojo/Employee.xml"></mapping> -->
- <mapping class="org.hibernate.pojo.Employee"/>
- <mapping resource="org/hibernate/pojo/Item.xml"></mapping>
- </session-factory>
- </hibernate-configuration>
- package org.hibernate.client;
- import org.hibernate.Session;
- import org.hibernate.SessionFactory;
- import org.hibernate.Transaction;
- import org.hibernate.cfg.AnnotationConfiguration;
- import org.hibernate.cfg.Configuration;
- import org.hibernate.pojo.Employee;
- public class Client {
- /**
- * @param args
- */
- public static void main(String[] args) {
- //Starting hibernate environment in your application
- Configuration conf = new Configuration();
- //2 Loading hibernate configuration file
- conf.configure("hibernate.cfg.xml");
- SessionFactory factory=new AnnotationConfiguration().configure("hibernate.cfg.xml").buildSessionFactory();
- //SessionFactory factory = conf.buildSessionFactory();
- Session session = factory.getCurrentSession();
- Employee ee = new Employee();
- ee.setUserName("Kranthi");
- //ee.setId(123);
- ee.setAge("Dallas");
- Transaction tx = session.beginTransaction();
- session.save(ee);
- tx.commit();
- session.close();
- factory.close();
- }
- }
- antlr_2.7.6.jar
- asm-3.3.1.jar
- cglib-2.2.2.jar
- domj-1.3.jar
- ehcache.jar
- hibernate-3.2.jar
- javax.persistence.jar
- jta.jar
- mysql-connector.jar
- commonlogging.jar
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement