Wednesday, 17 February 2016

How to resolve the error "java.lang.IllegalArgumentException: org.hibernate.hql.internal.ast.QuerySyntaxException: TravelEntity is not mapped" in hibernate

If you encounter any such error

java.lang.IllegalArgumentException: org.hibernate.hql.internal.ast.QuerySyntaxException: TravelEntity is not mapped [ from TravelEntity]
org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1374)
org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1310)
org.hibernate.ejb.AbstractEntityManagerImpl.createQuery(AbstractEntityManagerImpl.java:294)

Add an entry in persistence.xml of the particular entity class  as like below under the persistenceunit tag
<class>com.data.TravelEntity</class>

Ex:
<persistence-unit name="travelPU" transaction-type="JTA">
<class>com.data.TravelEntity</class>

Ho to resolve error such as "java.lang.IncompatibleClassChangeError: Implementing class" in while running pom through Eclipse IDE

If you see any such error as like below


java.lang.IncompatibleClassChangeError: Implementing class

Invocation of init method failed; nested exception is java.lang.IncompatibleClassChangeError: Implementing class


1) Try to do maven clean by right clicking on the pom.xml in the project.
2) Right click on all the projects that has dependencies choose  Maven--> Update Project... --> then select check box Force Update of Snapshots/Releases run maven install and do update
3) Then run maven install by right clicking on the pom.xml in the project.


Ho to resolve "org.springframework.web.util.NestedServletException: Request processing failed; nested exception is java.lang.IllegalArgumentException:..."

If you find any such error as like below

org.springframework.web.util.NestedServletException: Request processing failed; nested exception is java.lang.IllegalArgumentException: No converter found for return value of type: class com.xxx.xxx
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:981)
org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:860)
javax.servlet.http.HttpServlet.service(HttpServlet.java:734)
org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:845)


then please add the below lines of code in the project specific applicationcontext.xml, the primary reason may be class may not be loaded

<context:component-scan base-package="com.xxx.xxx" />
<mvc:annotation-driven />

How to resolve one of the Spring+Hibernate JTA Transaction error

If you are using jboss server for deployment and find the error as below in console

java.lang.NullPointerException org.hibernate.engine.transaction.internal.jta.JtaStatusHelper.getStatus(JtaStatusHelper.java:73).............................


then try to add the below property in persistence.xml

<property name="hibernate.transaction.jta.platform" value="org.hibernate.service.jta.platform.internal.JBossAppServerJtaPlatform" />

How to resolve error ClassNotFoundException in Hibernate


If you find the  error as follows then try to have a look at the persistence.xml to check whether it has any classes which is not present in the project.Remove the classnames from the persistence.xml

Caused by: javax.persistence.PersistenceException: [PersistenceUnit: xxxPU] class or package not found
at org.hibernate.ejb.Ejb3Configuration.addNamedAnnotatedClasses(Ejb3Configuration.java:1431)
at org.hibernate.ejb.Ejb3Configuration.addClassesToSessionFactory(Ejb3Configuration.java:1214)
at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:1058)
at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:703)
at org.hibernate.ejb.HibernatePersistence.createContainerEntityManagerFactory(HibernatePersistence.java:75)
at org.jboss.as.jpa.service.PersistenceUnitServiceImpl.createContainerEntityManagerFactory(PersistenceUnitServiceImpl.java:200)
at org.jboss.as.jpa.service.PersistenceUnitServiceImpl.access$600(PersistenceUnitServiceImpl.java:57)
at org.jboss.as.jpa.service.PersistenceUnitServiceImpl$1.run(PersistenceUnitServiceImpl.java:99)
... 4 more

Caused by: java.lang.ClassNotFoundException: xxxxx from [Module "org.hibernate:main" from local module loader @9e89d68 (finder: local module finder @3b192d32 (roots:

How to resolve Spring+Hibernate repository BeanCreationException related to persistence


If you see any such error as like below

Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'xxxxxViewRepository': Invocation of init method failed; nested exception is java.lang.NullPointerException

check whether you have the correct persistentunit declared as below, the value of the property persistentUnitName should match with persistent-unit name which is declared in persistence.xml

 <bean id="entityManagerFactoryBean" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
   <property name="dataSource" ref="dataSource"/>
<property name="persistenceXmlLocation" value="classpath:/META-INF/persistence.xml"/>  
   <property name="persistenceUnitName" value="xxxxxPU"/>
   <property name="jpaVendorAdapter" ref="jpaVendorAdapter"/>
 </bean>

Persistence.xml is the one below

<persistence-unit name="xxxxxPU">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.Oracle10gDialect" />
<property name="hibernate.show_sql" value="false" />
<property name="hibernate.format_sql" value="false" />
<property name="hibernate.generate_statistics" value="false" />
<property name="hibernate.use_sql_comments" value="false" /> -->
<property name="net.sf.ehcache.configurationResourceName" value="META-INF/ehcache.xml" />
<property name="hibernate.cache.use_query_cache" value="false" />
<property name="hibernate.cache.region.factory_class" value="org.hibernate.cache.ehcache.SingletonEhCacheRegionFactory" />
</properties>
</persistence-unit>

How to avoid property not found error while deploying the spring applicationcontext.xml

Modify as like below in the property-placeholder of the applicationcontext.xml
<context:property-placeholder
    ignore-resource-not-found="true"
    ignore-unresolvable="true"
    system-properties-mode="OVERRIDE"
    location="classpath:default.properties", file:///${app.configs}/app.properties"/>

Tuesday, 9 February 2016

How to resolve the issue " [com.arjuna.ats.jta] (Periodic Recovery) ARJUNA016027: Local XARecoveryModule.xaRecovery got XA exception XAException.XAER_RMERR: javax.transaction.xa.XAException" for oracle

The warning has occured due to insufficient permission in connecting Oracle database from Jboss server.
Database administrator can provide the required permission for the user and below are some useful links to ponder on.

1) https://access.redhat.com/solutions/22274
2)https://developer.jboss.org/wiki/ARJUNA016027LocalXARecoveryModulexaRecoveryGotXAExceptionXAExceptionXAERRMERR

How to resolve the issue "java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderListener" in Eclipse IDE

 1)  Right-click on the project's name in the project explorer and choose "Properties"
