cancel
Showing results for 
Search instead for 
Did you mean: 

JPA help needed(Java Persistence)

Former Member
0 Kudos

Hi friends ,

Is there any demo for JPA ,

I have to perform Java Persistence ,

I have the underlying tables , and I have to access and manipulate them , just like Java objects

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi, Brian,

I do not know how familiar are you with JPA, so my answer might not be optimal... Actually, you can read more about SAP JPA on [THIS|http://help.sap.com/saphelp_nwce10/helpdata/en/44/eba6292f446c30e10000000a114a6b/frameset.htm] page. It describes the general development scenario when working with JPA.

In JPA, there are the so called "Entities", which are regular Java objects that have mapping to tables in a relational database. See [THIS|http://help.sap.com/saphelp_nwce10/helpdata/en/46/8b38425f9c6be3e10000000a155369/frameset.htm] page for information about how to create entities and generate the corresponding database tables using the SAP NetWeaver Developer Studio.

However, if you have your database tables, but you do not have your entities, you can generate entities from database tables. See how to do this on [THIS|http://help.sap.com/saphelp_nwce10/helpdata/en/44/edbd4aa338108ee10000000a11466f/frameset.htm] page using the SAP NetWeaver Developer Studio.

To access and manipulate entities, you use the so called "Entity Manager". See [THIS|http://help.sap.com/saphelp_nwce10/helpdata/en/46/b1096a8e3d06f2e10000000a114a6b/frameset.htm] page for general information about how to use the Entity Manager.

[THIS|http://help.sap.com/saphelp_nwce10/helpdata/en/46/307a2a50094f09e10000000a114a6b/frameset.htm] page shows information about how to use the Entity Manager in Enterprise Java Beans (EJB).

[THIS|http://help.sap.com/saphelp_nwce10/helpdata/en/46/796c1da14f59d8e10000000a1553f6/frameset.htm] page shows how to use the Entity Manager in web applications.

Hope that helps!

Regards,

Yordan

Former Member
0 Kudos

Hi Yordan ,

I have read all the documents regarding JPA .

I understand the concept of JPA .

But I am a new developer , I dont know exactly how to use the commands , ie where should I create the EJB and then how to use it in my Application Service .

Till now I just made my own custom tables in Dictionary(in NWDS) , then in Java EE I created a new EJB module and set the Project facet settings(to include persistence) and after that set the JPA parameters , and then modified the persistence.xml file ,

After that I created an Appl Service , added the BO as dependency(did that in Dev Infrastructure) and tried to access the entities(ie the tables I created) , but was not able to do so .

-


Only thing I want to do is , to access the tables as objects , the tables are already present in the database , is it possible to give the steps as in how to do that using JPA

Thanks

Former Member
0 Kudos

Hi, Brian,

I will try to explain the same stuff again, but in detail.

If you want to access your database tables as objects, that means you need to have the objects (entities) that correspond to the database tables that you have.

If you have created your database tables, that does not mean that you have created the corresponding entities. That's why I gave you the link to the document that describes how you can generate entities from existing tables.

When you generate your entities, they should be stored (by default) under the EJB module that you have already created.

Now, you have the entities, i.e. the objects.

What kind of access and manipulation of the objects do you want?

  • If you want to access and manipulate the object files within the SAP NetWeaver Developer Studio, open your EJB-module (in the Java EE perspective, Project Explorer view) and you will see the generated entities. Double-click to open an entity and edit its code.

  • If you want to access and manipulate the objects during runtime (send commands to the objects, like FIND, PERSIST, MERGE, REMOVE) of your application, then you need an Entity Manager instance. That's why I gave you the link to the document that describes how to obtain an Entity Manager and how to use it in your application code.

I do hope this is at least a bit more clear now.

Regards,

Yordan

Former Member
0 Kudos

Hi Yordan ,

Thank You so much for your help .

I have done most of the steps , but ..

The Entities have been created in the EJB module , but now in my Application Service where I have an operation where I instantiate the Entity Manager .I can't see the Entities, nor is there any option that allows me to import anything .

I tried adding the EJB as dependency ,

but even then I am not able to view my Entities .May be that I have not added the dependencies properly (Please show how to add the dependency(Have to add the EJB to my current Application Service created in CAF)),

please help , I need it urgently.

Former Member
0 Kudos

>

> The Entities have been created in the EJB module , but now in my Application Service where I have an operation where I instantiate the Entity Manager .I can't see the Entities, nor is there any option that allows me to import anything .

>

> I tried adding the EJB as dependency ,

> but even then I am not able to view my Entities .May be that I have not added the dependencies properly (Please show how to add the dependency(Have to add the EJB to my current Application Service created in CAF)),

Hi, Brian,

I am not familiar enough with CAF, but I roamed around the Composite Application perspective and created a test Application service... Here are my steps:

(Composite Application perspective)

(Composite Application Explorer view)

1. Created an application service.

2. In the "Implementation" tab, clicked the EJB Implementation Class.

This generated and added the EJB implementation files to a default-named source package in the src/ directory of the EJB-module part of your composite application. You can see these in the Project Explorer of the Java EE perspective OR in the Navigator view of the Composite Application perspective.

(Navigator view)

3. Opened the Properties of my /ejbmodule, chose Project Facets and added the Java Persistence facet. For persistence configuration, I chose the SAP JPA platform and my (already existing) Dictionary connection profile. Did not create orm.xml file.

4. Generated my entities from the tables, that existed in the Dictionary: in the context menu of my /ejbmodule >> JPA Tools >> Generate Entities. For schema, I chose the one corresponding to my Dictionary DC, where I have defined my tables. For package, I chose a custom one.

RESULT: My /ejbmodule now contains two source packages - one for my EJB implementation and one for my entities.

5. In the EJB implementation, I add the following line at the top:

import the.package.of.my.entities;

RESULT: In the EJB implementation, I am now able to obtain an Entity Manager instance, and access and manipulate my entities.

Hope that helps!

Regards,

Yordan

Former Member
0 Kudos

Hi Yordan ,

Thanks a bilion for your help .

Actually I added the dependecy for Appl Service as a EJB module from Development Infrastr Perspective .

But the problem there is that we have to build the Appl Service before we can use that dependency , I didnt do that , so after I seen the dirty parts in Dev Infrastr Perspective , I did so .

So now I should be able to instantiate EntityManager (and use it as "em.persist" to add persistence for the entities, and similarly use "em.find" ''em.remove') within my Appln Service. and those would be reflected in my database????

What is the use of adding the <jta-data-source> in the persistence.xml file

Because I have not set up a Data Source in NetWeaver Admin

, so without this wont I be able to use em.persist in my Appl Service ? because till now I thought that we are accesing the tables and persisting the entities using the connection we create in the step(ejbmodule>properties>JPA>add connection)

And secondly what is the importance of the orm.xml file ?

Again Thanks a lot for your help

Former Member
0 Kudos



@PersistenceContext(unitName="CAR_AL")	
public EntityManager em;
	
@com.sap.caf.dt.CAFOperation(name = "getDetails")	
public com.sap.demo.perbrian_cas.types.EmpList getDetails() {


String str = "SELECT var FROM TestTable var" ;
		
	EmpList returnEmp = new EmpList();
	List<EmpData> temp = new ArrayList<EmpData>();
		
	try {
			
			
			
		List<TestTable> EmpTypeList = em.createQuery(str).
					getResultList();
			
		for(int i=0 ; EmpTypeList != null && 
					i<EmpTypeList.size();i++){
			EmpData EmpObj = new EmpData();
			EmpObj.setEmp_ID(EmpTypeList.get(i).getEmpId());
			EmpObj.setEmp_Name(EmpTypeList.get(i).getEmpName());
			EmpObj.setEmail(EmpTypeList.get(i).getEmail());
			temp.add(EmpObj);				
		}
			
		returnEmp.setEmpAll(temp);
			
	} catch (NoResultException nre) {
		return null;
	}
	catch (Throwable th){
		return null;			
	}
	return returnEmp;
		
}


Former Member
0 Kudos

My entity is TestTable (Test_Table in my database)

The only question I want to ask is that if I write within my try and catch -->



TestTable t = new TestTable();
t.setEmp_ID("20");
t.setEmp_Name("Yordan");

em.persist(t);

will this data be reflected in the database

Former Member
0 Kudos

>

> So now I should be able to instantiate EntityManager (and use it as "em.persist" to add persistence for the entities, and similarly use "em.find" ''em.remove') within my Appln Service. and those would be reflected in my database????

>

> What is the use of adding the <jta-data-source> in the persistence.xml file

> Because I have not set up a Data Source in NetWeaver Admin

> , so without this wont I be able to use em.persist in my Appl Service ? because till now I thought that we are accesing the tables and persisting the entities using the connection we create in the step(ejbmodule>properties>JPA>add connection)

>

>

> And secondly what is the importance of the orm.xml file ?

Hi, Brian,

These steps would allow you to use the Entity Manager within the EJB implementation of your application service.

<jta-data-source> is used to specify the DataSource you want to use for your application.

The orm.xml file is an alternative for defining the object-relational mapping. As you use annotations to do that, you do not need orm.xml.

Generally, if you want to develop and run a working application (that changes and persists data on the database), the picture is not that simple.

1, as I said, Java Dictionary is not a real database. You use it just to define your tables. Afterwards, you have to deploy these table definitions on a real database. [MORE INFORMATION|http://help.sap.com/saphelp_nwce10/helpdata/en/69/f9bc3d52f39d33e10000000a11405a/frameset.htm]

2, to run your application, you have to assemble it in an Enterprise Archive, then deploy it on the application server.

But I suggest that you read through the corresponding documentation, because everything that you need to know is described there, and it's too much to be copied here.

[COMPOSING SERVICES WITH CAF|http://help.sap.com/saphelp_nwce10/helpdata/en/49/80b066798a4ba2a1e26ce93997e839/frameset.htm]

Regards,

Yordan

Former Member
0 Kudos

Yordon when I tried to test my service I got this error

em is my Entity manager instance

javax.ejb.EJBException: Cannot perform injection over bean instance com.sap.demo.jpacas.modeled.appsrv.jpaservice.jpaserviceBeanImpl@5db311 for bean demo.sap.com/jpacasear*annotation|demo.sap.comjpacas~ejbmodule.jar*annotation|com.sap.demo.jpacas.modeled.appsrv.jpaservice.jpaservice; nested exception is: com.sap.engine.lib.injection.InjectionException: Injection on field em of instance com.sap.demo.jpacas.modeled.appsrv.jpaservice.jpaserviceBeanImpl@5db311 failed. Could not get a value to be injected from the factory.:




com.sap.engine.services.ejb3.util.pool.PoolException: javax.ejb.EJBException: Cannot perform injection over bean instance com.sap.demo.jpacas.modeled.appsrv.jpaservice.jpaserviceBeanImpl@5db311 for bean demo.sap.com/jpacas~ear*annotation|demo.sap.com~jpacas~ejbmodule.jar*annotation|com.sap.demo.jpacas.modeled.appsrv.jpaservice.jpaservice; nested exception is: com.sap.engine.lib.injection.InjectionException: Injection on field em of instance com.sap.demo.jpacas.modeled.appsrv.jpaservice.jpaserviceBeanImpl@5db311 failed. Could not get a value to be injected from the factory. 
at com.sap.engine.services.ejb3.util.pool.ContainerPool.translate(ContainerPool.java:288) 
at com.sap.engine.services.ejb3.util.pool.ContainerPoolImpl.doResizeOneStepUp(ContainerPoolImpl.java:378) 
at com.sap.engine.services.ejb3.util.pool.ContainerPoolImpl.ensureNotEmpty(ContainerPoolImpl.java:342) 
at com.sap.engine.services.ejb3.util.pool.ContainerPoolImpl.pop(ContainerPoolImpl.java:309) 
at com.sap.engine.services.ejb3.runtime.impl.StatelessInstanceLifecycleManager.getMethodReady(StatelessInstanceLifecycleManager.java:64) 
at com.sap.engine.services.ejb3.runtime.impl.Interceptors_StatelessInstanceGetter.invoke(Interceptors_StatelessInstanceGetter.java:14) 
at com.sap.engine.services.ejb3.runtime.impl.AbstractInvocationContext.proceed(AbstractInvocationContext.java:177) 
at com.sap.engine.services.ejb3.runtime.impl.Interceptors_SecurityCheck.invoke(Interceptors_SecurityCheck.java:21) 
at com.sap.engine.services.ejb3.runtime.impl.AbstractInvocationContext.proceed(AbstractInvocationContext.java:177) 
at com.sap.engine.services.ejb3.runtime.impl.Interceptors_ExceptionTracer.invoke(Interceptors_ExceptionTracer.java:16) 
at com.sap.engine.services.ejb3.runtime.impl.AbstractInvocationContext.proceed(AbstractInvocationContext.java:177) 
at com.sap.engine.services.ejb3.runtime.impl.DefaultInvocationChainsManager.startChain(DefaultInvocationChainsManager.java:133) 
at com.sap.engine.services.ejb3.runtime.impl.DefaultEJBProxyInvocationHandler.invoke(DefaultEJBProxyInvocationHandler.java:164) 
at $Proxy367_10002.getDetails(Unknown Source) 
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 com.sap.caf.rt.services.serviceaccess.ServiceWrapper.findByDataObject(ServiceWrapper.java:330) 
at com.sap.caf.rt.services.serviceaccess.CAFServiceAccessBeanImpl.findByDataObject(CAFServiceAccessBeanImpl.java:230) 
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 com.sap.engine.services.ejb3.runtime.impl.RequestInvocationContext.proceedFinal(RequestInvocationContext.java:43) 
at com.sap.engine.services.ejb3.runtime.impl.AbstractInvocationContext.proceed(AbstractInvocationContext.java:166) 
at com.sap.engine.services.ejb3.runtime.impl.Interceptors_StatesTransition.invoke(Interceptors_StatesTransition.java:19) 
at com.sap.engine.services.ejb3.runtime.impl.AbstractInvocationContext.proceed(AbstractInvocationContext.java:177) 
at com.sap.engine.services.ejb3.runtime.impl.Interceptors_Resource.invoke(Interceptors_Resource.java:71) 
at com.sap.engine.services.ejb3.runtime.impl.AbstractInvocationContext.proceed(AbstractInvocationContext.java:177) 
at com.sap.engine.services.ejb3.runtime.impl.Interceptors_StatefulTransactionAssociation.invoke(Interceptors_StatefulTransactionAssociation.java:43) 
at com.sap.engine.services.ejb3.runtime.impl.AbstractInvocationContext.proceed(AbstractInvocationContext.java:177) 
at com.sap.engine.services.ejb3.runtime.impl.AbstractInvocationContext.proceed(AbstractInvocationContext.java:189) 
at com.sap.engine.services.ejb3.runtime.impl.Interceptors_StatefulSessionInstanceGetter.invoke(Interceptors_StatefulSessionInstanceGetter.java:37) 
at com.sap.engine.services.ejb3.runtime.impl.AbstractInvocationContext.proceed(AbstractInvocationContext.java:177) 
at com.sap.engine.services.ejb3.runtime.impl.Interceptors_Transaction.doWorkWithAttribute(Interceptors_Transaction.java:38) 
at com.sap.engine.services.ejb3.runtime.impl.Interceptors_Transaction.invoke(Interceptors_Transaction.java:22) 
at com.sap.engine.services.ejb3.runtime.impl.AbstractInvocationContext.proceed(AbstractInvocationContext.java:177) 
at com.sap.engine.services.ejb3.runtime.impl.Interceptors_SecurityCheck.invoke(Interceptors_SecurityCheck.java:21) 
at com.sap.engine.services.ejb3.runtime.impl.AbstractInvocationContext.proceed(AbstractInvocationContext.java:177) 
at com.sap.engine.services.ejb3.runtime.impl.Interceptors_ExceptionTracer.invoke(Interceptors_ExceptionTracer.java:16) 
at com.sap.engine.services.ejb3.runtime.impl.AbstractInvocationContext.proceed(AbstractInvocationContext.java:177) 
at com.sap.engine.services.ejb3.runtime.impl.DefaultInvocationChainsManager.startChain(DefaultInvocationChainsManager.java:133) 
at com.sap.engine.services.ejb3.runtime.impl.DefaultEJBProxyInvocationHandler.invoke(DefaultEJBProxyInvocationHandler.java:164) 
at com.sap.engine.services.ejb3.runtime.impl.StatefulBMProxyInvocationHandler.invoke(StatefulBMProxyInvocationHandler.java:55) 
at $Proxy103_10002.findByDataObject(Unknown Source) 
at com.sap.caf.rt.ui.esf.BONodeServiceAccess.findBy(BONodeServiceAccess.java:296) 
at com.sap.caf.rt.ui.esf.Query.execute(Query.java:222) 
at com.sap.caf.ui.servicebrowser.components.visualizer.controllers.TableViewCC.execute(TableViewCC.java:353) 
at com.sap.caf.ui.servicebrowser.components.visualizer.controllers.wdp.InternalTableViewCC.execute(InternalTableViewCC.java:181) 
at com.sap.caf.ui.servicebrowser.components.visualizer.views.TableViewCV.onActionExcuteQuery(TableViewCV.java:429) 
at com.sap.caf.ui.servicebrowser.components.visualizer.views.wdp.InternalTableViewCV.wdInvokeEventHandler(InternalTableViewCV.java:342) 
at com.sap.tc.webdynpro.progmodel.generation.DelegatingView.invokeEventHandler(DelegatingView.java:131) 
at com.sap.tc.webdynpro.progmodel.controller.Action.fire(Action.java:72) 
at com.sap.tc.webdynpro.clientserver.phases.ProcessingEventPhase.doHandleActionEvent(ProcessingEventPhase.java:156) 
at com.sap.tc.webdynpro.clientserver.phases.ProcessingEventPhase.execute(ProcessingEventPhase.java:91) 
at com.sap.tc.webdynpro.clientserver.window.WindowPhaseModel.processRequestPartly(WindowPhaseModel.java:161) 
at com.sap.tc.webdynpro.clientserver.window.WindowPhaseModel.doProcessRequest(WindowPhaseModel.java:109) 
at com.sap.tc.webdynpro.clientserver.window.WindowPhaseModel.processRequest(WindowPhaseModel.java:96) 
at com.sap.tc.webdynpro.clientserver.window.WebDynproWindow.processRequest(WebDynproWindow.java:469) 
at com.sap.tc.webdynpro.clientserver.cal.AbstractClient.executeTasks(AbstractClient.java:52) 
at com.sap.tc.webdynpro.clientserver.cal.ClientApplication.doExecute(ClientApplication.java:1388) 
at com.sap.tc.webdynpro.clientserver.cal.ClientApplication.doProcessing(ClientApplication.java:1208) 
at com.sap.tc.webdynpro.serverimpl.core.sessionctx.AbstractExecutionContextDispatcher.delegateToApplicationDoProcessing(AbstractExecutionContextDispatcher.java:145) 
at com.sap.tc.webdynpro.serverimpl.wdc.sessionctx.DispatchHandlerForAppProcessing.doService(DispatchHandlerForAppProcessing.java:35) 
at com.sap.tc.webdynpro.serverimpl.wdc.sessionctx.AbstractDispatchHandler.service(AbstractDispatchHandler.java:116) 
at com.sap.engine.services.servlets_jsp.server.deploy.impl.module.IRequestDispatcherImpl.dispatch(IRequestDispatcherImpl.java:93) 
at com.sap.tc.webdynpro.serverimpl.wdc.sessionctx.ExecutionContextDispatcher.dispatchToApplicationDoProcessing(ExecutionContextDispatcher.java:114) 
at com.sap.tc.webdynpro.serverimpl.core.sessionctx.AbstractExecutionContextDispatcher.dispatch(AbstractExecutionContextDispatcher.java:80) 
at com.sap.tc.webdynpro.clientserver.session.ApplicationSession.dispatch(ApplicationSession.java:506) 
at com.sap.tc.webdynpro.clientserver.session.ApplicationSession.dispatch(ApplicationSession.java:526) 
at com.sap.tc.webdynpro.clientserver.session.ApplicationSession.doApplicationProcessingStandalone(ApplicationSession.java:457) 
at com.sap.tc.webdynpro.clientserver.session.ApplicationSession.doProcessing(ApplicationSession.java:248) 
at com.sap.tc.webdynpro.clientserver.session.ClientSession.doApplicationProcessing(ClientSession.java:698) 
at com.sap.tc.webdynpro.clientserver.session.ClientSession.doProcessing(ClientSession.java:230) 
at com.sap.tc.webdynpro.clientserver.session.RequestManager.doProcessing(RequestManager.java:228) 
at com.sap.tc.webdynpro.serverimpl.core.sessionctx.AbstractExecutionContextDispatcher.delegateToRequestManager(AbstractExecutionContextDispatcher.java:192) 
at com.sap.tc.webdynpro.serverimpl.wdc.sessionctx.DispatchHandlerForRequestManager.doService(DispatchHandlerForRequestManager.java:38) 
at com.sap.tc.webdynpro.serverimpl.wdc.sessionctx.AbstractDispatchHandler.service(AbstractDispatchHandler.java:116) 
at com.sap.engine.services.servlets_jsp.server.deploy.impl.module.IRequestDispatcherImpl.dispatch(IRequestDispatcherImpl.java:93) 
at com.sap.tc.webdynpro.serverimpl.wdc.sessionctx.ExecutionContextDispatcher.dispatchToRequestManager(ExecutionContextDispatcher.java:140) 
at com.sap.tc.webdynpro.serverimpl.core.sessionctx.AbstractExecutionContextDispatcher.dispatch(AbstractExecutionContextDispatcher.java:92) 
at com.sap.tc.webdynpro.serverimpl.core.sessionctx.AbstractExecutionContextDispatcher.dispatch(AbstractExecutionContextDispatcher.java:104) 
at com.sap.tc.webdynpro.serverimpl.core.AbstractDispatcherServlet.doContent(AbstractDispatcherServlet.java:87) 
at com.sap.tc.webdynpro.serverimpl.core.AbstractDispatcherServlet.doPost(AbstractDispatcherServlet.java:61) 
at javax.servlet.http.HttpServlet.service(HttpServlet.java:727) 
at javax.servlet.http.HttpServlet.service(HttpServlet.java:820) 
at com.sap.engine.services.servlets_jsp.server.Invokable.invoke(Invokable.java:66) 
at com.sap.engine.services.servlets_jsp.server.Invokable.invoke(Invokable.java:32) 
at com.sap.engine.services.servlets_jsp.server.HttpHandlerImpl.runServlet(HttpHandlerImpl.java:431) 
at com.sap.engine.services.servlets_jsp.server.HttpHandlerImpl.handleRequest(HttpHandlerImpl.java:289) 
at com.sap.engine.services.httpserver.server.RequestAnalizer.startServlet(RequestAnalizer.java:387) 
at com.sap.engine.services.httpserver.server.RequestAnalizer.startServlet(RequestAnalizer.java:376) 
at com.sap.engine.services.servlets_jsp.filters.ServletSelector.process(ServletSelector.java:85) 
at com.sap.engine.services.httpserver.chain.AbstractChain.process(AbstractChain.java:71) 
at com.sap.engine.services.servlets_jsp.filters.ApplicationSelector.process(ApplicationSelector.java:160) 
at com.sap.engine.services.httpserver.chain.AbstractChain.process(AbstractChain.java:71) 
at com.sap.engine.services.httpserver.filters.WebContainerInvoker.process(WebContainerInvoker.java:67) 
at com.sap.engine.services.httpserver.chain.HostFilter.process(HostFilter.java:9) 
at com.sap.engine.services.httpserver.chain.AbstractChain.process(AbstractChain.java:71) 
at com.sap.engine.services.httpserver.filters.ResponseLogWriter.process(ResponseLogWriter.java:60) 
at com.sap.engine.services.httpserver.chain.HostFilter.process(HostFilter.java:9) 
at com.sap.engine.services.httpserver.chain.AbstractChain.process(AbstractChain.java:71) 
at com.sap.engine.services.httpserver.filters.DefineHostFilter.process(DefineHostFilter.java:27) 
at com.sap.engine.services.httpserver.chain.ServerFilter.process(ServerFilter.java:12) 
at com.sap.engine.services.httpserver.chain.AbstractChain.process(AbstractChain.java:71) 
at com.sap.engine.services.httpserver.filters.MonitoringFilter.process(MonitoringFilter.java:29) 
at com.sap.engine.services.httpserver.chain.ServerFilter.process(ServerFilter.java:12) 
at com.sap.engine.services.httpserver.chain.AbstractChain.process(AbstractChain.java:71) 
at com.sap.engine.services.httpserver.server.Processor.chainedRequest(Processor.java:309) 
at com.sap.engine.services.httpserver.server.Processor$FCAProcessorThread.run(Processor.java:222) 
at com.sap.engine.core.thread.impl3.ActionObject.run(ActionObject.java:37) 
at java.security.AccessController.doPrivileged(Native Method) 
at com.sap.engine.core.thread.impl3.SingleThread.execute(SingleThread.java:152) 
at com.sap.engine.core.thread.impl3.SingleThread.run(SingleThread.java:247) 
Caused by: javax.ejb.EJBException: Cannot perform injection over bean instance com.sap.demo.jpacas.modeled.appsrv.jpaservice.jpaserviceBeanImpl@5db311 for bean demo.sap.com/jpacas~ear*annotation|demo.sap.com~jpacas~ejbmodule.jar*annotation|com.sap.demo.jpacas.modeled.appsrv.jpaservice.jpaservice; nested exception is: com.sap.engine.lib.injection.InjectionException: Injection on field em of instance com.sap.demo.jpacas.modeled.appsrv.jpaservice.jpaserviceBeanImpl@5db311 failed. Could not get a value to be injected from the factory. 
at com.sap.engine.services.ejb3.runtime.impl.Interceptors_DependencyInjection.invoke(Interceptors_DependencyInjection.java:25) 
at com.sap.engine.services.ejb3.runtime.impl.Interceptors_EJBContext30DependencyInjection.invoke(Interceptors_EJBContext30DependencyInjection.java:11) 
at com.sap.engine.services.ejb3.runtime.impl.AbstractInvocationContext.proceed(AbstractInvocationContext.java:177) 
at com.sap.engine.services.ejb3.runtime.impl.Interceptors_StatesTransition.invoke(Interceptors_StatesTransition.java:19) 
at com.sap.engine.services.ejb3.runtime.impl.AbstractInvocationContext.proceed(AbstractInvocationContext.java:177) 
at com.sap.engine.services.ejb3.runtime.impl.Interceptors_ApplicationInstancesCreator.invoke(Interceptors_ApplicationInstancesCreator.java:53) 
at com.sap.engine.services.ejb3.runtime.impl.AbstractInvocationContext.proceed(AbstractInvocationContext.java:177) 
at com.sap.engine.services.ejb3.runtime.impl.Interceptors_Resource.invoke(Interceptors_Resource.java:71) 
at com.sap.engine.services.ejb3.runtime.impl.AbstractInvocationContext.proceed(AbstractInvocationContext.java:177) 
at com.sap.engine.services.ejb3.runtime.impl.AbstractInvocationContext.proceed(AbstractInvocationContext.java:189) 
at com.sap.engine.services.ejb3.runtime.impl.Interceptors_NewBeanContext.invoke(Interceptors_NewBeanContext.java:17) 
at com.sap.engine.services.ejb3.runtime.impl.AbstractInvocationContext.proceed(AbstractInvocationContext.java:177) 
at com.sap.engine.services.ejb3.runtime.impl.DefaultInvocationChainsManager.startCallback(DefaultInvocationChainsManager.java:147) 
at com.sap.engine.services.ejb3.runtime.impl.StatelessInstanceLifecycleManager.makeExist(StatelessInstanceLifecycleManager.java:108) 
at com.sap.engine.services.ejb3.runtime.impl.StatelessInstanceLifecycleManager.access$000(StatelessInstanceLifecycleManager.java:23) 
at com.sap.engine.services.ejb3.runtime.impl.StatelessInstanceLifecycleManager$PoolUserImpl.createObject(StatelessInstanceLifecycleManager.java:34) 
at com.sap.engine.services.ejb3.util.pool.ContainerPoolImpl.doResizeOneStepUp(ContainerPoolImpl.java:373) 
... 113 more 
Caused by: com.sap.engine.lib.injection.InjectionException: Injection on field em of instance com.sap.demo.jpacas.modeled.appsrv.jpaservice.jpaserviceBeanImpl@5db311 failed. Could not get a value to be injected from the factory. 
at com.sap.engine.lib.injection.FieldInjector.inject(FieldInjector.java:115) 
at com.sap.engine.lib.injection.InjectionMatrix.inject(InjectionMatrix.java:45) 
at com.sap.engine.services.ejb3.runtime.impl.Interceptors_DependencyInjection.invoke(Interceptors_DependencyInjection.java:22) 
... 129 more 
Caused by: com.sap.engine.services.orpersistence.container.exceptions.ResourceException: Persistence unit 'CAR_AL' requested from archive 'demo.sap.com~jpacas~ejbmodule.jar' is not present in application 'demo.sap.com/jpacas~ear' or is not visible to the requested archive. 
at com.sap.engine.services.orpersistence.container.ORPersistenceObjectFactory.getPersistenceUnitInfo(ORPersistenceObjectFactory.java:213) 
at com.sap.engine.services.orpersistence.container.ORPersistenceObjectFactory.getObjectInstance(ORPersistenceObjectFactory.java:59) 
at com.sap.engine.lib.injection.ReferenceObjectFactory.getObject(ReferenceObjectFactory.java:65) 
at com.sap.engine.lib.injection.FieldInjector.inject(FieldInjector.java:113) 
... 131 more 
 
 
 
Close 

Former Member
0 Kudos

Hi, Brian,

I think that the cause for the exception is that you have not developed the persistence part of your application properly.

Once you have your entities and their object-relational mapping, you have to edit the persistence.xml file (define a persistence unit, specify the DataSource for your tables...).

Moreover, you have to edit the data-sources.xml and data-source-aliases.xml (or only the latter, if you are using the system database) for your EAR.

All these steps are described in the JPA documentation [HERE|http://help.sap.com/saphelp_nwce10/helpdata/en/44/eba6292f446c30e10000000a114a6b/frameset.htm].

Regards,

Yordan

Former Member
0 Kudos

Hi Yordan,

I have read the documentation you have sent .

I am not not using the the Dictionary at all.

I am directly getting the tables from the database , using (add connections --> SQL Server , in the step EJB module>properties> JPA >add conn )

But the problem is that there is no one here to set up the data source in the NetWeaver Administrator ,

is there any way I can use the default datasource or build a datasource and datasource alias.

Former Member
0 Kudos

>

> is there any way I can use the default datasource or build a datasource and datasource alias.

Hi,

I did not get if you are using the system database of the application server, but anyway...

If you want to use the default DataSource, you have to do the following:

PREREQUISITE: The database tables exist on the system database. Otherwise, you have to create them there.

1. Add the DataSource Aliases facet to your EAR-project.

2. Open the data-source-aliases.xml (it is in the EAR-project) and type a name for your alias in the <alias> tag. Ensure that the

3. Open the persistence.xml and type your alias name in the <jta-data-source> tag.

4. Re-deploy your application (i.e. the EAR-file).

This should work.

Regards,

Yordan

Former Member
0 Kudos

Hi Yordan ,

I tried that , but even then I am getting the same error ,

my tables are there the the System DB , I can view them from the SQL Server mgmt Studio .

I should be adding the facet to which ear ?

The CAF Application service right ?

which gives me ---/dictionary ---/ear ---/ejbmodule ---/metadata ---/permissions

Are there any more settings I need to do ?

Former Member
0 Kudos

>

> Are there any more settings I need to do ?

Hi,

Unfortunately, I cannot think of anything else that could solve the problem...

In my opinion, your code (the EM part) seems OK, and if you have organized your persistence imports properly, namely:

import javax.persistence.Query;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

...I do not have an idea where might the problem come from.

Regards,

Yordan

Former Member
0 Kudos

Are you sure the error hasn't changed? (Scrolling down to the end usually shows the causing exception)

One thing that is mentioned only casually in the documentation and I'm not sure whether you've already set this up: "If you are using the system database, you have to define the tables in the Java Dictionary." [1]

Have you set up the Dictionary project and deployed the tables? (There is a corresponding View in NWDS)

Cheers,

Felix

[1] http://help.sap.com/saphelp_nwce10/helpdata/en/44/edbd4aa338108ee10000000a11466f/frameset.htm

Former Member
0 Kudos

hi Felix ,

I am not using the tables created in the NW Dictionary .

I already have my tables in a custom location in my SQL Server 2005 DB at a custom location.

I can point to them by setting up the connection (using add connections) in my EJB module by setting properties>JPA>add connections , the appropriate Entities are generated .

But I still feel I am having the problem of "DataSource"

which I need to specify in persistence.xml .

How do I make that data source point to the tables in SQl DB , custom location.

Are there any more settings for DataSource ?????????

Former Member
0 Kudos

Brian,

I had precisely the same problem (being able to generate the entities in NWDS, but dependency injection failed, not finding the appropriate tables/schemata) because I used the system database. As mentioned in the quote from my previous posting, if you you the system database then you have to use the Java Dictionary.

However if you don't use the system database, then you should enable the data sources facet for your enterprise application project and have a data-sources.xml that sets up the connection to the appropriate data source. All this is described also in the documentation that was posted by Yordan.

Cheers,

Felix

Former Member
0 Kudos

>

> hi Felix ,

>

> I am not using the tables created in the NW Dictionary .

>

> I already have my tables in a custom location in my SQL Server 2005 DB at a custom location.

>

> I can point to them by setting up the connection (using add connections) in my EJB module by setting properties>JPA>add connections , the appropriate Entities are generated .

>

> But I still feel I am having the problem of "DataSource"

> which I need to specify in persistence.xml .

>

> How do I make that data source point to the tables in SQl DB , custom location.

>

> Are there any more settings for DataSource ?????????

Hi, Brian,

1) If you use the system database (part of the application server), then you should deploy only a DataSource alias by means of the data-source-aliases.xml. This alias should point to the system database. I already explained that some posts above.

2) If you use a custom database, then you should deploy a DataSource object together with your application. This means that you have to add data-sources.xml and you have to configure your DataSource object in this file. Moreover, you can optionally use a DataSource alias together with the DataSource object, i.e. you can use both data-sources.xml and data-source-aliases.xml.

In the persistence.xml you have to specify either:

  • the name of your DataSource, as specified in the data-sources.xml (this is in case you do not specify the DataSource alias)

  • the name of your DataSource alias, as specified in the data-source-aliases.xml (this is in case you have a DataSource alias)

data-sources.xml and data-source-aliases.xml are added to your EAR by means of modifying the EAR project facets (I already explained that).

I did not write all of this before, as you said you have read the documentation and you know the concepts...

Regards,

Yordan

Former Member
0 Kudos

Hi Yordan, Felix ,

Thank You so much for showing so much interest and helping me.

Well I am fairly inexperienced , so I am not good with the terminologies.

Anyways I am not creating any tables nor am I using the System Database Tables and the java Dictionary.

I have a custom database created (DB_XYZ)and am using a schema 'dbo' and within that I have my tables .

I only need to access those tables .

I have created an EJB module and generated entities , and those files are present in the package within my EJB module.

Then I am creating a Composite Appl , and then creating a Appl Service which adds that EJB module as a dependency and so I can see the Entity in my Application Service .

But when I try to Instantiate :: ie Entity Manager em ; in the operation of my Appl Service , I get a problem .

So I dont understand what you are refering to as Enterprise Appl Project ;where I need to set the project facets for Data Source.

Do I have to go to netWeaver Administrator and create a data Source there and add it to the persistence.xml ???

Former Member
0 Kudos

>

> So I dont understand what you are refering to as Enterprise Appl Project ;where I need to set the project facets for Data Source.

>

>

> Do I have to go to netWeaver Administrator and create a data Source there and add it to the persistence.xml ???

Hi, Brian,

There are two options to create a DataSource:

  • (Design-time) Deploy it with your application - this is when you use the data-sources.xml in your EAR.

  • (Run-time) Create the DataSource using the SAP NWA - [MORE INFORMATION|http://help.sap.com/saphelp_nwce10/helpdata/en/56/1e5d427213d142e10000000a1550b0/frameset.htm]

In both cases, you will also have to enter the same DataSource name (or the name of its alias) in the persistence.xml.

Regards,

Yordan

Former Member
0 Kudos

Hi Yordon,

I did as you said .

In NetWeaver Administrator , I created a datasource and for that I had to create a data Manager for which I had to provide a SQL driver file named sqljdbc.jar , this was the same one that I used to create the connections ,

So I did that , but after I create the Driver and the datasource ,

The dataSource is displayed as Not Available

Is that the reason I am getting the injection error .

Are there any possible resolutions for that , or do I need to contact my Basis Team.

Problem is that no one else here knows about Data Source.

Former Member
0 Kudos

Hi Yordan ,

there is some problem with my nwa

So I am not able to create a Datasource there ,

can you give me a sample file for data-sources.xml with the important tags needed,

I tried understanding that from help.sap

but I couldnt understand which tags to put and where,

ie database class , database url .........

Former Member
0 Kudos

Hi, Brian,

This is the typical structure of the data-sources.xml:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE data-sources SYSTEM "data-sources.dtd" >
<data-sources>
  <data-source>
    <data-source-name>data-source-name</data-source-name>
    <driver-name>driver-name</driver-name>
    <sql-engine>sql-engine</sql-engine>
    <jdbc-1.x>
      <driver-class-name>driver-class-name</driver-class-name>
      <url>url</url>
      <user-name>user-name</user-name>
      <password>password</password>
    </jdbc-1.x>
  </data-source>
</data-sources>

You can find more information on the following links:

[data-sources.dtd|http://help.sap.com/saphelp_nwce10/helpdata/en/64/0bee3da7138e5be10000000a114084/frameset.htm]

[Working with Data Sources|http://help.sap.com/saphelp_nwce10/helpdata/en/45/07d0efea3e0485e10000000a155369/frameset.htm]

Hope that helps!

Regards,

Yordan

Former Member
0 Kudos

Hi Yordan ,

I am still struggling with the same error .I went to the log trace and found this



Caused by: com.sap.engine.services.orpersistence.container.exceptions.ResourceException: 

 

Persistence unit 'EmpPersistenceUnit' requested from archive '&*&*%*ejbmodule.jar' is not present in 

application '%$^%&*%*jpanewcas~ear' or is not visible to the requested archive.

 

 

            at com.sap.engine.services.orpersistence.container.ORPersistenceObjectFactory.getPersistenceUnitInfo(ORPersistenceObjectFactory.java:213)

            at com.sap.engine.services.orpersistence.container.ORPersistenceObjectFactory.getObjectInstance(ORPersistenceObjectFactory.java:59)

            at com.sap.engine.lib.injection.ReferenceObjectFactory.getObject(ReferenceObjectFactory.java:65)

            at com.sap.engine.lib.injection.FieldInjector.inject(FieldInjector.java:113

Former Member
0 Kudos

Hi Yordan ,

I have created a datasource in NWA .

that ear file is from my Composite Application Service ,

what could be the cause of the problem .

I have tried all possible DataSources ie Custom DS , System DS .

But I still get the same error

Former Member
0 Kudos

Hi, Brian,

As a prerequisite to my current post, I assume that you have properly created (1) your DataSource using NWA, and you have also specified (2) a DataSource alias for this DataSource (in NWA, during the DataSource creation procedure, you have the option to create a DataSource alias also).

Now, double-check the following points:

1, There should be NO data-sources.xml, nor data-source-aliases.xml in your EAR, because you have already created these in NWA.

If these files ARE present in the EAR, you have to remove the "DataSource" and "DataSource alias" facets, then delete these two files from the EAR.

2, The name of the DataSource alias (pointing to the successfully created DataSource in NWA) is present in your persistence.xml within the <jta-data-source> tag.

If you dot have created a DataSource alias anyway, you can use the name of the DataSource.

3, The name of the persistence unit in the persistence.xml is the same as the value of the name attribute of the @PersistenceContext annotation in your application code.

<persistence-unit name="CAR_AL">
	<jta-data-source>YOUR_DATA_SOURCE_OR_ALIAS_NAME</jta-data-source>
</persistence-unit>

...

@PersistenceContext(name="CAR_AL")
EntityManager em;

Of course, if you happen to make any changes according to the upper considerations, you will have to rebuild and/or redeploy your application afterwards.

I hope this helps!

Regards,

Yordan

Former Member
0 Kudos

Hi Yordan ,

Thank You for all the intrest you have shown and help given.

I am pretty confident that the error is in the data Source creation in nwa.

Actually I am pointing to a custom database in my MS SQL Server.

So I have to upload some files(sqljdbc.jar) to create the driver.

Which is needed for construction of the DataSource.

The only problem is that I can't verify if the DataSource is pointing correctly to my table.

Is there anyway to check in nwa , if the DataSources we create are pointing to the appropriate locations.

Please help me with this, because I feel this is the only hurdle for me .

Thanks in advance ,

Brian.

Former Member
0 Kudos

I searched the default trace and found out that the problem was in dependencies.

But now I am receiving this problem


getrowscas.getRowsCASBeanImpl@1342f38 failed because the field is not assignable from injection object com.sap.engine.services.orpersistence.container.EntityManagerFactoryProxy@1080e5a

adrian_goerler
Active Participant
0 Kudos

Hi Brian,

it seems that the target class of the injection is not assignable from the class EntityManagerFactory.

Are you sure it is an EntityManagerFactory (@PersistenceUnit), you want to inject? Or should it rather be an EntityManager (@PersistenceContext)?

IHTH,

Adrian

Former Member
0 Kudos

Hi all ,

Thanks for all your help.

I have solved my issue.

The main problem was in accessing the Entity from my ejb module during runtime.

Hence I added the dependencies and the Entity Manager worked perfectly.

Former Member
0 Kudos

Hi Yordan,

I am facing another problem.

My JPA application works fine when I use a single column as the primary key.

But as soon as I make 2 keys of my table as the primary key, I get the following error.


Caused by: com.sap.engine.lib.injection.InjectionException: Injection on field em of instance com.wipro.CompJPABean@1ac5b1e failed. Could not get a value to be injected from the factory. 
at com.sap.engine.lib.injection.FieldInjector.inject(FieldInjector.java:115) 
at com.sap.engine.lib.injection.InjectionMatrix.inject(InjectionMatrix.java:45) 
at com.sap.engine.services.ejb3.runtime.impl.Interceptors_DependencyInjection.invoke(Interceptors_DependencyInjection.java:22) 
... 98 more 
Caused by: java.lang.RuntimeException: The persistence unit is inconsistent with the database schema:
Error on attribute >>com.wipro.TestTableOne.column4<<: The column >>Test_Table_One.COLUMN4<< does not exist.
Error on attribute >>com.wipro.TestTableOne.column3<<: The column >>Test_Table_One.COLUMN3<< does not exist.
Error on attribute >>com.wipro.TestTableOne$PK.column2<<: The column >>Test_Table_One.COLUMN2<< does not exist.
Error on attribute >>com.wipro.TestTableOne$PK.column1<<: The column >>Test_Table_One.COLUMN1<< does not exist.

Are there any dependencies I need to add when using a Composite key. I havent found much documentation regarding this.

Thanks Brian

Former Member
0 Kudos

Hi Adrian,

I am facing another problem.

My JPA application works fine when I use a single column as the primary key.

But as soon as I make 2 keys of my table as the primary key, I get the following error.


Caused by: com.sap.engine.lib.injection.InjectionException: Injection on field em of instance com.wipro.CompJPABean@1ac5b1e failed. Could not get a value to be injected from the factory. 
at com.sap.engine.lib.injection.FieldInjector.inject(FieldInjector.java:115) 
at com.sap.engine.lib.injection.InjectionMatrix.inject(InjectionMatrix.java:45) 
at com.sap.engine.services.ejb3.runtime.impl.Interceptors_DependencyInjection.invoke(Interceptors_DependencyInjection.java:22) 
... 98 more 
Caused by: java.lang.RuntimeException: The persistence unit is inconsistent with the database schema:
Error on attribute >>com.wipro.TestTableOne.column4<<: The column >>Test_Table_One.COLUMN4<< does not exist.
Error on attribute >>com.wipro.TestTableOne.column3<<: The column >>Test_Table_One.COLUMN3<< does not exist.
Error on attribute >>com.wipro.TestTableOne$PK.column2<<: The column >>Test_Table_One.COLUMN2<< does not exist.
Error on attribute >>com.wipro.TestTableOne$PK.column1<<: The column >>Test_Table_One.COLUMN1<< does not exist.

Are there any dependencies I need to add when using a Composite key. I havent found much documentation regarding this.

Thanks Brian

Former Member
0 Kudos

Hi, Brian,

I think the problem is in your object model - it is inconsistent with the database schema you are using:

>

> Error on attribute >>com.wipro.TestTableOne.column4<<: The column >>Test_Table_One.COLUMN4<< does not exist.

> Error on attribute >>com.wipro.TestTableOne.column3<<: The column >>Test_Table_One.COLUMN3<< does not exist.

> Error on attribute >>com.wipro.TestTableOne$PK.column2<<: The column >>Test_Table_One.COLUMN2<< does not exist.

> Error on attribute >>com.wipro.TestTableOne$PK.column1<<: The column >>Test_Table_One.COLUMN1<< does not exist.

>

That is, you have defined these four columns as fields of your entity, but the columns do not exist physically in the database table you are using.

You can fix this by either using forward mapping or by creating these columns manually.

More information:

...about the forward mapping: http://help.sap.com/saphelp_nwce10/helpdata/en/46/8b38425f9c6be3e10000000a155369/frameset.htm

...about creating tables using Java Dictionary: http://help.sap.com/saphelp_nwce10/helpdata/en/87/773a55f35a65409009e87261c84eb2/frameset.htm

...about creating tables on a native database: http://help.sap.com/saphelp_nwce10/helpdata/en/45/07cec7ea3e0485e10000000a155369/frameset.htm

Note, that creating tables on a native database usually depends on the database vendor specifics, so it is recommended that you use the database specific tools described in the relevant database documentation.

I hope that helps!

Regards,

Yordan

Former Member
0 Kudos

Hi Yordan,

I have already created the tables in my database.

I am performing the same operations as I have successfully done, the only difference being that now the Priamry Key is made up of 2 fields.

I am also using the NetWeaver capability, JPA Tools > Generate Entities, to generate Entities from the tables in the underlying database.

This is what causes the problem for me. So I am not sure if the steps performed for the single Column Primary key is sufficien, hence I want to know if there are any additional dependencies to be added in case of a Composite Primary Key.

Thanks

--- Brian

adrian_goerler
Active Participant
0 Kudos

Hi Brian,

could you please point the source of your entity as well as the definition of your database tables?

-Adrian

Answers (3)

Answers (3)

Former Member
0 Kudos

Problem with Composite Key

Former Member
0 Kudos

Hi Brian

I'm having the same issue as you, and was wondering whether you could let me know what the dependencies were that you added to resolve the issue?

Would greatly appreciate your help on this, as I think I've tried all the options you tried (literally went through every suggestion made in this thread without any luck).

Thanks

Stuart

Former Member
0 Kudos

Hi Stuart,

Dont worry , even I went through the same phase...

So lets keep the approach simple.

Create an EJB module, within that an EJB EJBsource(stateless Session Bean). One EAR moduleEARsource.

Now suppose that our client is a Composite Application(as in my case,with a Stateless Session BeanEJBclient and an EAR moduleEARclient).

To add the dependencies:

1) To add the design time dependency --> simply add the EJBsource as a dependency for the EJBclient.........So now u would see the Entities in your client for coding.

Now for run time dependency

Done in Development Infrastructure Perspective

2)In the EJBsource and in the permissions tab, select MyComponents for Entity Forwarding.

3)In the EARsource add a new Public Part, and Reference entities --> client of the EJBsource

4)Finally now add this EARsource as a dependency to the EARclient.

Thats it ............Reward points if useful

If you face any more difficulty, you can reply back.

HTH ..

cheers

--- Brian.

Former Member
0 Kudos

--