Thursday, 17 September 2015

How to activate scott schema in Oracle Express Edition


SCOTT is a database username in ORACLE  database software.
In Scott Schema we have some default tables like emp, dept, salgrade, bonus..
these tables are so well designed that every functionalities supported by Oracle works on these tables. so for the SQL practitioner  these tables are really helpful . But now this scott schema is not available in the current versions of oracle( oracle 9i onwards) in newer version we have hr and other schemas  for practice . but for the old practitioner  we feel easy while practicing on these default tables .
so if you want to enable the scott schema in your version of Oracle you can follow the below simple steps

step1) login to oracle as the System DBA
    sql> conn system/manager ;
then search the file SCOTT.sql in your oracle installation directory then copy the path of the SCOTT.sql and enter into the sql prompt
SQL> @%ORACLE_HOME%\RDBMS\ADMIN\SCOTT.sql;
 (in my system "@C:\oraclexe\app\oracle\product\10.2.0\server\RDBMS\ADMIN\scott.sql"
so i will do like
SQL>@C:\oraclexe\app\oracle\product\10.2.0\server\RDBMS\ADMIN\scott.sql )
SQL> connect scott/tiger
Connected.

easy final steps
 sql> conn system/manager ;
connected.
SQL>@C:\oraclexe\app\oracle\product\10.2.0\server\RDBMS\ADMIN\scott.sql )
SQL> connect scott/tiger
Connected.

so now you can use the SCOTT schema and can have the default tables of SCOTT schema.



hope this tutorial is helpful to you
thanks




Wednesday, 16 September 2015

LazyInitializationException in Hibernate

This is a pretty inconvenient situation occurs while using Hibernate ORM for developing Data Access Layer logic  in our java application .

Though Lazy loading is considered as one of the greatest advantage given by hibernate while considering the performance still we got situations like the LazyInitializationExceptions.
As lazy loading reduces hits to the database by the principle like "prepare food only when you are hungry , but don't prepare food even though you are not hungry presently . so when you prepare food even though you are not hungry then the food may get waste"

Like wise if you don't require the data urgently then don't go to the data base directly . only go to the database when you need to access the data. this way hibernate reduces unnecessary hits to the database.

Now ,We can consider a situation like

suppose an object employee is being loaded using load() method and also the lazy attribute is configured as true
  Employee employee=(Employee)session.load(Employee.class,101);
        session.close();
   int no=employee.getEmployeeNo();

here getter method getEmployee()  is used to get the employeeNo from the employee object but before that the session is closed then we have no Connection to the database  and as we know when an object is loaded using the load() method with the lazy attribute equal to true then hibernate returns the proxy class object of Employee instead of real Employee class object from database and the proxy is having only the id assigned to it.
 (proxy class> ---$$--javaassist_0 class)
so when we try to access the other properties by calling getter method on the object  and before that if the session is closed then hibernate couldn't load the object from the database and it throws
LazyInitializationException .


hope the article is helpful to you
in case any query feel free to comment below..



Monday, 7 September 2015