2)  Choose "Deployment Assembly" and click on the "Add..." button on the right margin.
3)  Choose "Java Build Path Entries" from the menu of Directive Type and click "Next".
4)  Choose "Maven Dependencies" from the Java Build Path Entries menu and click "Finish".
Now you should be able to see "Maven Dependencies" added to the Web Deployment Assembly definition.

Saturday, 6 February 2016

Useful & Basic GIT Commands

Download Gitbash and install
1)  Right click on the folder where you would like to checkout the branch and choose  gitbash , command prompt will appear.
2) Use the following command to setup the repository  path in your local
     git clone  <branch repo path.git>
3)  Use the following command to  checkout the branch to the local directory.
     git checkout < branch-name>
4) Use the following command to know the status like the branch name and the files that are to be added or modified in your local
git status
5) Use the following command to pull the latest contents from the remote repo
git pull
6) Use the following command to clean/reset all the files from the local repo
git reset --hard
7) To know the remote repository path
git remote -v

How to make datasource connection in JBOSS server

For data-source set-up on JBoss AS
1)  Make changes  in standalone.xml or standalone-full.xml  whichever you use
2)  Under <datasources> element add the below one
<xa-datasource jndi-name="java:jboss/datasources/appDS" pool-name="appDS" enabled="true" use-ccm="false">
                    <xa-datasource-property name="URL">
                        jdbc:oracle:thin:@//<ip address>:<port no>/<database environment>
                    </xa-datasource-property>
                    <driver>oracle</driver>
                    <xa-pool>
                        <is-same-rm-override>false</is-same-rm-override>
                        <interleaving>false</interleaving>
                        <pad-xid>false</pad-xid>
                        <wrap-xa-resource>false</wrap-xa-resource>
                    </xa-pool>
                    <security>
                        <user-name></user-name>
                        <password></password>
                    </security>
                    <validation>
                        <validate-on-match>false</validate-on-match>
                        <background-validation>false</background-validation>
                    </validation>
                    <statement>
                        <share-prepared-statements>false</share-prepared-statements>
                    </statement>
                </xa-datasource>

3) Provide the driver depending upon the database that you use say for Oracle add the below elements under <drivers> element ,

<driver name="oracle" module="com.oracle.db">
                        <xa-datasource-class>oracle.jdbc.xa.client.OracleXADataSource</xa-datasource-class>
                    </driver>

Note : Important is that driver refers module: com.oracle.db.So please create folders in such a way as follows for Oracle

<JBOSS_HOME>\modules\system\layers\base\com\oracle\db\main\

4) Usually for Oracle there will be three files required such as Module.xml,ojdbc6.jar &  ojdbc6.jar.index
5) Module.xml will have the following entries
<?xml version="1.0" encoding="UTF-8"?>

<module xmlns="urn:jboss:module:1.1" name="com.oracle.db">

    <resources>
        <resource-root path="ojdbc6.jar"/>
    </resources>
    <dependencies>
        <module name="javax.api"/>
        <module name="javax.transaction.api"/>
    </dependencies>
</module>

How to resolve connection timeout issue while building through maven

If you see any such error while downloading any of the jars as following
Failed to read artifact descriptor for org.springframework.security:spring-security-core:jar:4.2.4.RELEASE: Could not transfer artifact org.springframework.security:spring-security-core:pom:4.2.4.RELEASE from/to mirror  (https://<maven repo path>): connection timed out to .......

Try to check the whether you have the appropriate nexus repo path as like below in pom.xml

  <distributionManagement>
         <repository>
             <id>depl</id>
            <url>http://<nexus path></url>
         </repository>
        <snapshotRepository>
             <id>depl-snapshot</id>
             <url>http://<nexus snapshot path></url>
        </snapshotRepository>
</distributionManagement> 

How to resolve application war not being deployed properly in JBOSS server

If you see any such following info in the server console

INFO  [org.jboss.as.server.deployment.scanner] (DeploymentScanner-threads - 1) JBAS015003: Found xxx.war in deployment directory. To trigger deployment create a file called xxx.war.dodeploy

Try to create and place a file named xxx.war.dodeploy in deployments folder
say for EAP6.1 on standalone its C:\JBOSS\jboss-eap-6.4\standalone\deployments\

How to Convert Eclipse project to J2EE/Web project

1)  Right click on the Project.
2)  Click Properties
3)  Choose Project Facets
4)  Choose Dynamic web module check box(Choose the required version of it say 3.0/3.1)
5)  Choose Java and provide the required version which supports appropriate dynamic  web module version.

How to resolve Error "Dynamic Web Module 3.1 requires Java 1.7 or newer"

If you see the error while choosing Dynamic web module 3.1 from Project Facets(Right click on the Project and click on properties) then Choose Java (the required version of Java) and then click Apply.

How to add Maven Plugin in Eclipse Helios

Go to Help ==> Install New Software... ==>  Click on Add... button ==> Provide Name as Maven Tools & Location as http://download.eclipse.org/technology/m2e/releases/1.3

How to add Jboss Enterprise Server Tools in Eclipse Helios

Go to Help ==> Choose Install New Software... ==>  Click on Add... button ==> Provide Name as JBoss Tools & Location as  http://download.jboss.org/jbosstools/updates/stable/helios/