Map java Object to database.

Map java Object to database.

How do you map Java Objects with Database tables?

View Answers

March 8, 2011 at 7:14 PM

Hi Friends, There are to way for mapping of our java object to database..

Using annotation..

package net.roseindia.Model;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;

@Entity
@Table(name = "userinfo")
public class AddInformation implements Serializable {
    private String firstname;
    private int id;

    @Id
    @GeneratedValue
    @Column(name = "id")
    public int getId() {
        return id;
    }

    @Column(name = "firstname")
    public String getFirstname() {
        return firstname;
    }


    public void setFirstname(String firstname) {
        this.firstname = firstname;
    }

    public void setId(int id) {
        this.id = id;
    }   

}

By using hbm.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping auto-import="true" default-lazy="true">
    <class name="net.roseindia.model.EmployeeInfoModel" table="employeeinfo">
        <id name="id" column="id" type="java.lang.Integer">
            <generator class="increment" />
        </id>
        <property name="name" column="name" type="java.lang.String" />
        <property name="address" column="address" type="java.lang.String" />
    </class>
</hibernate-mapping>

Ads









Related Tutorials/Questions & Answers:
Map java Object to database.
Map java Object to database.  How do you map Java Objects with Database tables
How do you map Java Objects with Database tables?
How do you map Java Objects with Database tables?  Hi, How do you map Java Objects with Database tables? thanks
Advertisements
ModuleNotFoundError: No module named 'map-object'
ModuleNotFoundError: No module named 'map-object'  Hi, My Python... 'map-object' How to remove the ModuleNotFoundError: No module named 'map... have to install padas library. You can install map-object python
parse map in java
parse map in java  What is a Parser? Can you give the source code to parse map in Java
Java Map
Java Map         In Java, a Map is a kind of generalized array. It provides a more general way of storing elements. It is an object that maps keys to values. Map
Map
Map  If I have an object implementing the Map interface in Java and I wish to iterate over every pair contained within it, what is the most efficient way of going through the map either iterator or for each loop or for loop
Insert Serialized Object into Database Table
Insert Serialized Object into Database Table In the previous tutorial, you have learned about Serializing and Deserializing an object and inserting it into a file. In this section, you will learn how to Insert a serialized object
adding multiples markers to google map from a mysql database
adding multiples markers to google map from a mysql database   hello, i am trying to add markers to my googlemaps map. the latitudes and longitudes are strored in table called appreciation in a mysql database. i followed sevrel
adding multiples markers to google map from a mysql database
adding multiples markers to google map from a mysql database   hello, i am trying to add markers to my googlemaps map. the latitudes and longitudes are strored in table called appreciation in a mysql database. i followed sevrel
adding multiples markers to google map from a mysql database
adding multiples markers to google map from a mysql database   hello, i am trying to add markers to my googlemaps map. the latitudes and longitudes are strored in table called appreciation in a mysql database. i followed sevrel
adding multiples markers to google map from a mysql database
adding multiples markers to google map from a mysql database   hello, i am trying to add markers to my googlemaps map. the latitudes and longitudes are strored in table called appreciation in a mysql database. i followed sevrel
Java Map Example
Java Map Example  How we can use Map in java collection?   The Map interface maps unique keys to value means it associate value to unique...(String[] args) { Map mp = new HashMap(); mp.put(new Integer(2
java code for PartialSearch using Map????
java code for PartialSearch using Map????  java code for Partial Search using Map
Java Map Example
and value. Each key-value pair is saved in a java.util.Map.Entry object. Map... the key and values. Map.Entry defines both of these methods. Java Map Example...Map Interface adds keys to values. Every key in the Map Interface should
How to convert map to json in Java
How to convert map to json in Java  Hi, I my program I have an object of HashMap and I have to output this into json string. How to convert map... hashmap to JSON string. It provides the method toJson(map) to converting object
How to convert map to json in Java
How to convert map to json in Java  Hi, I my program I have an object of HashMap and I have to output this into json string. How to convert map... hashmap to JSON string. It provides the method toJson(map) to converting object
Object in java - Java Beginners
Object in java  Hi deepak, I am new to java, can u tell me what is class ,object and instance with example. For example : class raja , raja r.../java/master-java/java-object-oriented-language.shtml http
Is Java object oriented?
Is Java object oriented?  Hi, Is Java object oriented? Thanks   Hi, Java is object oriented programming language. It is supports OPPS concepts: Object Class Inheritance Polymorphism Abstraction Encapsulation All
Java tree map trouble
Java tree map trouble  This is a project for a class, and I am totally stuck! I've created a tree map using an input text file. I split the lines into fields so that I could work with 2 elements from the file. It appears
java is pure object oriented
java is pure object oriented  java is pure object oriented or not.? reason.?   Java is not pure object oriented language because... are not object 2)It does not support operator overloading multiple inheritance. 3
java code to compare two hash map objects
java code to compare two hash map objects  java code to compare two hash map objects
how to refresh google map using ajax by fetching lat long from database
how to refresh google map using ajax by fetching lat long from database  i have a jsp page where we select the object and by submitting the form the route travelled by it will be displayed on the google map by fetching the lat
map
map  using map, i want display message based on id selected [both are strings]   i do no   Hi Friend, Try the following code...) { Map map=new HashMap(); map.put("Message1","Hello
Introduction to Map and SortedMap Interface
in a java.util.Map.Entry object. A set of these map entries can be obtained by calling a map's... C:\nisha>java MapDemo Keys of tree map: [0, 1, 2, 3, 4... Introduction to Map and SortedMap Interface
How to convert hashmap to json in Java?
the pre-developed library for converting the Map object or any other Java object... this for converting the map to string in Java. Gson (google-gson) is an open... code of any Java object to work with. So, its good library for JSON
Object class in java
Object class in java  want an example and with an explaination about equals() method in object class? Is equals() is similar
Is Java a pure object oriented language?
Is Java a pure object oriented language?   Hi, Is Java a pure object oriented language? thanks   Hi No, Java is an object oriented programming language but not purely a object oriented language. In OOPs programming
java : object oriented
java : object oriented   (a) Write a class named CarRental... the user for the data needed for a rental and creates an object of the correct... an object of the correct type. Display the total rental fee
Java Object
Java Object      ... properties of the class or its group. Java object is an instance of the class. It takes.../java-object-oriented-language.shtml  
java database
java database  help me with this...i never learn build java database... to design and implement objects needed for a program that maintains a database.../teacher information, search it, alter it, etc. The database is maintained as a list
Deserializing an Object in java
Deserializing an Object in java     .... The given program shows how to read any data or contents from the serialized object or file. It takes a file name and then converts into java object. If any exception

Ads