Monday, December 31, 2012

General flow of Hibernate communication with RDBMS?

  • Load the Hibernate configuration file and create configuration object. It will automatically load all hbm mapping files
  • Create session factory from configuration object
  • Get one session from this session factory
  • Create HQL Query
  • Execute query to get list containing Java objects
Reference:- http://alltechinone.in

What is Hibernate?

Hibernate is a pure Java object-relational mapping (ORM) and persistence framework that allows you to map plain old Java objects to relational database tables using (XML) configuration files. Hibernate not only takes care of the mapping from Java classes to database tables (and from Java data types to SQL data types), but also provides data query and retrieval facilities that can significantly reduce development time otherwise spent with manual data handling in SQL and JDBC.
There are several benefits of using Hibernate
  • Powerful object-oriented hibernate query language
  • Descriptive O/R Mapping through mapping file.
  •  Hibernate cache : Session Level, Query and Second level cache.
  • Transparent persistence based on POJOs without byte code processing
  • Automatic primary key generation
  • Performance: Lazy initialization, Outer join fetching, Batch fetching

linux command — “tail”: most basic use

There is most basic but powerful use of linux “tail” command. I mostly use this command to see the log files which are constantly growing.
>tail -100f catalina.out
The above use provides me a way to keep an eye on catalina.out file while it is getting updated constantly during the tomcat server start up. It always shows me last 100 lines in the catalina.out. To come out of the log view one should press CTRL+C.
The above command can be used to see the last specified number of lines of log files or any file which are getting updated by any other process.

Thursday, November 22, 2012

Silent Installation of IBM Websphere Application Server 7

Before we start installation, there is this little subtlety that we need to address. If you execute the command “ls -al `which sh`” you will see that the /bin.sh is actually pointing to a binary called ‘dash’.
~# ls -al `which sh`
lrwxrwxrwx 1 root root 4 Jun  7 20:49 /bin/sh -> dash
We need to re-link the/bin/sh to /bin/bash as the default symbolic link of sh in Ubuntu is pointing to dash. There are numerous posts on the internet talked about this. Won’t worry about why it is so, just interested to install the IBM WAS. Fix the sh sym link issue.
cd /bin
unlink sh
ln -s /bin/bash sh
Installation Steps:
1) Go to directory containing WAS archive and then untar the IBM Websphere Application Server 7 archive using following commands:-
tar -xzvf was.cd.70011.trial.base.opt.linux.ia32.tar.gz
2)  we need to create a response file named “response.txt” for silent installation in directory in the WAS directory in the expanded installation archive.
vi response.txt
Add following entries in response.txt file.
-OPT silentInstallLicenseAcceptance=”true”
-OPT disableOSPrereqChecking=”true”
-OPT installType=”installNew”
-OPT profileType=”standAlone”
-OPT feature=”noFeature”
-OPT PROF_enableAdminSecurity=”true”
-OPT PROF_adminUserName=”wasadmin”
-OPT PROF_adminPassword=”password”
-OPT PROF_profileName=”appsvr01″
-OPT PROF_defaultPorts=”true”
-OPT installLocation=”/home/was_home”
-OPT traceLevel=”INFO”
-OPT allowNonRootSilentInstall=”true”
3) It is not necessary to pre-create the installation directory. As long as the installation process has the privilege to create the folder. Otherwise create a directory “was_home” in “/home/”
4) execute the install.sh  from “WAS” directory with the following arguments
./install -options response.txt -silent
5) Now You can start the default server ‘server1′ of our profile appsvr01.
cd /home/was_home/profiles/appsvr01/bin
./startServer.sh server1
The application server instance server1 is now started.
Before starting the server make sure no other instance of server is running.
6) To stop the server
cd /home/was_home/profiles/appsvr01/bin
./stopServer.sh server1
7) To check logs go to “was_home/profiles/appsvr01/logs/server1” location.

How to increase Websphere JVM memory size without using administrative console.

JVM memory size can be increased easily using Websphere administrative console. But if server gives “out of memory Error” error when we are trying to start the server, then we need to perform following steps :-
1)    Go to location “<WAS_Home>/profiles/appsvr01/config/cells/serverNode01Cell/nodes/serverNode01/servers/server1”.  Here WAS_Home is location where websphere application server is installed.
2)    Then look for server.xml file at above mentioned location.
3)    In server.xml file find “jvmEntries” xml element.
Change initialHeapSize=”512” and add maximumHeapSize=”1526” attribute.
initialHeapSize and maximumHeapSize attributes can be modified according to your system configuration.
Now you can save the file and try starting the server, you are all set to go.

Monday, November 19, 2012

Failed to connect to the DataSource in Websphere Application Server

 
I was trying to create a data source in websphere application server using administrative console and my db (mysql) was running on same server. But I was running into following exception when I hit the test connection button.
Normally this exception occurs when JAAS alias under J2C Authentication Data Entries is not set properly, however in this case I have set the Component managed authentication alias properly. But was still having following problem:-
Could not invoke an operation on object: WebSphere:name=DataSourceCfgHelper,process=server1,platform=dynamicproxy,node=ip123Node01,version=7.0.0.11,type=DataSourceCfgHelper,mbeanIdentifier=DataSourceCfgHelper,cell=ip123Node01Cell,spec=1.0 because of an mbean exception: java.sql.SQLException: java.lang.IllegalAccessError: com/mysql/jdbc/ConnectionImpl.getInstance(Ljava/lang/String;ILjava/util/Properties;Ljava/lang/String;Ljava/lang/String;)Lcom/mysql/jdbc/Connection;
[10/5/12 5:00:37:241 UTC] 00000013 DSConfigurati W DSRA0174W: Warning: GenericDataStoreHelper is being used.
[10/5/12 5:00:37:305 UTC] 00000013 DataSourceCon E DSRA8040I: Failed to connect to the DataSource. Encountered “”: java.lang.IllegalAccessError: com/mysql/jdbc/ConnectionImpl.getInstance(Ljava/lang/String;ILjava/util/Properties;Ljava/lang/String;Ljava/lang/String;)Lcom/mysql/jdbc/Connection;
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:334)
at com.mysql.jdbc.jdbc2.optional.MysqlDataSource.getConnection(MysqlDataSource.java:443)
at com.mysql.jdbc.jdbc2.optional.MysqlDataSource.getConnection(MysqlDataSource.java:141)
at com.mysql.jdbc.jdbc2.optional.MysqlConnectionPoolDataSource.getPooledConnection(MysqlConnectionPoolDataSource.java:83)
This problem was vanished after I restarted the Websphere Application Server.