How to configure Eclipselink nosql JPA implementation with mongodb nosql database? - mongodb

I want to use JPA to create an entity class that can be used with the persistence context to access my db2 nosql database. The problem is the #NoSql annotation is not being found.
As per http://wiki.eclipse.org/EclipseLink/UserGuide/JPA/Advanced_JPA_Development/NoSQL/Configuring, I:
Created a web project
Enabled JPA via project properties-> Project Facets -> Check mark JPA v2.1
Under Project properties -> JPA -> Set Platform to EclipseLink 2.5x, Set JPA Implementation to Library Provided by Target Runtime
Setup server.xml with the datasource and the persistence.xml
I have java.persistence.org but not java.persistence.org.oracle.nosql. I'm not sure if I am suppose to download it or it should already be setup. And I also do not know how to use maven (and I would prefer not to).
Most tutorials online either only show HOW to use (and not configure) or use mysql connector and somewhere in the project config it just works. I greatly appreciate assistance!

I solved the problem by following this blog post: https://blogs.oracle.com/NoSQL/entry/eclipselink_jpa_and_oracle_nosql.
Excerpt:
Now at first glance it looks like EclipseLink 2.5 includes support for
NoSQL databases right out of the box, but in fact if you look closely
there is another specific NoSQL plugin download necessary. Download,
unzip and save this plugin in a directory e.g. /nosql-plugin . Later
you’ll need to get some libraries from it.
So go here to get the jar files and import the following into your project
org.eclipse.persistence.nosql_2.5.0*.jar
org.eclipse.persistence.oracle.nosql_2.5.0*.jar
javax.resource_1.5.0*.jar
To import go right-click project -> properties -> java build path -> Libraries tab -> Add External Jar -> Navigate to the jar files and import

Related

Importing JAVA bean into Drools Workbench

I start using KIE Drools Workbench and I practice in creating DRL files so I can tutor pepole that are not programmers in creating rules.
I know how to create a JAVA class within the Workbench but I need to know how to import a class I already wrote that will be part of the statement.
For example:
Employer - class I create within the Workbench
Employee - class I developed in eclipse and wish to import into the Workbench
So the drl could look like this:
when
$employer:Employer(isHappy == true)
then
Employee emp = new Employee();
emp.setSalary(100);
insert(emp);
end
Any idea how can I import JAVA bean to use in KIE Drools Workbench?
Thanks!
Create a jar with the beans you want to use (use maven for convenience).
Upload jar into workbench through Artifact Repository.
Include dependency using project editor AND include all packages of the jar to the Package white list.
Add the classes you need at the Data Objects menu of the rules to use them.
What Stathis stated gives you one option to do this. Alternatively you can
maven install your beans project (this will extract a jar in .m2 repository to use as a dependency)
add a dependency with the jar extracted in .m2 in your project's pom
As for the tutoring part you should examine the possibility of using dsl (Domain Specific Language) for your rules. This and this (chapter 5.10) might be handy to you

Is possible to make a library jpa based?

I'm looking to create some projects with common classes for every other project I create, web or standard.
In eclipse I'd already created two projects with the maven quickstart archetype without the jpa facet, but with the eclipselink libraries in the maven POM to anotate entities and jpa stuff. One project is for generic JPA access and another project for security (user entities, user services, user repository) that uses the JPA access project.
Then I create a 3rd project with the same archetype from last 2 project for testing the previous 2, but this have the JPA facet and the Persistence.xml. When I try to do something JPA related, it says the metamodel is empty. Then I found on the internet and the documentation says I have to use the tag in my persistence.xml, but I dont know how since Im including the previous two project in the build path of eclipse, not exactly any jar file. How can I achieve this?
Excuse my english translation.
You probably need an Composite Peristence Unit. Also, it will probably require some care in your built/deployment scripts.

Running servlet within Eclipse requires libs to be defined 3 times - am I doing something wrong?

