ALLInterview.com :: Home Page KalAajKal.com
 Advertise your Business Here     
Browse  |   Placement Papers  |   Company  |   Code Snippets  |   Certifications  |   Visa Questions
Post Question  |   Post Answer  |   My Panel  |   Search  |   Articles  |   Topics  |   ERRORS new
   Refer this Site  Refer This Site to Your Friends  Site Map  Bookmark this Site  Set it as your HomePage  Contact Us     Login  |  Sign Up                      
tip       Ask Questions on ANYTHING, that arise in your Daily Life at     FORUM9.COM
Google
 
Categories  >>  Software  >>  Advanced Java  >>  Java J2EE  >>  Java Related
 
 


 

 
 Core Java interview questions  Core Java Interview Questions
 Advanced Java interview questions  Advanced Java Interview Questions
 Swing interview questions  Swing Interview Questions
 EJB interview questions  EJB Interview Questions
 Servlets interview questions  Servlets Interview Questions
 Struts interview questions  Struts Interview Questions
 JDBC interview questions  JDBC Interview Questions
 JMS interview questions  JMS Interview Questions
 SunOne interview questions  SunOne Interview Questions
 J2EE interview questions  J2EE Interview Questions
 Weblogic interview questions  Weblogic Interview Questions
 Websphere interview questions  Websphere Interview Questions
 Java Networking interview questions  Java Networking Interview Questions
 Java J2EE AllOther interview questions  Java J2EE AllOther Interview Questions
Question
Dear freinds... I want to know how to write self mapping 
for a table using hibernate?
 Question Submitted By :: Sudheerj2ee
I also faced this Question!!     Rank Answer Posted By  
 
  Re: Dear freinds... I want to know how to write self mapping for a table using hibernate?
Answer
# 1
contact.java
------------

package com.tutorial.hibernate;

public class Contact {
	private String firstName;
	private String lastName;
	private String email;
	private long id;

	public String getEmail() {
		return email;
	}

	public String getFirstName() {
		return firstName;
	}


	public String getLastName() {
		return lastName;
	}

	public void setEmail(String string) {
		email = string;
	}

	public void setFirstName(String string) {
		firstName = string;
	}

	public void setLastName(String string) {
		lastName = string;
	}


	public long getId() {
		return id;
	}


	public void setId(long l) {
		id = l;
	}

}

--------------------------------------------------------
FirstExample.java
------------------
package com.tutorial.hibernate;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;
public class FirstExample {
	public static void main(String[] args) {
		Session session = null;
		try {
			SessionFactory sessionFactory = new 
Configuration().configure()
					.buildSessionFactory
();
			session = sessionFactory.openSession
();
			Transaction tx = 
session.beginTransaction();
			Contact contact = new Contact();
			contact.setId(3);
			contact.setFirstName("sita");
			contact.setLastName("ram");
			contact.setEmail
("sitam75@gmail.com");
			session.save(contact);
			tx.commit();	
		} catch (Exception e) {
			System.out.println(e.getMessage());

		} finally {
			// Actual contact insertion will 
happen at this step
			session.flush();
			session.close();

		}

	}
}

--------------------------------------------------------
contact.hbm.xml
---------------

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC 
    "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
    "http://hibernate.sourceforge.net/hibernate-mapping-
3.0.dtd">
<hibernate-mapping>
  <class name="com.tutorial.hibernate.Contact" 
table="CONTACT">
	   <id name="id" type="long" column="ID" >
	   <generator class="assigned"/>
	  </id>

	  <property name="firstName">
		 <column name="FIRSTNAME" />
	  </property>
	  <property name="lastName">
		<column name="LASTNAME"/>
	  </property>
	  <property name="email">
		<column name="EMAIL"/>
	  </property>
   </class>

   </hibernate-mapping>

-----------------------------------------------------
contact.hbm.xml file is a selfmapping file.
 
Is This Answer Correct ?    6 Yes 2 No
Dsr
 

 
 
 
Other Advanced Java Interview Questions
 
  Question Asked @ Answers
 
What are Benefits of Connection Pooling?  1
what is the RMI / IIOP?  3
Define the remote interface?  1
What is runnable?  2
What is Lock Based Protocol and what is its use? Wipro1
Why DOM Parser would take more Memory than SAX parser while they are parsing? OnMobile3
What is Bootstrapping in RMI?  1
suppose i open my yahoo mail.then copy the url. then sign out & close browser.then open browser paste that url on the browser.will i get my mail opened or not? i know it ill not.but how it work.how i create like this type of secure site?  7
What is Connection Pooling? Infosys1
What is MOM? Wipro1
How to get an image from db2 database plz help as soon as possible  1
What is the difference between a stub and a skeleton? ABC3
What is the name of the state, when a thread is executing?  4
What is the initial state, When a thread is created and started?  2
what is a dirty read?  1
How many ways can a thread be used? Sun-Microsystems3
What are the disadvantages of using threads? Oracle2
can a static method be overridden SolutionNET27
What is the need of serialize? Wipro1
Is System.err.println(""Statement"); is execute the output on console . Example: System.err.println("Hello JAVA");  6
 
For more Advanced Java Interview Questions Click Here 
 
 
 
 
 
   
Copyright Policy  |  Terms of Service  |  Help  |  Site Map 1  |  Articles  |  Site Map  |   Site Map  |  Contact Us interview questions urls   External Links 
   
Copyright © 2007  ALLInterview.com.  All Rights Reserved.

ALLInterview.com   ::  Forum9.com   ::  KalAajKal.com