Error / Exception 1 ::
While configuring for my first sample JPA application , I faced many weird errors and exceptions but that was all due to my inexperience on this side, I have few documented below which could help other developers
a) Internal Exception: java.sql.SQLException: Io exception: NL Exception was generated
Possible Cause:: Check your jdbc url in the Persistence.xml file under Meta-Inf configuration
I had :: jdbc:oracle:thin://host:1521/dbname3t;create=true for my JPA configuration
It should have been :: jdbc:oracle:thin:@host:1521:dbname3t
b) persistence, oracle thin, ORA-12505, TNS listener does not currently know of SID
I was getting org.eclipse.persistence.exceptions.DatabaseException ORA-12505, TNS:listener does not currently know of SID given in connect descriptor
While trying to fix it I found the URL configured in the persistance.xml was incorrect
I had :: jdbc:oracle:thin://host:1521/dbname3t;create=true for my JPA configuration
It should have been :: jdbc:oracle:thin:@host:1521:dbname3t
c) javax.persistence.PersistenceException: No Persistence provider for EntityManager named "TestJPAEntity"
In JPA a database connection is represented by the EntityManager interface. In order to access and work with an ObjectDB database we need an EntityManager instance. If there is any problem in locating the Entitymanager defined in your client/service class then this error will be thrown
You can update the persistence.xml or your testClient/Service java class to have same name
refer below sample code for persistence Unit Name and name in your java class.
Sample Persistence XML ::
persistence.xml
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
<persistence-unit name="JPATestPaymentCreation">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<class>payments.Payment</class>
<properties>
<property name="javax.persistence.jdbc.driver"
value="oracle.jdbc.driver.OracleDriver" />
<property name="javax.persistence.jdbc.url"
value="jdbc:oracle:thin:@dbhost03:1521:dbName3t" />
<property name="javax.persistence.jdbc.user" value="online_service" />
<property name="javax.persistence.jdbc.password" value="EW66P#$A" />
</properties>
</persistence-unit>
</persistence>
TestJPAJava Class
public class TestInsertPaymentViaJPA {
private static final String PERSISTENCE_UNIT_NAME = "JPATestPaymentCreation";
private static EntityManagerFactory factory;
public static void main(String[] args) {
factory = Persistence.createEntityManagerFactory(PERSISTENCE_UNIT_NAME);
EntityManager em = factory.createEntityManager();
// Read the existing entries and write to console
Query q = em.createQuery("SELECT emp FROM Employee emp");
List<Employee> empList = q.getResultList();
for (Employee emp : empList) {
System.out.println(emp.getEmpNameId());
}
System.out.println("Size: " + empList.size());
em.close();
}
}
c) java.lang.ClassCastException: org.eclipse.persistence.jpa.PersistenceProvider cannot be cast to javax.persistence.spi.PersistenceProvider
If you are using Eclipselink as your persistence provider , then you could have faced this error , this is a run time error and could be due to following causes:
i) The version of the Eclipselink and javax.persistence.xx jars are not compatible
ii) If you are running your application on Tomcat and the jars in Tomcat/lib directory are of different
version then the ones you have packaged in your web application.
iii) Another possible cause could be any other jar in your workspace or packaged WAR is causing conflict
I was having issues with below combinations ::
persistence-api-1.0.2.jar and eclipselink.jar (1.0)
persistence-api-1.0 and eclipselink(1.0)
I was able to make it work with :: javax.persistence-2.1.0 and eclipselink (eclipselink-2.1.0.v20100614-r7608)
d) While Configuring Maven in the local workspace , most of the developers get below issue initially
Eclipse complains “Could not resolve archetype”
Could not resolve archetype org.apache.maven.archetypes:maven-archetype-webapp:RELEASE from any of the configured repositories.
While analyzing this issue and going through multiple posts online I figured this is related to proxy settings in the settings conf file under 9C:\Users\anyUserProfile\.m2\settings.xml), even though I had included the proxy settings with correct User/Password to get the Maven schema validated the format was incorrect , see below
For my network settings below proxy config did nt work ::
<proxies>
<!-- proxy Specification for one proxy, to be used in connecting to the network.-->
<proxy>
<active>true</active>
<protocol>http</protocol>
<username>anyUser</username>
<password>passxxx</password>
<host>host.name.com/</host>
<port>80</port>
</proxy>
</proxies>
So instead of above settings I replaced with below ::
<proxy>
<id>optional</id>
<active>true</active>
<protocol>http</protocol>
<username />
<password />
<host>proxy.test.com</host>
<port>8080</port>
<nonProxyHosts>localhost,127.0.0.1</nonProxyHosts>
</proxy>
And this resolved my issue of Maven Project not getting created.
d) Missing [SEI] when generating artifacts with WSGEN
I faced this error while generating the artifacts for my Service implementation, which
needed to be exposed as a WebService.
I tried following command on command prompt to generate my classes :
wsgen -verbose -cp . com.test.ws.EchoService -wsdl
This throws me below error : WSGEN [options] <SEI>
and the reason being the utility not able to reach out or find the SEI Service Implementation class for which we might want to write a client.
What is happening here is the option " -cp " will set the classpath and try to retrieve or resolve the EchoService class location according your classpath so in my case it was build/classes hence this makes it looks as ::
build/classes/com/test/ws/EchoService but the actual path is :: C:\Users\EchoWebServiceExample\build\classes and then the package so it should be
wsgen -cp C:\Users\EchoWebServiceExample\build\classes com.test.ws.EchoService -wsdl
e) Issue with new configuration on Eclipse to execute POM.xml to resolve all config metadata and execute the maven commands.
Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.3.2:compile
Issue Faced: Error " WARNING: Error injecting: org.apache.maven.plugin.CompilerMojo
**java.lang.NoClassDefFoundError: org/codehaus/plexus/compiler/CompilerException**
Actually my JAVA_HOME was pointing to JRE_HOME , I found out when I executed this with below command
mvn clean install -X
Java version: 1.7.0_79, vendor: Oracle Corporation
Java home: C:\Program Files\Java\jre7
To fix this in eclipse I updated my CLASSPATH Variables under Eclipse -> Preferences -> Java -> Build Path - CLASSPATh VARIABLES to have a new entry as JAVA_HOME and pointed it to my JDK home it worked perfectly fine
f) Issue in building Web Application in Eclipse via inbuilt Maven plugin
JDK's tools.jar was not found in C:\Program Files\Java\lib\tools.jar. Usually this means you are running JRE, not JDK
Go toPreferences/Java/Installed JREs
and add one more location as"C:\Program Files\Java\jdk1.7.0_7
or something like below you can update existing JRE location to point to JRE under your JDK as I removed the one forC:\Program Files\Java\jre7 and added C:\Program Files\Java\jdk1.7.0_79\jre
As you can see, the pathC:\Program Files\Java\jre7\..\lib\tools.jar
only makes sense if the first part (til the /..) is replaced byC:\Program Files\Java\jdk1.7.0_79\jre
.
No comments:
Post a Comment