Wednesday, 17 February 2016

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>