can JPA and memcached be used simultaneously in a web application? how? - java

i am developing a web application and for Object relation mapping i am using JPA.
My application frequently reads from DB.
to speed up the DB reads can i use memcached along with JPA? what's the machanism?
i am using JPA with eclipselink, eclipse and weblogic.

Only place JPA and memcached will relate through an API I can think, if you are using hibernate, is caching. If you are using Hibernate you may configure memcached as your 2nd level cache provider by using the hibernate-memcached project. Though I believe there are better alternative than memcached if you are just planing to use it as a hibernate 2nd level cache.
Memcached is an in memory caching system which you may use as a db it self.

Related

Can I use Spring Data JPA in a Java Application (not Spring project)?

I created a simple Java application and use Hibernate to deal with postgres database. I want to use Spring Data JPA with Hibernate in my project. Is there a way to do that?

Update all schemas with multitenancy architecture

I have a Java Web project with multitenancy using Hibernate, Spring and JPA. We recently implemented the architecture multitenancy but we don't know how update all the schemas of the database. Before that, when we didn't have this architecture we set in the persistence.xml the property hibernate.hbm2ddl.auto with update, but now it isn't possible because we have more than one schema. Do you have a solution?
Try using FlywayDB instead of hibernate.hbm2ddl.auto which shouldn't be used in production anyway. An incremental schema update can provide you a guarantee that the product environment can be safely updated, once you tested the incremented scripts on a QA server.

How does the Embedded Neo4j actually work?

I am new to neo4j and based on the reading I have done so far it seem there are two ways to interact with neo4j using Neo4j REST and Embedded. Where I am a little confused is does the Embedded option only give you the ability use the native Neo4j API to manipulate the datastore or can you also embed Neo4j and package it with your java application and if so how would I go about doing it?
As far as I know, Embedded term coined out to integrate neo4j with your application. In embedded mode, your db is locked and your application is solely authorized to access it. You can not access your db from any where else as far as your application is running and accessing it.
Where as in Neo4j Rest or Say Neo4j Server support REST API through which you can perform all the data store related operation via API call. In Rest API mode, you can handle your db externally using Neo4j GUI console along with your application.
Performance wise, I found embedded mode is much faster than Server mode.
does the Embedded option only give you the ability use the native Neo4j API to manipulate the datastore
You can use either of mode (Server REST API mode or embedded mode) to manipulate datastore.
Package with Java Application
it depends on your application configuration, in embedded mode you generally don't need external neo4j server running. You just need to explicitly mention your db path along with other configuration (I have used Spring data neo4j). Where as in Neo4j Server mode, you will require neo4j server running.
You can have look on this thread as well.

What is the JPA implementation in this guide?

I followed this NetBeans guide here on RESTful web services using JPA - http://netbeans.org/kb/docs/websvc/rest.html
I thought JPA was supposed to be a specification and you would use something like Hibernate as the actual implementation in your application. But this guide doesn't make any mention of an implementation at all. So where is the implementation coming from, is NetBeans providing its own JPA implementation?
That tutorial uses Glassfish as the Application Server. It provides the implementations for the JavaEE Apis, and in the case of JPA, it is EclipseLink. The idea is that your application does not ship with those libraries (JARs) and instead rely on the ones provided by the Application Server
Once you have it working, if you wish to learn about different JPA implementations, or different Application Servers, then you can try running the same application on JBoss, which has Hibernate as its JPA implementation.
Presumably it is the JPA provided by the container (probably Glassfish).

Use of Hibernate 3.0 with EJB 3.0 & JPA

Where I'm working the guys that are sitting across from me are working on a project. This is a JavaEE app which uses Struts, Spring, EJB 3.0, JPA, and Hibernate 3.0. They are using EJB 3.0 entity beans with annotations. I've been asking them why Hibernate 3.0 is in this mix and noone can seem to tell me. It feels like they've included Hibernate 3.0 because they were told to but are not using it for anything that they can't get from EJB 3.0 entity beans/JPA. They're using CMP and accessing all of the database functions via EJBs.
Can Hibernate give you anything in this setup that can't be provided by EJB 3.0/JPA?
Hibernate does have a JPA implementation but it can also be used standalone. It is possible to use Hibernate as the persistence provider in JavaEE. The JBoss application server for example uses Hibernate for its persistence. So if you are using Hibernate to provide the persistence in the app server, it may make sense.
If you are using an app server that does not use Hibernate for the persistence, then it sounds like you might not need it. Hibernate does have some extensions and things that are not available in JPA. Many other persistence providers also have these extensions (like Toplink or Eclipselink). Check with your app server provide to see if they have the extensions you might need or something similar to what you might have used in Hibernate.
JPA itself is just a specification, not a product, it cannot perform persistence or anything else by itself. JPA is just a set of interfaces and requires an implementation (a persistence provider). There are open source and commercial JPA implementations (Toplink Essentials, EclipseLink, Hibernate EntityManager, OpenJPA, Kodo, etc) and any Java EE 5 (or Java EE 6) application server must provide support for its use (JBoss uses Hibernate EntityManager, GlassFish v2 uses Toplink Essentials by default, GlassFish v3 uses EclipseLink by default, WebLogic uses Kodo by default, etc)1.
Now, one of the nice things with JPA is that it can be used outside a container, for example in a Java SE application or in a testing context (that was one of the big problems with EJB 2.x). But in that case, you need to provide an implementation as you won't get the one provided by the container. As we saw, Hibernate EntityManager - which is build on top of Hibernate Core - is one of them and this may explain why you see it.
1 Note that most (all?) containers offer a way to replace the default implementation that they provide. It is for example possible to use Hibernate instead of Kodo with Weblogic or instead of EclipseLink with GlassFish. This may be another reason why you see it in the mix.

Categories