Sie sind auf Seite 1von 3

q1]

Persistence is the property of storage of the copy of database object into


temporary memory.
It is used to persist data java environment to database.
--------------------------------------------------------------

q2]
Entity is when a group of states are assosciated together in a single
unit.Each entity associated with a metadata
and the metadata represents the information of it.The metadata can exist inside or
outside of the class.

An example of an Entity
Example for Entity:

import javax.persistence.*;
@Entity
public class Student {
@Id

private String name;


private int id;
private long fees;
public Student() {}
public Student(int id)
{
this.id = id;
}
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 long getFees()
{
return fees;
}
public void setFees (long fees)
{
this.fees = fees;
}
}

----------------------------------------------
q3]
-A session is used to get a physical connection with database.
-A session object is lightweight and designed to be instatiated each time an
interaction is needed with the database
-It is a short lived object and wraps a jdbc connection.It is a factory of
Transaction query and Criteria.
Persistent objects are saved and retrieved through a Session object.

Session Interface Methods:

1]Transaction beginTransaction()
Begin a unit of work and return the associated Transaction object.
2]
void cancelQuery()
Cancel the execution of the current query.
3]
Query createFilter(Object collection, String queryString)
Create a new instance of Query for the given collection and filter
string.
4]
Criteria createCriteria(String entityName)
Create a new Criteria instance, for the given entity name.
5]
Connection close()
End the session by releasing the JDBC connection and cleaning up.
6]
Criteria createCriteria(Class persistentClass)
Create a new Criteria instance, for the given entity class, or a superclass of an
entity class.
7]
Serializable getIdentifier(Object object)
Return the identifier value of the given entity as associated with this session.
8]void delete(Object Object)
delete persistant instance fro the database
------------------------------------------------------
q4]The cfg file or the configuration file give the information about the database
and mapping file.
the file is called hibernate.cfg.xml

hbm file is the mapping file,the syntax should be class_name.hbm.xml


there are many elements in the hbm file like
i]Hibernate mapping which is the root elemet and contains allmapping elements.
ii]class is a subelement of hibernate mapping element and it specifies persistent
class.
iii]id which is a subelement and specifies the key attribute of the class.
iv]generator which generates the primary key.
v]property which specifies the property name of the persistent class
------------------------------
5]
-Object relational mapping is a connecting link between the java(object) and the
database(column).
-It binds the object to the database.While mapping we have to consider the datatype
of the data and its
relation with the self entity or the entity of other table.
-orm tool simplifies the data creation,data manipution and data access.
-----------------------------------------------------------
6]Hibernate mapping types.
While mapping java datatypes into RDBMS datatypes the types declared is the
hibernate mapping types
which can translate from java to sql datatypes.
there are two types primitive type and data and time type
primitive type
egs:
mapping type javatype sqltype
integer int/java.lang.Integer INTEGER
long long/java.lang.long BIGINT

data and time type


egs:
mapping type javatype sqltype

date java.util.date DATE


time java.util.time TIME

---------------------------------------------------------------
7]
@column annotation describes
It is type of defining mapping without the use of mapping files.
It helps to replace mapping of xml mapping metadata.
there are many annotations that is used to create hibernate applications like
@id,@entity.
@Column annotation specifies the details of the column for this property or field.
If @Column annotation is not specified, property name will be used as the column
name by default.
------------------------------------------------------------
8]Steps to create configure files in a project.
The configuration file contains all the informations for the database such as
connection_url, driver_class, username,password etc.
The hbm2ddl.auto property is used to create the table in the
database automatically.
To create the configuration file, right click on src - new file. Now specify the
configuration file name e.g. hibernate.cfg.xml.
------------------------------------------------------
9]session.saveOrUpdate(Object object)
it is afuntion which is used to save or update the given instance.
It can either insert or update based on the exitence of of record.It can bring
transient and detached object to persistent state.It often reattach a detached
object into session.
--------------------------------------------------
10]When transaction is commited.
It makes permenent changes which is performed by the sql commands within the
transaction.It flushes the session.
------------------------------------------------------

Das könnte Ihnen auch gefallen