JPA, EntityManager and RMI
Hello,
in my client server application, I want to get a DAO from the server to add or update a business object.
My problem is that the DAO must have a property with the EntityManager so he can do his job, this EntityManager
is not serializable, so RMI throw a NotSerializableException, but when I set the property tansient, the EntityManager
will be null after serialize the DAO to the client.
How can I solve that problem?
Thanks.
teramor1 wrote:
Thank you! I undestand, the domain objects are not attached and therefor not JPA managed, when some changes are made to the objects.
When I take a Service Interface and take the implementation from the Rmi Server, so I can call update(...) the ServiceImplementation must have a property to a DAO and the DAO to an EntityManager, but the EntityManager is not serializable.
How can I detach the ServicImplementation from the DAO and/or the EntityManager so the Client gets the ServiceImplementation and can call the update(...) method and this method can do his job on the dao and the dao can do his job on the EntityManager?Assuming i understand your usage of the word "Service" (and i'm not sure i do), the client will never get an instance of the Service implementation. the Service implementation never leaves the server. a client gets a handle to the Service interface through some sort of jndi lookup. it then invokes remote methods on this Service which may return entity objects. then only things that travel between the client and server are the entity objects themselves.
Similar Messages
-
JPA EntityManager shared across OSGi modules
Hi,
I'd like to create an OSGi module which would act as a 'JPA master' making JPA EntityManager available to other OSGi modules. The persistence.xml would be part of this module but it would do nothing more.
I'd like to then access EntityManager from other OSGi bundles, both JARs and WARs (JAR Bundles and WAR Bundles).
I'm running on GlassFish 3.1.2.2 and using EclipseLink as the JPA provider.
Any idea for best practices?
Thank youHi, thanks for the link.
It says 'Refer to the examples to see it being used.' without a link so I read the section above that (8. JPA in OSGi Application)
It says about some config entries in GlassFish, I enabled it but still no luck.
Here's my /src/main/resources/META-INF/persistence.xml
<?xml version="1.0" encoding="UTF-8"?>
<persistence 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_1_0.xsd" version="1.0">
<persistence-unit name="cmsdbconnection">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<exclude-unlisted-classes>false</exclude-unlisted-classes>
<properties>
<property name="javax.persistence.jdbc.url" value="jdbc:mysql://172.16.145.139:3306/test_db"/>
<property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver"/>
<property name="javax.persistence.jdbc.user" value="db_user"/>
<property name="javax.persistence.jdbc.password" value="db_user"/>
<property name="eclipselink.ddl-generation.table-creation-suffix" value="engine=InnoDB" />
<property name="eclipselink.ddl-generation" value="create-tables" />
<property name="eclipselink.target-server" value="=SunAS9" />
</properties>
</persistence-unit>
</persistence>
Maven pom.xml to generate MANIFEST.MF:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
<extensions>true</extensions>
<configuration>
<archive>
<manifestEntries>
<Bundle-ManifestVersion>2</Bundle-ManifestVersion>
<Bundle-SymbolicName>com.ifp.vault.service.persistence</Bundle-SymbolicName>
<Bundle-Version>${project.version}</Bundle-Version>
<Import-Package>org.osgi.framework,org.osgi.util.tracker,javax.persistence;jpa="2.0";version="1.1.0",org.eclipse.persistence.jpa</Import-Package>
<JPA-PersistenceUnits>cmsdbconnection</JPA-PersistenceUnits>
<Meta-Persistence>META-INF/persistence.xml</Meta-Persistence>
</manifestEntries>
</archive>
</configuration>
</plugin>
Deploying in GlassFish succeeds, but I cannot obtain the EntityManagerFactory from other OSGi bundles.
Should that be registered as an OSGi service anyway? Because I can't see that when listing all OSGi bundles. -
Difference Between JMS and RMI
Difference Between JMS and RMI in J2EE Technologies
STFW
JMS - http://www.google.co.za/search?hl=en&q=what+is+jms&meta=
RMI - http://www.google.co.za/search?hl=en&q=what+is+rmi&meta= -
Hello,
Can anyone please tell me in detail the difference between RPC and RMI? If possible can you pls give examples?
Thanks in advance.
KiranJyotThank you for the reply.
Yes, I did google about this. But, it was not clear to me. I did ATM application using both RPC and RMI. Even though, it worked fine and did not lose points in my assignments, unfortunately the concepts were not clear.
Can you please explain me what does it meant by - there is objects involved in RMI. In RPC, invoking functions is done through a proxy function. It will be great if you can explain it using ATM application.
Regards,
KiranJyothi -
I have a project that I am porting from WL5.1 to WL6. It was working fine
in WL5.1
but cannot get it working in WL6. So, I went back to the HelloWorld
example to
see if I could get it working. The problem I am having is basically getting
applet to
talk to a server via RMI. The applet works fine alone and RMI works fine
alone.
I can't get the applet to talk to the server via RMI.
I am trying to get the "HelloWorld" applet example in WL6 working with RMI.
I previously had the same app working in WL5.1 with SP9 but cannot get it
working in WL6.
I am running WebLogic Server 6.0 with SP2.
I have registered a startup class in the WebLogic console
named "HelloServer". When starting up the server, it states
that the HelloImpl class has been registered as "HelloServer".
When starting up the client applet I get the following error:
java.rmi.MarshalException: Error marshaling transport header; nested
exception is:
java.io.EOFException
These are two different methods of looking up the same object.
The exception occurs at the "lookup" method call in both cases.
"myserver" is the name of my machine that WL is running on.
7001 is the port that WL is using.
Registry reg = LocateRegistry.getRegistry("myserver", 7001);
obj = (Hello)reg.lookup("HelloServer");
or...
obj = (Hello)weblogic.rmi.Naming.lookup("rmi://" +
getCodeBase().getHost() + ':' + port + "/HelloServer");
I previously ran this same program under WL5.1 SP9 and everything works
fine.
I defined the startupClass in the weblogic.properties file in WL5.1
Can anyone tell my what is causing this exception and how to correct the
problem?
Thanks
Terry Antle"Terry Antle" <[email protected]> writes:
These are two different methods of looking up the same object.
The exception occurs at the "lookup" method call in both cases.
"myserver" is the name of my machine that WL is running on.
7001 is the port that WL is using.
Registry reg = LocateRegistry.getRegistry("myserver", 7001);
obj = (Hello)reg.lookup("HelloServer");
or...
obj = (Hello)weblogic.rmi.Naming.lookup("rmi://" +
getCodeBase().getHost() + ':' + port + "/HelloServer");
I previously ran this same program under WL5.1 SP9 and everything works
fine.
I defined the startupClass in the weblogic.properties file in WL5.1
Can anyone tell my what is causing this exception and how to correct the
problem?I don't know what the problem is but you shouldn't be using either of
these methods for looking up RMI objects - you should use JNDI instead.
Thanks
andy -
Jini and Rmi utilisation for a particulary case..
I have to write a application which is going to connect our server to different hospitals infromatque system.
The application would provide a user interface in hospital side wich is going to make them able to send us a inventory file(fromated differently for each hospital with their own informatiqe system).
The application have also to change the the file format befor stored in our data-base(each information have to go to different table)
My supervisor ask me to look Jini and Rmi technologie for this application..
So far i read some information about both technologie..but still i'm wondering my self is Jini or Rmi have a real use in this case.
If your are masterd in those technologie and java networking device woud you help me up ?
Could you tell me if those technologie have to be realy use in this case or there is other solution with java programming.
Thank's
Astiage GhassemianJini is a high level framework that a computer to easily locate a service provider in a network and get the service. So your case does not need such a framework because in your case, just like most of todays application, the service is provided only by your server and you know where it is and what it does. You just need something a one level lower than Jini that actually does the communication - RMI. Jini runs only top of any other lower level protocol including RMI. Detailed description of Jini:
Jini technology is an architecture for the construction of systems from objects and networks. The Jini architecture lets programs use services in a network without knowing anything about the wire protocol that the service uses. One implementation of a service might be XML-based, and another RMI-based, and a third CORBA-based. The client is, in effect, taught by each service how to talk to it. A service is defined by its programming API, declared as a Java programming language interface.
When a service is plugged into a network of Jini technology-enabled services and/or devices, it advertises itself by publishing a Java programming language object that implements the service API. This object's implementation can work in any way the service chooses. The client finds services by looking for an object that supports the API. When it gets the service's published object, it will download any code it needs in order to talk to the service, thereby learning how to talk to the particular service implementation via the API. The programmer who implements the service chooses how to translate an API request into bits on the wire using UPnP, RMI, CORBA, or a private protocol.
In other words, the Jini architecture uses objects that move around the network to make each service, as well as the entire network of services, adaptable to new strategies over time. -
Can someone help me understand and analyze the marshaling techniques of CORBA, RMI and RMI-IIOP??
RMI/JRMP is easy, just read the RMI Specification:
http://java.sun.com/j2se/1.5.0/docs/guide/rmi/spec/rmi-protocol.html
CORBA is not so easy. Find the GIOP and IIOP specifications at http://www.omg.org -
Making choice between socket and RMI
I never use RMI, but i am familiar to socket programming. i want to write an online game, I know that use RMI will easy than use socket, could anyone tell me what factors will affect the choice between using socket and RMI if don't consider which one i am familiar ?
thanks
jackyI would consider the amount of traffic your online game is going to be generating. Obviously, if the traffic is the bottleneck, you will want to optimize it as much as possible.
I can see that if you are familiar with sockets and socket programming, where this is very appealing because after all, you can't get much faster than raw sockets. Also, the Java APIs around sockets are much easier than the equivalent BSD Socket C/C++ libraries.
Still, RMI has much more to offer.
o It is relatively easy to set up a connection
o exceptions will be thrown when problems occur
o serializing classes is so easy it's laughable
o If performance becomes an issue, you can (as the previous poster suggests) create your own custom socket factory which optimizes the used bandwidth. Options here include compression if you have the CPU cycles to spare.
o There are mechanisms in place for working RMI over firewalls
Many of the things that RMI offers, you might find yourself re-writing in your own socket-based API. Personally, I would choose RMI. -
CORBA and RMI are "dead"?
Hi,
I'm a Comp. Sci. student taking a course in CORBA and RMI and was wondering how relevant these technologies are out in the real world? I have a friend in industry who tells me that these technologies are "dead". He says XML has taken over as a communications standard.
Also, I am in the design phase of developing a 3D online game and I want to know if CORBA or RMI is fast enough to be used in a realtime application such as this (let's say I want to make 10 remote method calls per second to each of 50 clients). Can someone aim me at some benchmarks or performance figures?
Thanks all.1. Your friend doesn't know as much as he thinks.
His statement is like saying "Conversation is dead because everybody uses English."
I can't speak about CORBA, but
o We have some very robust applictions written using RMI.
o We wonder if SUN is walking away from RMI totards JAX: an XML-based communications scheme.
2. Your problem is kind of under-specified, but
o the way you phrased it sounds like lots of callback from server to clients - an area RMI handles, but only very well on LANs.
o I suspect your performance will be more limited by network characteristics than by RMI. Unerneath, it's just TCPIP. -
Lazy loading, EntityManager and concurrency.
I need advice which strategy to use with lazy loading.
My project is based on Spring, Struts 2 and Hibernate JPA. I have enough OneToMany and ManyToMany relationships and it's reasonable to use lazy loading. It seems very convenient to load data in Struts Actions with OpenEntityManagerInViewFilter in such way like:
Style style = user.getStyle()
But to avoid LazyLoadException I have to use:
@PersistenceContext(type=PersistenceContextType.EXTENDED)
Unfortunately, EntityManager in this case becomes not thread-safe, according to Spring docs: "+Extended EntityManagers are not thread-safe, hence they must not be used in concurrently accessed beans (which Spring-managed singletons usually are).+" EXTENDED means that EntityManager is shared in user session and my EntityManager is injected in singleton services.
I've found this issue when tried to make quick sequential page reloading which call some selects and got:
java.sql.SQLException: You can't operate on a closed Statement!!!
What's the best practice in this situation:
1. Try synchronize session access to EntityManager by myself or put each user database requests in separate queue (something terrible I suppose).
2. Use HQL queries with join fetch to preload data for access outside of transaction (maybe overhead).
3. Or something else???
And why we need EXTENDED context if it's so unreliable??
Thanks for help!Hi
Do you have the link to the "lazy loading content"?
I can't find a proper way to do it.
Thanks -
JPA - EntityManager - createQuery - Inheritance
I'm quite new to JPA and I need support on query syntax.
I have an abstract entity:
@MappedSuperclass
public abstract class HACCP implements Serializable {
}and more than one concrete implementations used to differentiate the DB table where data are stored
@Entity
@Table(schema = "dbo", name = "haccp_01")
public class HACCP01 extends HACCP {
@Entity
@Table(schema = "dbo", name = "haccp_02")
public class HACCP02 extends HACCP {
}I want to use only one service to execute CRUD functionalities.
When I retrieve data using the find method of the EntityManager everithing works fine:
em.find(HACCP.class, id);and at runtime the concrete class identifies the correct DB table.
Now I need to write my own query with a where clause
Query query = getEntityManager().createQuery( "select p FROM HACCP p WHERE [...]");obviously forcing the name of the table is not what I want!
How shold I write the query?
Edited by: mbm63 on Aug 1, 2008 11:52 AMSolved!
I just get the runtime simple name of the argument class and build the query using it:
public HACCP retrieveCurrent(HACCP haccp) {
Query query = getEntityManager().createQuery( "select p FROM " + haccp.getClass().getSimpleName() + " p WHERE [...]");
} -
Conflict between socket and RMI
Hi
I wrote a program in client-server using socket and it was fine. I also wrote a client-server program using RMI. Fine as well. But after I connected the client-server using socket (open socket, send-receive messages, close socket), then use RMI. I got java.rmi.NotBoundException.
Would anyone have a look and provide your feedback please? Thanks.
big J
*****************this is Server.java ***************************
package single;
import java.io.*;
import java.rmi.Naming;
import java.rmi.RemoteException;
import java.net.*;
import java.rmi.*;
public class Server
extends Thread {
public static final int SOCKETPORT = 5555;
private String serverName;
public Server() throws IOException {
System.out.println("*** socket opened ***");
serverName = new String("localhost");
ServerSocket serverSocket = new ServerSocket(SOCKETPORT);
Socket socket = serverSocket.accept();
InputStream is = socket.getInputStream();
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(is));
System.out.println(bufferedReader.readLine());
OutputStream os = socket.getOutputStream();
PrintWriter printWriter = new PrintWriter(new OutputStreamWriter(os), true);
printWriter.println("from server");
os.close();
is.close();
socket.close();
System.out.println("*** socket closed ***");
public void runServer() {
System.out.println("*** start of run():RMI ***");
System.setSecurityManager(new SecurityManager());
try {
RMIInterfaceImpl rMIInterfaceImpl = new RMIInterfaceImpl();
Naming.bind("//" + serverName + ":9999/RMIInterface", rMIInterfaceImpl);
catch (RemoteException ex) {
catch (MalformedURLException ex) {
catch (AlreadyBoundException ex) {
System.out.println("*** end of run():RMI ***");
public static void main(String args[]) throws Exception {
Server server = new Server();
server.runServer();
******************this is Client.java **************************
package single;
import java.io.*;
import java.net.*;
import java.rmi.Naming;
public class Client {
private String serverName;
private final static int SOCKETPORT = 5555;
public Client() throws IOException {
serverName = new String("localhost");
Socket socket = new Socket(serverName, SOCKETPORT);
OutputStream os = socket.getOutputStream();
PrintWriter printWriter=new PrintWriter(os, true);
printWriter.println("from client");
InputStream is = socket.getInputStream();
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(is));
System.out.println(bufferedReader.readLine());
is.close();
os.close();
socket.close();
public void runClient() throws Exception {
System.out.println("*** start of runClient():RMI ***");
System.setSecurityManager(new SecurityManager());
RMIInterface rMIInterfaceImpl = (RMIInterface) Naming.lookup(
"//" + serverName + ":9999/RMIInterface");
String str = rMIInterfaceImpl.print();
System.out.println(str);
rMIInterfaceImpl.serverSide();
System.out.println("*** end of runClient():RMI ***");
public static void main(String args[]) throws Exception {
Client client = new Client();
client.runClient();
***************** this is RMIInterface.java ***********************
package single;
import java.rmi.Remote;
import java.rmi.RemoteException;
interface RMIInterface
extends Remote {
String print() throws RemoteException;
void serverSide() throws RemoteException;
********************* this is RMIInterfaceImpl.java ***************
package single;
import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;
public class RMIInterfaceImpl
extends UnicastRemoteObject
implements RMIInterface {
public RMIInterfaceImpl() throws RemoteException {}
public String print() {
return new String("hello world");
public void serverSide(){
System.out.println("this should appear in serverside");I think you have a timing problem between your client and server. As soon as your client and server programs have finished their socket communication, they will both do their "runServer"/"runClient" methods. If the client attempts to lookup the server before the server has registered itself via Naming.bind(), I would expect that's why you're getting a NotBoundException in the client.
You probably wouldn't use the design of your test client/server for something significant, but a quick and dirty way to make this work might be to have the client call Thread.sleep() for a few seconds before trying to do the lookup. -
Problem with JPA Implementations and SQL BIGINT in primary keys
I have a general Question about the mapping of the SQL datatype BIGINT. I discovered, that there are some different behaviour depending on the JPA implementation. I tested with TopLink Essentials (working) and with Hibernate (not working).
Here is the case:
Table definition:
/*==============================================================*/
/* Table: CmdQueueIn */
/*==============================================================*/
create table MTRACKER.CmdQueueIn
CmdQueueInId bigint not null global autoincrement,
Type int,
Cmd varchar(2048),
CmdState int,
MLUser bigint not null,
ExecutionTime timestamp,
FinishTime timestamp,
ExecutionServer varchar(64),
ScheduleString varchar(64),
RetryCount int,
ResultMessage varchar(256),
RecordState int not null default 1,
CDate timestamp not null default current timestamp,
MDate timestamp not null default current timestamp,
constraint PK_CMDQUEUEIN primary key (CmdQueueInId)
The java class for this table has the following annotation for the primary key field:
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
@Column(name = "CmdQueueInId", nullable = false)
private BigInteger cmdQueueInId;
When using hibernate 3.2.1 as JPA provider I get the following exception:
avax.persistence.PersistenceException: org.hibernate.id.IdentifierGenerationException: this id generator generates long, integer, short or string
at org.hibernate.ejb.AbstractEntityManagerImpl.throwPersistenceException(AbstractEntityManagerImpl.java:629)
at org.hibernate.ejb.AbstractEntityManagerImpl.persist(AbstractEntityManagerImpl.java:218)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.springframework.orm.jpa.SharedEntityManagerCreator$SharedEntityManagerInvocationHandler.invoke(SharedEntityManagerCreator.java:176)
at $Proxy16.persist(Unknown Source)
at com.trixpert.dao.CmdQueueInDAO.save(CmdQueueInDAO.java:46)
at com.trixpert.test.dao.CmdQueueInDAOTest.testCreateNewCmd(CmdQueueInDAOTest.java:50)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at junit.framework.TestCase.runTest(TestCase.java:154)
at junit.framework.TestCase.runBare(TestCase.java:127)
at
Caused by: org.hibernate.id.IdentifierGenerationException: this id generator generates long, integer, short or string
at org.hibernate.id.IdentifierGeneratorFactory.get(IdentifierGeneratorFactory.java:59)
at org.hibernate.id.IdentifierGeneratorFactory.getGeneratedIdentity(IdentifierGeneratorFactory.java:35)
at org.hibernate.id.IdentityGenerator$BasicDelegate.getResult(IdentityGenerator.java:157)
at org.hibernate.id.insert.AbstractSelectingDelegate.performInsert(AbstractSelectingDelegate.java:57)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2108)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2588)
at org.hibernate.action.EntityIdentityInsertAction.execute(EntityIdentityInsertAction.java:48)
at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:248)
at org.hibernate.event.def.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:290)
at org.hibernate.event.def.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:180)
at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:108)
at org.hibernate.event.def.DefaultPersistEventListener.entityIsTransient(DefaultPersistEventListener.java:131)
at org.hibernate.event.def.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:87)
at org.hibernate.event.def.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:38)
at org.hibernate.impl.SessionImpl.firePersist(SessionImpl.java:618)
at org.hibernate.impl.SessionImpl.persist(SessionImpl.java:592)
at org.hibernate.impl.SessionImpl.persist(SessionImpl.java:596)
at org.hibernate.ejb.AbstractEntityManagerImpl.persist(AbstractEntityManagerImpl.java:212)
... 34 more
This means, that their ID generator does not support java.math.BigInteger as datatype.
But the code works if I take TopLink essentials as JPA Provider.
Looking at the spec shows the following:
In chapter 2.1.4 "If generated primary keys are used, only integral types will be portable." Integral datatypes are byte, short, int, long and char. This would mean, that the Hibernate implementation fits the spec but there seem to be a problem in general with BIGINT datatypes.
I use a SYBASE database. There it is possible to declare a UNSIGNED BIGINT. The range of numbers is therefore 0 - 2^64 - 1. Since in Java a long is always signed it would mean its range is from -2^63 -1 to 2^63 -1. So a mapping of BIGINT to java.lang.long could result in an overflow.
The interesting thing is, that I used NetBeans to reverse engineer an existing database schema. It generated for all Primary Keys of Type BIGINT automatically a java.math.BigInteger. But for other fields (not being keys) it mapped BIGINTs to java.lang.long.
It looks like there are some problems with either the spec itself or the implementation of it. While TopLink seems to handle the problem correctly, Hibernate doesn't. But Hibernate seems to fulfill the spec.
Is anybody familiar with the Spec reading this and can elaborate a little about this situation?
Many thanks for your input and feedback.
TomNot sure if I clearly understand your issue, would be good if you can explain it a bit more clearly.
"I select a value from LOV and this value don't refresh in the view"
If you mean ViewObject, check if autoSubmit property is set to true.
Amit -
Is RMI the right choice for developing a remote desktop application (sending mouse and keys events and receive screen shots) ?
That's not a reason, that's just a (fallacious) assertion about using RMI for anything. In fact, 'managing the RMI server' is probably the easiest part of RMI.
The reason I said it isn't appropriate is that the communications primitives you need can't be sensibly expressed as procedure calls. You have a stream of screen information flowing between the remote and the peer, and you may have occasional keyboard/mouse events going the other way if you implement remote control. RMI is a completely inappropriate choice for this. -
Problem accesing JPA EntityManager from JSP scriplet
Hy,
I am trying to access an EntityManager from JSP scriptlet for testing purposes and it just doesn't work.
Here is the JSP scriptlet:
<%
EntityManager em = (EntityManager) (new InitialContext()).lookup("java:comp/env/persistence/em");
Query query = em.createQuery("select u from USER u");
List<User> users = (List<User>) query.getResultList();
for (User user : users) { user.toString(); }
%>
The application is deployed in JBoss 4.2.2.GA.Sorry for my previous post. It was incomplete.
I am trying to access an EntityManager from JSP scriptlet for testing purposes and it doesn't work.
Here is the JSP scriptlet:
<%
EntityManager em = (EntityManager) (new InitialContext()).lookup("java:comp/env/persistence/em");
Query query = em.createQuery("select u from USER u");
List<User> users = (List<User>) query.getResultList();
for (User user : users) { user.toString(); }
%>
persistence.xml file :
<persistence-unit name="myApp">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<jta-data-source>java:/XAOracleDS</jta-data-source>
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.Oracle9iDialect"/>
</properties>
</persistence-unit>
web.xml file :
<persistence-context-ref>
<persistence-context-ref-name>persistence/em</persistence-context-ref-name>
<persistence-unit-name>myApp</persistence-unit-name>
</persistence-context-ref>
The application is deployed in JBoss 4.2.2.GA. When I access the JSP page I get the following exception:
javax.servlet.ServletException: javax.naming.NameNotFoundException: persistence not bound
I guess I have to configure the resource in jboss-web.xml too, but I don't know how. I tried with <resource-ref>, but I got the same error.
Any help at all would be highly appreciated !
Thanks.
Andrei
Maybe you are looking for
-
I am a very amateur web designer, who is also very new to CSS, so please be gentle- I am having a very frustrating issue with Firefox. My website is designed so that when my main menu navigation bar is too long for the screen, it automatically conver
-
Hi All, Have an app that I am creating in flashbuilder 4, java axis 2 web service and mysql. In my app I have defined a service. I have had not problems with pulling data and inserting data by calling my java functions through the service. I added a
-
What do I need to do to use a Wal Mart Straight talk chip in a factory unlocked iPhone 4S?
What do I need to do to use a Wal Mart Straight talk chip in a factory unlocked iPhone 4S?
-
Two problems: hiding key-switch notes and messages to effect-plugins
Hello, first please apologize my bad (school-) English, which I haven't much practiced sind I left school more than 30 yeras ago. I have got two problems, and I should be grateful, if somebody could give me a hint. 1. I am using sample libraries, whi
-
How to migrate my effects custom presets from Premiere Pro CC to Premiere Pro CC 2014?
I have recently created a whole bunch of custom made presets for all the effects I use on a regular daily bases on Premiere Pro CC. Today I installed the new CC 2014 and all my custom bins and effects presets are gone and to create them all again wil