Powered by Blogger.

Difference between load( ) vs get( ) in Hibernate

>> Wednesday, March 23, 2011

The following Hibernate code snippet retrieves a User object from the database:

load()
--------------
1). Only use the load()method if you are sure that the object exists.
2). load() method will throw an exception if the unique id is not found in the database.
3). load() just returns a proxy by default and database won’t be hit until the proxy is first invoked.

Read more..

What are the JSP page attributes

>> Tuesday, March 22, 2011

Syntax of the declaration of the page directive with it's attributes is <%@ page attributeName="values" %>. The space between the tag <%@ and %> before the page(directive name) and after values of the last attribute, is optional, you can leave the space or not.


Following are name of the attributes of the page directive used in JSP:

JSP Page Directive Attributes


  • language
  • extends
  • import
  • session
  • buffer
  • autoflush
  • info
  • errorPage
  • isErrorPage
  • isThreadSafe

Read more..

What is the difference between doGet() and doPost() methods ?

>> Monday, March 21, 2011

The difference has given below......


 
doGet

doPost
In doGet Method the parameters are appended to the URL and sent along with header information
In doPost parameters are sent in separate line in the body
Maximum size of data that can be sent using doget is 240 bytes
There is no maximum size for data
Parameters are not encrypted
Parameters are encrypted
DoGet method generally is used to query or to get some information from the server
DoPost is slower compared to doGet since doPost does not write the content length
DoGet should be idempotent. i.e. doget should be able to be repeated safely many times
This method does not need to be idempotent. Operations requested through POST can have side effects for which the user can be held accountable for example updating stored data or buying items online.
DoGet should be safe without any side effects for which user is held responsible.
This method does not need to be either safe.





Read more..

Disadvantages of Hibernate

>> Sunday, March 20, 2011

The main disadvantages of Hibernate is given in detail.

1) Steep learning curve.

2) Use of Hibernate is an overhead for the applications which are :

• simple and use one database that never change
• need to put data to database tables, no further SQL queries
• there are no objects which are mapped to two different tables
Hibernate increases extra layers and complexity. So for these types of applications JDBC is the best choice.

3) Support for Hibernate on Internet is not sufficient.

Read more..

JDBC Vs Hibernate

>> Saturday, March 19, 2011


Why is Hibernate better than JDBC

1)   Relational Persistence for JAVA

Working with both Object-Oriented software and Relational Database is complicated task with JDBC because there is mismatch between how data is represented in objects versus relational database. So with JDBC, developer has to write code to map an object model's data representation to a relational data model and its corresponding database schema. Hibernate is flexible and powerful ORM solution to map Java classes to database tables. Hibernate itself takes care of this mapping using XML files so developer does not need to write code for this.

2)   Transparent Persistence

The automatic mapping of Java objects with database tables and vice versa is called Transparent Persistence. Hibernate provides transparent persistence and developer does not need to write code explicitly to map database tables tuples to application objects during interaction with RDBMS. With JDBC this conversion is to be taken care of by the developer manually with lines of code.

Read more..

Hibernate communication with RDBMS

General steps:

1. Load the Hibernate configuration file and create configuration object. It will automatically load all hbm           mapping files.
2. Create session factory from configuration object
3. Get one session from this session factory.
4. Create HQL query.
5. Execute query to get list containing Java objects.

Example: Retrieve list of employees from Employee table using Hibernate. /* Load the hibernate configuration file */

Configuration cfg = new Configuration(); cfg.configure(CONFIG_FILE_LOCATION);

/* Create the session factory */

SessionFactory sessionFactory = cfg.buildSessionFactory();

/* Retrieve the session */

Session session = sessionFactory.openSession();

/* create query */

Query query = session.createQuery("from  EmployeeBean”);

/* execute query and get result in form of Java objects */ List finalList = query.list();

EmployeeBean.hbm.xml File


"-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">




















Read more..

Related Posts Plugin for WordPress, Blogger...
© javabynataraj.blogspot.com from 2009 - 2022. All rights reserved.