05 October 2011

Signing a jar file

As I had to sign the jar file (to provide it permissions), used the following command to sign the jar file.

jarsigner -keystore  PATHTO\srack.keys -storepass password PATHTOYOURJAR\audiorecording-1.0.jar https://www.skillrack.com/

Note: The srack.keys was generated earlier using a command like (as I was lazy specified 10 years validity :))
keytool -genkey -keystore srack.keys -alias https://www.skillrack.com/ -validity 3650


03 October 2011

GlassFish Error - javax.ejb.AccessLocalException: Client not authorized for this invocation

If you are using GlassFish (along with NetBeans and facing this error when invoking an EJB from a Servlet or any  web layer class using @EJB inject, clear the generated policy files and redeploy the application.

Ensure a line for the (newly added or renamed) method being accessed is present in the policy file. An example is provided below.

permission javax.security.jacc.EJBMethodPermission "ExamManagementEJB", "getQuestionTags,Local,com.packagename.entity.SomeEntity";

Configuring Hibernate as JPA implementation provider in GlassFish

This post helps to configure Hibernate as JPA implementation provider replacing the bundled EclipseLink.

I am using Maven and mine is an EAR containing a WAR and an EJB module. Hence in the pom.xml of the EAR module, the following dependency is mentioned.

        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-entitymanager</artifactId>
            <version>3.6.7.Final</version>
         </dependency>

 
As this jar has to go into the lib folder directly under EAR ROOT, specify the value for defaultLibBundleDir (in pom.xml)

               <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-ear-plugin</artifactId>
                <version>2.4.2</version>
                <configuration>
                    <version>6</version>
                    <defaultLibBundleDir>lib</defaultLibBundleDir>


Finally your persistence unit in persistence.xml

 <persistence-unit name="yourPU" transaction-type="JTA">
        <provider>org.hibernate.ejb.HibernatePersistence</provider>
        <jta-data-source>jdbc/yourDataSourceName</jta-data-source>
        <properties>
            <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect" />
            <property name="hibernate.transaction.manager_lookup_class" value="org.hibernate.transaction.SunONETransactionManagerLookup" />
        </properties>
    </persistence-unit>