Hullo - issue is this:
I wrote a servlet in Eclipse which requires mysql-connector-java-5.1.22-bin.jar
To compile I need to add the jar via the project's "Java Build Path"
To deploy I need to add the jar to the project's "Deployment Assembly"
To run the servlet within eclipse I need to add the jar to the servlet's Run Configuration -> Classpath
It's not the end of the world re-re-repeating myself like this, but it does seem odd.
Given that Eclipse gets a lot of other stuff correct I'm guessing / hoping that maybe I'm overlooking some feature to avoid this silliness (I cannot imagine a scenario where you'd benefit from entering this in 3 different spots ... but maybe I'm being uncreative here ...).
Insights appreciated :-)
The only thing you need to do is to drop the jar in WebContent/WEB-INF/lib.
You are developing a Java Web project, so the traditional place to put the required libs (JAR files etc) is under /WEB-INF/lib. And you do it only once.
In Eclipse, when you create Dynamic Web Project the appropriate project structure is generated for you (this is a development structure). In this case you place your JAR files in ProjectName/WebContent/WEB-INF/lib folder. And this folder is *automatically included in the project's build path.
Considering the fact that it is a Java Web project (you said you use servlets) you have to deploy your web app to some Application Server, like GlassFish, JBoss, WebLogic, WebSphere etc, or more simple Web Container like Apache Tomcat. If you do this thru Eclipse, then again your web project is automatically deployed.
NB!
There may be some additional details related to using libraries.
For instance, when it comes to using database drivers (MySql, PostgreSQL, Oracle etc) Tomcat advises the following while configuring JNDI Datasource (quote):
Before you proceed, don't forget to copy the JDBC Driver's jar into
$CATALINA_HOME/lib
In your case (MySQL) see the example here: MySQL DBCP Example
Also see my answer related to Webapp configuration file organization convention.
Hope this will help you.
P.S. Here is a step-by-step example: How do I access MySQL from a web application?

Hibernate Setup in eclipse helios

How I can setup Hibernate for a Dynamic Web application by using Eclipse Helios? I am a newbe so please let me know if there is any example.
I tried for Java application and included all JARS and it worked fine. But don't understand how I can do it for Web application and test it.
I will use Struts2 so I will appreciate if I can get appropriate example or guidance.
Drop the jars in WEB-INF/lib. Those jars are automatically added by Eclipse to the project build path, and constitute (with the WEB-INF/classes directory and the container classpath) the classpath of the webapp.
http://hardik4u.wordpress.com/2008/09/02/struts-2-hibernate-3-integrationcomplete-using-eclipse/
https://stackoverflow.com/questions/4364923/struts2-and-hibernate-framework-create-in-eclipse
First, download Struts2, and import example WAR file into Eclipse. You can find it from the source folder: struts-2.3.1-all\struts-2.3.1\apps\struts2-blank.war
Second, you should install Eclipse Hibernate Plugin. Goto Window > Preferences > Install/Update > Available Software Sites and add following link and name it JBossTools or something.
http://download.jboss.org/jbosstools/updates/helios/
Depending on your needs you can install Hibernate Plugins for many project types. In this case, select web application plugin.
And after, you should include Hibernate Core libraries into your classpath. I would recomment Hibernate 3.6 and greater. Because it does not depend on asm (asm-3.3.jar, asm-commons-3.3.jar ...) anymore. If you use earlier versions you might encounter some problems, since Struts2 also depend on asm libraries.
Then create your database, and use following link to configure and generate model bean classes.
http://casteyo.wordpress.com/2007/06/06/conf_hibernate/
Now you don't need to write mapping files by yourselves. And with DAO factory pattern you have your way to finish your project.
Hope this helps, and Goodluck

Spring Explorer not showing beans from bean definition file

I just downloaded the Springsource Tool Suite, and I created a simple bean configuration file called myDefinition.xml and placed it in the root directory of the Spring Project. However, the Spring Explorer is not showing any data. I'm using eclipse 3.5 and the latest SpringSource all-in-one installation.
Also, if I specify invalid property names in the configuration file, I get no error. Autocomplete, however, is working.
Thoughts?
In the Spring Explorer tab in Eclipse, right click on your project > properties. Then go to Spring > Beans Support and select the Config Files tab. You can then select files or scan a directory and that should add them. I haven't found a way to autoscan a directory so I don't have to do this whenever I add a new spring bean file. The beans that appear in that list are stored in the .springbeans file.
Just want to add that if you want to generate a diagram of a webflow of an existing project, you have to right-click said project in Eclipses Project Explorer and "Add Spring Project Nature" by using the Spring Tools entry of the context menu.
There currently (as of 2012-04-10) seem to be problems with the Spring Explorer view when using a purely annotation driven bean definition (i.e. using Java annotations to wire everything up instead of using XML files).
There is a workaround though, by providing a minimum XML file that declares scanning for components.
http://forum.springsource.org/showthread.php?118928-Spring-Explorer-with-Java-based-Web-Container-configuration
Unfortunately, this procedure is still flawed, missing some components.
Just to add Claudio030
Make sure you have JEE perspective selected for your project, otherwise it won't show in Java perspective.