Java

Java is a set of computer software and specifications developed by Sun Microsystems, which was later acquired by the Oracle Corporation, that provides a system for developing application software and deploying it in a cross-platform computing environment. Java is used in a wide variety of computing platforms from embedded devices and mobile phones to enterprise servers and supercomputers.

Spring Logo

Spring Framework

The Spring Framework provides a comprehensive programming and configuration model for modern Java-based enterprise applications - on any kind of deployment platform. A key element of Spring is infrastructural support at the application level: Spring focuses on the "plumbing" of enterprise applications so that teams can focus on application-level business logic, without unnecessary ties to specific deployment environments.

Hibernate Logo

Hibernate Framework

Hibernate ORM is an object-relational mapping framework for the Java language. It provides a framework for mapping an object-oriented domain model to a relational database.

Showing posts with label Exceptions. Show all posts
Showing posts with label Exceptions. Show all posts

Friday, February 27, 2015

Exception in thread "main" org.hibernate.MappingException: Cannot use identity column key generation with mapping for:


Exception in thread "main" org.hibernate.MappingException: Cannot use identity column key generation with <union-subclass> mapping for: com.varasofttech.pojo.table_per_concrete_class.PermanentEmployee
    at org.hibernate.persister.entity.UnionSubclassEntityPersister.<init>(UnionSubclassEntityPersister.java:96)
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 org.hibernate.persister.internal.PersisterFactoryImpl.create(PersisterFactoryImpl.java:163)
at org.hibernate.persister.internal.PersisterFactoryImpl.createEntityPersister(PersisterFactoryImpl.java:135)
at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:401)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1859)
at com.varasofttech.util.HibernateUtil.buildSessionFactory(HibernateUtil.java:36)
at com.varasofttech.util.HibernateUtil.getSessionFacoty(HibernateUtil.java:22)
at com.varasofttech.client.Application.main(Application.java:22)
Entity:
@Entity
@Table(name="Persons")
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
public class Person implements Serializable {
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
private long id;
// some other properties
}
Problem:
Hibernate does not support the use of identity or increment generation strategy for "table per concrete class with union strategy".

@Entity
@Table(name="Persons")
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
public class Person implements Serializable {

@Id
@GeneratedValue(strategy=GenerationType.TABLE)
private long id;
// some other properties

}

org.hibernate.MappingException: Unknown entity

Problem:
This exception will occur mainly because of the following two reasons

1. Making the @Entity with the wrong annotation

import org.hibernate.annotations.Entity; 
@Entity
public class Employee implements Serializable {
...
}
solution for this one is changing the package name.
import javax.persistence.Entity;
2. Missing the @Entity annotation

public class Employee implements Serializable {
...
}

solution for this one is adding the @Entity annotation to the class.

import javax.persistence.Entity;

@Entity
public class Employee implements Serializable {

}


Happy Coding!!!

Monday, February 2, 2015

The method getDispatcherType() is undefined for the type HttpServletRequest

An error occurred at line: [42] in the generated java file: [D:\Upgrade\Upgrade_Eclipse_Worlspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\work\Catalina\localhost\Spring4Hiberante4Integration\org\apache\jsp\WEB_002dINF\pages\employeeList_jsp.java]

The method getDispatcherType() is undefined for the type HttpServletRequest

Solution:

<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
</dependency>

Tuesday, January 27, 2015

No data type for node: org.hibernate.hql.internal.ast.tree.IdentNode \-[IDENT] IdentNode: 'e' {originalText=e}

org.springframework.web.util.NestedServletException: Request processing failed; nested exception is java.lang.IllegalStateException: No data type for node: org.hibernate.hql.internal.ast.tree.IdentNode 
 \-[IDENT] IdentNode: 'e' {originalText=e}

HQL query:
Query query = session.createQuery("SELECT e FROM Employee");

Problem: 
In the above query, 'e' alias name is given in Employee table.

Solution: 
Query query = session.createQuery("SELECT e FROM Employee e");

Sunday, January 18, 2015

Caused by: java.lang.ClassNotFoundException: javax.servlet.SessionCookieConfig

Exception:

Caused by: java.lang.ClassNotFoundException: javax.servlet.SessionCookieConfig
        at java.net.URLClassLoader$1.run(URLClassLoader.java:372)
        at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:360)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
        ... 38 more

Solution: We need to migrate Servlet version 2.5 to 3.0.1

The final dependency was

<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.0.1</version>
</dependency>

Tuesday, June 3, 2014

Exception in thread "main" org.hibernate.HibernateException: Access to DialectResolutionInfo cannot be null when 'hibernate.dialect' not set

