Wednesday, 29 May 2013

Initial SessionFactory creation failed.java.lang.NoClassDefFoundError: net/sf/cglib/proxy/CallbackFilter

Initial SessionFactory creation failed.java.lang.NoClassDefFoundError: net/sf/cglib/proxy/CallbackFilter

ADD "cglib-nodep-2.2.3.jar"  To classpath


You can download the library here – http://cglib.sourceforge.net/

Java.Lang.NoClassDefFoundError: Javax/Transaction/Synchronization

Solution
Add "jta.jar"  to classpath

Java.Lang.NoClassDefFoundError: Javax/Transaction/Synchronization


log4j:WARN No appenders could be found for logger (org.hibernate.cfg.Environment).
log4j:WARN Please initialize the log4j system properly.
Exception in thread "main" java.lang.NoClassDefFoundError: javax/transaction/Synchronization
                at org.hibernate.impl.SessionImpl.<init>(SessionImpl.java:213)
                at org.hibernate.impl.SessionFactoryImpl.openSession(SessionFactoryImpl.java:473)
                at org.hibernate.impl.SessionFactoryImpl.openSession(SessionFactoryImpl.java:497)
                at org.hibernate.impl.SessionFactoryImpl.openSession(SessionFactoryImpl.java:505)
                at App.main(App.java:14)
Caused by: java.lang.ClassNotFoundException: javax.transaction.Synchronization
                at java.net.URLClassLoader$1.run(Unknown Source)
                at java.security.AccessController.doPrivileged(Native Method)
                at java.net.URLClassLoader.findClass(Unknown Source)
                at java.lang.ClassLoader.loadClass(Unknown Source)
                at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
                at java.lang.ClassLoader.loadClass(Unknown Source)

                ... 5 more

Solution
Add "jta.jar"  to classpath

org.hibernate.exception.GenericJDBCException: Cannot open connection

Solution Check Password


Exception in thread "main" org.hibernate.exception.GenericJDBCException: Cannot open connection
                at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:103)
                at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:91)
                at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
                at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:29)
                at org.hibernate.jdbc.ConnectionManager.openConnection(ConnectionManager.java:426)
                at org.hibernate.jdbc.ConnectionManager.getConnection(ConnectionManager.java:144)
                at org.hibernate.jdbc.JDBCContext.connection(JDBCContext.java:119)
                at org.hibernate.transaction.JDBCTransaction.begin(JDBCTransaction.java:57)
                at org.hibernate.impl.SessionImpl.beginTransaction(SessionImpl.java:1326)
                at App.main(App.java:16)
Caused by: java.sql.SQLException: Access denied for user 'root'@'localhost' (using password: YES)
                at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1073)
                at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3609)
                at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3541)
                at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:943)
                at com.mysql.jdbc.MysqlIO.secureAuth411(MysqlIO.java:4113)
                at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1308)
                at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2336)
                at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2369)
                at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2153)
                at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:792)
                at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:47)
                at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
                at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
                at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
                at java.lang.reflect.Constructor.newInstance(Unknown Source)
                at com.mysql.jdbc.Util.handleNewInstance(Util.java:411)
                at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:381)
                at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:305)
                at java.sql.DriverManager.getConnection(Unknown Source)
                at java.sql.DriverManager.getConnection(Unknown Source)
                at org.hibernate.connection.DriverManagerConnectionProvider.getConnection(DriverManagerConnectionProvider.java:110)
                at org.hibernate.jdbc.ConnectionManager.openConnection(ConnectionManager.java:423)

                ... 5 more

hibernate sql server configuration

hibernate configuration file for sql server 2008

To change the database, you must:
1.    Provide an appropriate JDBC driver for the database on the class path,
2.    Change the JDBC properties (driver, url, user, password)

3.    Change the Dialect used by Hibernate to talk to the database


<hibernate-configuration>
<session-factory>
  <property name="hibernate.connection.driver_class">com.microsoft.sqlserver.jdbc.SQLServerDriver</property>
  <property name="hibernate.connection.url">jdbc:sqlserver://127.0.0.0;databaseName=glproc</property>
  <property name="hibernate.connection.username">sa</property>
  <property name="hibernate.connection.password"> </property>
  <property name="hibernate.connection.pool_size">10</property>
  <property name="show_sql">true</property>
 <property name="hibernate.hbm2ddl.auto">create</property>
  <property name="dialect">org.hibernate.dialect.SQLServer2008Dialect</property>
  <!-- Mapping files -->
  <mapping resource="hbm/cXX.hbm.xml"/>
</session-factory>
</hibernate-configuration>

sql server maven dependency

sql server maven dependency

<dependency>
<groupId>com.microsoft.sqlserver</groupId>
  <artifactId>sqljdbc4</artifactId>
  <version>2.0</version>
</dependency>


<hibernate-configuration>
<session-factory>
  <property name="hibernate.connection.driver_class">com.microsoft.sqlserver.jdbc.SQLServerDriver</property>
  <property name="hibernate.connection.url">jdbc:sqlserver://127.0.0.0;databaseName=glproc</property>
  <property name="hibernate.connection.username">sa</property>
  <property name="hibernate.connection.password"> </property>
  <property name="hibernate.connection.pool_size">10</property>
  <property name="show_sql">true</property>
 <property name="hibernate.hbm2ddl.auto">create</property>
  <property name="dialect">org.hibernate.dialect.SQLServer2008Dialect</property>
  <!-- Mapping files -->
  <mapping resource="hbm/cXX.hbm.xml"/>
</session-factory>
</hibernate-configuration>


mvn install:install-file -Dfile=<path-to-file> -DgroupId=<group-id> 
    -DartifactId=<artifact-id> -Dversion=<version> -Dpackaging=<packaging>
 
mvn install:install-file -Dfile=sqljdbc4.jar -DgroupId=com.microsoft.sqlserver -DartifactId=sqljdbc4 -Dversion=3.0 -Dpackaging=jar



Wednesday, 8 May 2013

r cannot be resolved to a variable android

r cannot be resolved to a variable android

Go to Project Properties >
Java Build Path > Tick Android Version Checkbox
 Then if your workspace does not build automatically… Properties again > Build Project

What are the Core interfaces are of Hibernate framework

What are the Core interfaces are of Hibernate framework
Most of hibernate based application code deals with following interfaces provided by the Hibernate

Session interface
SessionFactory interface
Query and Criteria interfaces
Configuration interface
Transaction interface

How to create Userdefined Immutable Class in Java

How to create Userdefined Immutable Class in Java


1) Define class as final 
2) Define private member field as final 
3) set member field value only through constructor 
4) define only getter method of member field.

static in java

static in java

error Project facet Java version 1.7 is not supported in eclipse Fixed

Fixed error Project facet Java version 1.7 is not supported in eclipse

1: Right Click over your Project on Project Explorer and click on Properties.
2: Goto java build path->Libraries
 Check JRE System Library Jars and also check it is JDK 1.6 or 1.7
3:Goto Project Facet and select your current java version available.

Reason  It can be that java 1.7 is not installed in your system then you can use java version that is already installed in your system. 

OR
While creating new project we can do these steps

empty-field-validation-in-android

Android empty field validation in android or required field validation
we can solve this issue using setError().
———————————————
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button btn =(Button)findViewById(R.id.button1);
btn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
EditText edittext =(EditText)findViewById(R.id.editText1);
if(edittext.getText().length()==0){
edittext.setError(“please enter the value”);
}
}
});
}