# JPA - Problem mit Persistence Unit / Context



## megachucky (11. Feb 2009)

Ich probier jetzt schon ewig rum, finde leider den Fehler nicht. Hab schon etliche Kombinationen probiert, aber es klappt einfach nicht.

Ich habe eine EJB, die den Entity Manager nutzen soll, um ein Entity zu persistieren. 

Soweit ich es bei der Fehlermeldung und Google richtig verstehe liegt das Problem irgendwo in der Kombination aus web.xml, persistence.xml und EJB. Irgendein unitname oder sowas passt nicht ?!?

Die ganze App wird dann nicht deployt.

Ich hoffe jemand kann mir helfen, vielen Dank.



Anbei Fehlermeldung und relevanter Code:


```
[#|2009-02-11T17:04:40.015+0100|SEVERE|sun-appserver9.1|javax.enterprise.system.tools.deployment|_ThreadID=15;_ThreadName=Timer-7;_RequestID=9bf8090b-95cb-4dc6-80b8-e36447887f85;|Exception occured in J2EEC Phase
com.sun.enterprise.deployment.backend.IASDeploymentException: Deployment Error -- Could not resolve a persistence unit corresponding to the persistence-context-ref-name [de.jsf.model.StoreUserData/em] in the scope of the module called [C:\Program Files\glassfish\domains\domain1\applications\j2ee-modules\jsf]. Please verify your application.
	at com.sun.enterprise.deployment.BundleDescriptor.findReferencedPUsViaPCRefs(BundleDescriptor.java:702)
	at com.sun.enterprise.deployment.WebBundleDescriptor.findReferencedPUs(WebBundleDescriptor.java:722)
	at com.sun.jdo.spi.persistence.support.ejb.ejbc.PersistenceProcessor.getAllPersistenceUnitDescriptors(PersistenceProcessor.java:171)
	at com.sun.jdo.spi.persistence.support.ejb.ejbc.PersistenceProcessor.processApplication(PersistenceProcessor.java:132)
	at com.sun.jdo.spi.persistence.support.ejb.ejbc.DeploymentEventListenerImpl.processApplication(DeploymentEventListenerImpl.java:211)
	at com.sun.jdo.spi.persistence.support.ejb.ejbc.DeploymentEventListenerImpl.processEvent(DeploymentEventListenerImpl.java:172)
	at com.sun.jdo.spi.persistence.support.ejb.ejbc.DeploymentEventListenerImpl.notifyDeploymentEvent(DeploymentEventListenerImpl.java:122)
	at com.sun.enterprise.deployment.backend.DeploymentEventManager.notifyDeploymentEvent(DeploymentEventManager.java:79)
	at com.sun.enterprise.deployment.backend.ModuleDeployer.handlePostDeployEvent(ModuleDeployer.java:636)
	at com.sun.enterprise.deployment.backend.ModuleDeployer.postDeploy(ModuleDeployer.java:625)
	at com.sun.enterprise.deployment.backend.ModuleDeployer.doRequestFinish(ModuleDeployer.java:188)
	at com.sun.enterprise.deployment.phasing.J2EECPhase.runPhase(J2EECPhase.java:191)
	at com.sun.enterprise.deployment.phasing.DeploymentPhase.executePhase(DeploymentPhase.java:108)
	at com.sun.enterprise.deployment.phasing.PEDeploymentService.executePhases(PEDeploymentService.java:919)
	at com.sun.enterprise.deployment.phasing.PEDeploymentService.deploy(PEDeploymentService.java:276)
	at com.sun.enterprise.deployment.phasing.PEDeploymentService.deploy(PEDeploymentService.java:294)
	at com.sun.enterprise.admin.mbeans.ApplicationsConfigMBean.deploy(ApplicationsConfigMBean.java:555)
	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:597)
	at com.sun.enterprise.admin.MBeanHelper.invokeOperationInBean(MBeanHelper.java:375)
	at com.sun.enterprise.admin.MBeanHelper.invokeOperationInBean(MBeanHelper.java:358)
	at com.sun.enterprise.admin.config.BaseConfigMBean.invoke(BaseConfigMBean.java:464)
	at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.java:836)
	at com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:761)
	at sun.reflect.GeneratedMethodAccessor13.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:597)
	at com.sun.enterprise.admin.util.proxy.ProxyClass.invoke(ProxyClass.java:90)
	at $Proxy1.invoke(Unknown Source)
	at com.sun.enterprise.admin.server.core.jmx.SunoneInterceptor.invoke(SunoneInterceptor.java:304)
	at com.sun.enterprise.interceptor.DynamicInterceptor.invoke(DynamicInterceptor.java:174)
	at com.sun.enterprise.deployment.autodeploy.AutoDeployer.invokeDeploymentService(AutoDeployer.java:564)
	at com.sun.enterprise.deployment.autodeploy.AutoDeployer.deployJavaEEArchive(AutoDeployer.java:545)
	at com.sun.enterprise.deployment.autodeploy.AutoDeployer.deploy(AutoDeployer.java:492)
	at com.sun.enterprise.deployment.autodeploy.AutoDeployer.deployAll(AutoDeployer.java:267)
	at com.sun.enterprise.deployment.autodeploy.AutoDeployControllerImpl$AutoDeployTask.run(AutoDeployControllerImpl.java:374)
	at java.util.TimerThread.mainLoop(Timer.java:512)
	at java.util.TimerThread.run(Timer.java:462)
```
@Entity(name="userdata")
public class UserDataEntity implements Serializable {

	private static final long serialVersionUID = 1L;

	private int id;
	private String firstName;
	private String lastName;
	private String email;

	@Id
	public int getId() {
		return id;
	}
	public void setId(int id) {
		this.id = id;
	}
........

```
@Stateless
public class StoreUserData implements StoreUserDataIF {
	
	@PersistenceContext(unitName="unitname")
	private EntityManager em;
	
	
	public void storeUserData(String firstName, String lastName, String email) {
		UserDataEntity user = new UserDataEntity();
		user.setFirstName(firstName);
		user.setLastName(lastName);
		user.setEmail(email);
		
		em.persist(user);
		
	}
........
```


```
<?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="unitname">
	
		<jta-data-source>jdbc/EJBandJPA</jta-data-source>
		
		<properties>
			<!--
			see [url]http://www.oracle.com/technology/products/ias/toplink/jpa/resources/toplink-jpa-extensions.html#Java2DBSchemaGen[/url]
			-->
			<property name=" toplink.platform.class.name"
              value="oracle.toplink.essentials.platform.database.DerbyPlatform"/>
        </properties>

	</persistence-unit>

</persistence>
```


```
<web-app>
........


 <persistence-context-ref>
  
          <persistence-context-ref-name>em</persistence-context-ref-name>
   
          <persistence-unit-name>unitname</persistence-unit-name>
   
 </persistence-context-ref>     


	
</web-app>
```


----------



## Gelöschtes Mitglied 5909 (19. Feb 2009)

da is ne beispiel persistence.xml

http://www.oracle.com/technology/products/ias/toplink/JPA/essentials/toplink-jpa-extensions.html


----------

