Unable to find interface javax.transaction.UserTransaction; - jpa

I am trying to setup a new Netbeans project with JPA. The Java SDK version is 1.5.0_22-b03 and J2EE version is J2EE 1.4.I am using TOPLINK Essentials for JPA.
Going by javadoc javax.transaction.UserTransaction interface comes with J2EE 1.4.
Then why it's not able to find javax.transaction.UserTransaction?

The JPA 1.0 specification is meant to cater to Java EE 5 containers and not J2EE 1.4 containers (unless the same also support EJB 3.0 like the erstwhile OC4J containers from Oracle). Likewise JPA 2.0 caters to Java EE 6 containers.
I would suggest using Netbeans with Java EE 5 or Java EE 6, instead of heading for a wild goose chase on getting your JPA 1.0/2.0 provider to work amicably with a J2EE 1.4 container. This isn't merely about placing some JARs in your compile time classpath; your runtime classpath will require classes that are available only in a Java EE 5/6 container.

Either you have an incorrect classpath or you are missing a required jar. What are you using to build?

You have not correctly included the j2ee-1.4.jar in your project classpath. Otherwise you can reference to it. Perhaps you meet problem in setting classpath of your java project in netbeans.
Please check your jar to ensure it is correctly downloaded.

Maybe this is an old question but since no other answer has been posted, I post what I was able to do to make it work.
I found a file at:
C:\Program Files (x86)\NetBeans 8.1\java\modules\ext\hibernate4
Right-click your project >Libraries >Add jar > find your Netbeans installation directory...
usually => C:\Program Files (x86)\NetBeansXXX
find java\modules\ext\hibernate4 and choose jboss-transaction-apixxxxx.jar
hope it helps everyone else,

Related

Netbeans wizard for JSF pages doesn't recognize TomEE 1.6 to have Web Profile support

I am creating a Java EE 6 application with the help of Netbeans 8.0 and TomEE 1.6. I have successfully added the server to netbeans and even generated some entity classes. I am currenlty trying to generate some JSF pages using the Netbeans wizard. However I get the following message
Cannot be generated for Java EE 6 sources wihtout server with complete Java EE 6 Web profile support (at least EJB Lite support).
I am using TomEE 1.6.0.2 plus
The problem is Netbeans 8 has a bug in which it fails to find the tomee-common-[version].jar in the [TomEE]/lib directory.
The solution is to simply rename the jar file to an older version.
For example, you have [TomEE]/lib/tomee-common-1.6.0.2.jar or [TomEE]/lib/tomee-common-1.7.1.jar. Rename these files to [TomEE]/lib/tomee-common-1.6.0.jar
This should sort you out :)
you can use tomcatEE 1.7.2 with a few small changes
you find here:
http://zarnisfd.blogspot.com/
I think this also applies to TomEE 1.6
According to the following sites:
http://forums.netbeans.org/ntopic48005.html
https://netbeans.org/bugzilla/show_bug.cgi?id=210835
Tomcat does not support EJB's therefor you would need to use an enterprise server that at least supports EJB Lite. One such server would be GlassFish

Is there any way to have a fully portable Java EE 6 deployment?

Is it possible to make a Java EE 6 application deployable on any Java EE 6 Container (like JBoss or GlassFish, etc) without using their modules / libraries?
If for example I want Hibernate or Weld then add these in my Maven pom.
In other words, is there any "vanilla" container or can JBoss or GlassFish be made "vanilla"?
I´m sorry... but to be honest I don´t understand your question.
Java EE applications are in most cases deployable an all containers - as long as they are not using packages or configurations which are specific to the chosen container.
Even if you add libraries in your POM and the applications are packaged as WAR or EAR this should work.
Weld is not needed because the API is part of Java EE 6. If you want to use JPA you also don´t need hibernate.

Adding Java EE sources to an Eclipse project

Using Eclipse, I have configured one Java EE project to include in its class path the JBoss 7.1 Runtime.
(I did this with the "Add Library" button in "Project properties" -> "Java build path" -> "Libraries").
I use Maven to build the project and "normally" this works fine.
However, when I debug this application the Java EE source classes are not available. Just in case I took a look in the JBoss runtime but apparently the sources are not there. My main question is: Could someone please tell me what is the best way to add the Java EE sources to my Eclipse project so they will be available when debugging?
Also, if I am working with Maven is fine to add the Java EE libraries as the JBoss Runtime, as I am currently doing in my project? or it is considered a better approach to declare the dependency on Java EE in the project POM instead?
I started to wonder if the JBoss runtime approach was the "correct" way to add the Java EE binary classes, since strangely enough Maven from time to time fails compiling the application since it cannot see anymore the Java EE classes. I solve this deleting the JBoss Runtime from the build path (in the Eclipse project configuration) and adding them again. Fortunately, this compilation does not happen often, so I have been able to work doing this workaround until now.
Thanks for any feedback.

About Java EE classpath

I am developing an online conference system based on Java EE framework using NetBeans for my school. My project contains the Java EE library which has javax.mail package.
I use the javax.mail.authenticator class in my code and everything seems to be OK. However, when I run the project and try to send email with this system, problem occurs, saying it can not find class javax.mail.authenticator.
Then I put the files mail.jar and authenticator.jar in folder WEB-INF/lib, after that it can send email correctly. I don't know why it can not find the class authenticator and why this two jar files should be put there?
PS: I use Tomcat 6 as my web server.
There is a difference between having a class on the Java build path, and on the classpath. By putting mail.jar and authenticator.jar into WEB-INF/lib, you have put them into Tomcat's classpath so that Tomcat can "see" those classes at runtime.
Recommended reading: What is the difference between Class Path and Build Path
P.S. I think you mean Java EE. It hasn't been called J2EE for ~5 years now.
When you deploy an application to a Java EE container, like Tomcat, there are certain places classes and jars are loaded to form an application's classpath. For web applications (a war), classes are loaded from WEB-INF/classes and from jars in the WEB-INF/lib.

How to make a java project from a Websphere ear work with JPA

I have an EAR installed in Websphere 6.1. Development is done in Eclipse, but using a simple Java project and updating the *.java and *.class files directly to the server. I want to start using JPA, but the #Stateless annotation gives the error "cannot be resolved to a type". What am I missing?
Thank you for your time,
Iulia
You need either to be on WebSphere 7.0, or to have installed the EJB3 Feature pack for WebSphere 6.1. You pattern of use of EAR files and plain java projects sounds a little diferent from what I've done. Suggest you start by following Roland Barcia's tutorial, et that going before you experiment with other patterns.
This tutorial may be helpful, it relates to WebSphere 6.1 + feature pack.