Java EE How do you use an EntityManager with Mongo? - mongodb

I"m trying to create a Java EE project using a mongo database. I am unable to find any good working examples.How do you correctly set up JPA for the project?

Java EE 6 (or in JPA 2.0 as an part of it) does not have any defined support for MongoDB or for NoSQL databases in general.
That's why how it is done depends fully from JPA provider implementation. If you use EclipseLink, maybe you can try to follow example given in this blog post and present further questions about what exactly is not working.

Hey you should at least check out Arun Gupta's blog post on this at https://blogs.oracle.com/arungupta/entry/java_ee_6_and_nosql. Gupta is the Oracle Java EE Evangelist and this entry covers using EclipseLink for a JPA connection to MongoDB and deploying to Glassfish. If you search his blog, there is also an earlier entry on how to use the Java driver included with MongoDB in a Java EE project. I haven't tried the example with an EntityManager but am thinking about doing so.

Related

MySQL to ObjectDB Migration

A maven JEE project using JSF, JPA (EclipseLink 2.3) is using MySQL comminity edition as the database. With the size of the database exceeding 20GB, there are database related peformance issues. As a solution, I am going to use ObjectDB.
I am doing to use two persistence units for each database and migrate objects. Will it work? If not, is there any other recommendation? I tired the web to search, but could not find any totorial explaining how to do it ?

How to use OpenJpa using persistence.xml without using Enhance.xml ..?

How can I use OpenJpa ,with using Persistence.xml configuration same we use in jpa, I dont want to use Enhance.xml.
If you rely on some non-IDE tool to build your app, you can enhance automatically during buildtime. For Maven, for example, see this
If you are running in a JavaEE container you will get enhancement for free. The other option when running in a JSE environment is to configure the -javaagent.
Take a look at the section titled 'Explicit javaagent support'. As for JavaEE stuff, I'd suggest getting ahold of the Pro JPA 2 book. It is very good at describing usage of JPA in an EE environment.

How do I add Hibernate to an existing Eclipse project? Is Hibernate the same as JPA?

I have searched. I can't find the exact way that matches what I have. I installed Eclipse for Java EE. I then went to help and install new software. Put in the jboss url, downloaded the Hibernate libraries. Everything went fine. I also installed the JDBC driver for MySQL. I tested it. It works. Downloaded and installed slf4j because I read someone that said to (hey, I'm learning).
I started a new Java EE project, and uh, I'm kind of stuck after that. It's a "Hello World" at the moment.
I can't find out what to do. I've seen tutorials where it says create a Hibernate project, but what if I want to add it later after I start a "normal" project? I don't want to manually look for the Hibernate.jar in the download folder. I installed it and want to know how to get to it.
I also saw lots of things that said JPA and Hibernate. Are they the same thing?
EDIT: I was able to find Hibernate by right clicking on the project, new, scroll down to hibernate. I am still interested in JPA and Hibernate.
JPA stands for "Java Persistence API", and it is a specification. It basically defines the APIs and behaviors of a persistence layer, and there are different implementations of the JPA specification. Hibernate is one of these implementations. There are a few others, e.g.:
http://www.oracle.com/technetwork/middleware/toplink/overview/index.html
http://openjpa.apache.org/
The JPA specification can be found here:
http://jcp.org/aboutJava/communityprocess/final/jsr317/index.html

Migrate from EJB 2 Entity Bean to EJB3

I am having some entity beans created in EJB 2.0 and now I need to migrate to EJB 3.x, but I've studied that use of entity beans are changed in EJB 3.x and they are using JPA instead.
Where can I find solution to actuate my beans to be comfortable with EJB 3.x?
For example from following resources available online:
http://www.datadisk.co.uk/html_docs/ejb/ejb3_migration.htm
http://www.oracle.com/technetwork/middleware/ias/oc4j-twp-ejb3-migration-1013-133021.pdf
or following printed books:
Pro JPA 2 Mastering the Java Persistence API (p. 457-466)
EJB3 in Action (p. 513-528)
IntelliJ EJB refactoring tools might prove to be useful: http://www.jetbrains.com/idea/webhelp/migrating-to-ejb-3-0.html
I belive there are some for Eclipse too.
just for future reference, I recommend the following link:
http://what-when-how.com/enterprise-javabeans-3/migrating-cmp-2-entity-beans-to-the-ejb-3-jpa-part-1/
And there's also part 2 on the same site as well as migrating session beans and MDBs.
I used them and found them very helpful and useful.

Starting a project in Java EE

I am thinking of using Java EE for my college project. Previously, I have used C# for a desktop application. I am new to Java and Java EE.
My question is this. What do I have to consider before starting a project in Java EE? I am thinking about using NetBeans as my IDE. Is this a good idea? I can choose either MS Sql Server or Oracle as my back end.
What do I have to consider before starting a project in Java EE?
This question is very broad and I don't know if this is exactly the expected answer but my suggestion would be to go for Java EE 6 (more precisely, for the Java EE 6 Web Profile which is a subset of the entire specification but should be more than enough in your case) and to use the following APIs:
JSF 2.0 for the presentation layer.
EJB 3.1 Lite for the services layer.
JPA 2.0 for the persistence of your domain objects.
For the runtime environment (the server to run the code), I suggest using GlassFish 3.0.1 Web Profile.
I am thinking about using NetBeans as my IDE. Is this a good idea?
That would be my recommendation. NetBeans is a very decent IDE, is beginner friendly IDE (but still powerful), it provides very good support for Java EE 6, very good integration with GlassFish, and has are plenty of tutorials and documentation available to get started:
Getting Started with Java EE 6 Applications
Java EE & Java Web Learning Trail
I can choose either MS Sql Server or Oracle as my back end.
Java uses an unified low level API called JDBC (JPA being a higher level API built on top of it) to interact with a database so choosing one or the other doesn't really matter from a Java point of view and it won't make any difference for a college project so pick the one you want to work with (if you already used SQL Server for your C# project, you might want to get some experience with Oracle).
Related questions
What to learn for making Java web applications in Java EE 6?