Exception in thread "main" org.hibernate.HibernateException: Access to DialectResolutionInfo cannot be null when 'hibernate.dialect' not set
    at org.hibernate.engine.jdbc.dialect.internal.DialectFactoryImpl.determineDialect(DialectFactoryImpl.java:104)
    at org.hibernate.engine.jdbc.dialect.internal.DialectFactoryImpl.buildDialect(DialectFactoryImpl.java:71)
    at org.hibernate.engine.jdbc.internal.JdbcServicesImpl.configure(JdbcServicesImpl.java:209)
    at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:111)
    at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:234)
    at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:206)
    at org.hibernate.cfg.Configuration.buildTypeRegistrations(Configuration.java:1885)
    at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1843)
    at com.ranga.MultiTenancyDemo.main(MultiTenancyDemo.java:34)
 

Problem:

// Create the SessionFactory from hibernate.cfg.xml
        Configuration configuration = new Configuration();
       
         System.out.println("Hibernate Configuration loaded.");
       
        //apply configuration property settings to StandardServiceRegistryBuilder
        serviceRegistry = new StandardServiceRegistryBuilder().applySettings(
                configuration.getProperties()).build();
        System.out.println("Hibernate serviceRegistry created.");
       
        sessionFactory = configuration.buildSessionFactory(serviceRegistry);
        System.out.println("Hibernate sessionFactory object created.");    

Solution:

After creation of Configuration object, we need to call the         configuration.configure("hibernate.cfg.xml"); method.

Thursday, April 3, 2014

Exception in thread "main" org.hibernate.HibernateException: persist is not valid without active transaction



Problem:  The problem in Configuration file.

<bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">       
        <property name="dataSource" ref="dataSource"></property>       
        <!-- Configuring the  Hibernate properties -->
        <property name="hibernateProperties">
            <props>
                <prop key="hibernate.dialect">${hibernate.dialect}</prop>
                <prop key="hbm2ddl.auto">${hibernate.hbm2ddl.auto}</prop>
                <prop key="hibernate.show_sql">${hibernate.show_sql}</prop>               
                <prop key="hibernate.current_session_context_class">${hibernate.current_session_context_class}</prop>
            </props>       
        </property>
        <property name="annotatedClasses">
            <list>
                <value>com.ranga.Employee</value>
            </list>
        </property>       
    </bean>

------------------------------------------------------------------------------------------------------------------------------

hibernate.current_session_context_class is required only for JTA transactions.

Solution: Remove the hibernate.current_session_context_class property in sessionFactory. Now the code looks like

<bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">       
        <property name="dataSource" ref="dataSource"></property>       
        <!-- Configuring the  Hibernate properties -->
        <property name="hibernateProperties">
            <props>
                <prop key="hibernate.dialect">${hibernate.dialect}</prop>
                <prop key="hbm2ddl.auto">${hibernate.hbm2ddl.auto}</prop>
                <prop key="hibernate.show_sql">${hibernate.show_sql}</prop>               
            </props>       
        </property>
        <property name="annotatedClasses">
            <list>
                <value>com.ranga.Employee</value>
            </list>
        </property>       
    </bean>

Click here to see more information.



java.lang.NoClassDefFoundError: org/aopalliance/intercept/MethodInterceptor

Problem:

While doing transactions management with the annotations, prior to Spring 3.0 we are adding aopalliance.jar file. In latest Spring bundle this jar file not available. If we add below line applicationContext.xml we need to add the aopalliance.jar file other wise it will throws the java.lang.NoClassDefFoundError: org/aopalliance/intercept/MethodInterceptor

<tx:annotation-driven transaction-manager="hibernateTransactionManager"/>

Solution: Add the aopalliance.jar file to classpath or pom.xml file.

Click here to Download

Sunday, March 16, 2014

java.lang.NoClassDefFoundError: org/springframework/dao/DataAccessException

Problem: The problem is we are missing to add the Spring Transaction jar file to class path.

Solution: Add the spring-tx- x.x.RELEASE.jar to the class path. here x.x is spring current version you are using.

Thursday, January 9, 2014

Caused by: java.sql.SQLSyntaxErrorException: ORA-00918: column ambiguously defined

Caused by: java.sql.SQLSyntaxErrorException: ORA-00918: column ambiguously defined

Problem: The problem comes from while triggering a select query. In select query the multiple tables having the same column name but if we specified with out any prefix then it will throws the column ambiguously defined.

Example: Assume it two table Student and Employee. Both tables is having id, id.

Then while fetching the recored

Select id, * from Student s, Employee e;

Solution: Add prefix to the column

Select s.id, e.id, * from Student s, Employee e;

Note: Columns must be referenced as TABLE.COLUMN or TABLE_ALIAS.COLUM .

Saturday, July 20, 2013

org.apache.ibatis.exceptions.TooManyResultsException:

org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.exceptions.TooManyResultsException: Expected one result (or null) to be returned by selectOne(), but found: 2

Example is : while fetching by name, name founds in two times.

ID          NAME                           DESCRIPTION

1            Test                              Test Desc...
2            Test                              Test Desc1...