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

Wednesday, 19 August 2015

Exception in thread "main" java.lang.ExceptionInInitializerError at Test.Test.main(Test.java:20) Caused by: org.hibernate.HibernateException: /hibernate.cfg.xml not found

such type of exception may occur in hibernate when the configuration file - hibernate.cfg.xml can not be located by the hibernate system while developing project in Eclipse IDE. it is because if you have not given the path for the hibernate.cfg.xml file properly ..
if in your eclipse project if you are keeping your files in different packages then make sure you gave the path of the packages..
to solve the above problem you need to follow the below steps
Procedure number 1:
1)you need the give the path of the package in your mapping file(say here employee.hbm.xml)  for the name attribute of  <class name="<here>"  >  tag ..

2)and also you need to provide the full package path in the  <mapping resource="<here> "> tag of the hibernate.cfg.xml file

again while creating the Configuration  Object also you need to provide the full package name in the configure(< here> ) method

so by above process you make your hibernate system know from where to locate the hibernate.cfg.xml file

Procedure number 2

instead of procedure number 1 you can simply place you configuration file and mapping file inside the classes folder of WEB-INF 
simply copy and paste the hibernate.cfg.xml and hbm.xml(here employee.hbm.xml inside the classes folder of WEB-INF folder


Tuesday, 18 August 2015

Exception in thread "main" org.hibernate.HibernateException: 'hibernate.dialect' must be set when no Connection available

Such exception occurs usually in cases like if  we missed the configure() method while creating Configuration Object for Hibernate system followed by  the SessionFactory object.
one of the simplest way to remove such exception is simply by adding configure() method

here is an example of such case

   the easy to solve this problem is simply replace this code by
Configuration config=new Configuratio().configure();
or
Configuration config=new Configuration();
config.configure();

hope it solved your problem


thanks and regards 
ErrorsException Team