# EntityMangerFactory



## Falko (16. Nov 2007)

Hallo, ich bin gerade dabei mich mit der Entwicklung von Web-Anwendungen zu beschäftigen. Ich habe ein Beispiel-Profekt, welches die JPA für die Datenbank Anbindung nutzt. Server ist JBoss 4.2 und Hibernate als OR Mapper.
Hab soweit alles zusammen, aber es kommt eine Exception, welche ich mir nicht erklären kann:

15:10:42,640 INFO  [config] Initializing Sun's JavaServer Faces implementation (1.2_04-b16-p02) for context '/PhoneExample'
15:10:42,734 INFO  [TomcatDeployer] deploy, ctxPath=/jmx-console, warUrl=.../deploy/jmx-console.war/
15:10:42,906 INFO  [Http11Protocol] Starting Coyote HTTP/1.1 on http-127.0.0.1-8080
15:10:42,937 INFO  [AjpProtocol] Starting Coyote AJP/1.3 on ajp-127.0.0.1-8009
15:10:42,937 INFO  [Server] JBoss (MX MicroKernel) [4.2.2.GA (build: SVNTag=JBoss_4_2_2_GA date=200710221139)] Started in 14s:172ms
15:10:45,218 ERROR [[Faces Servlet]] Servlet.service() for servlet Faces Servlet threw exception



java.lang.VerifyError: (class: org/hibernate/ejb/Ejb3Configuration, method: <clinit> signature: ()V) Bad type in putfield/putstatic
	at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:119)
	at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:51)
	at services.impl.ManagedUserBean.<init>(ManagedUserBean.java:38)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
	at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
	at java.lang.Class.newInstance0(Class.java:355)
	at java.lang.Class.newInstance(Class.java:308)
	at com.sun.faces.config.ManagedBeanFactoryImpl.newInstance(ManagedBeanFactoryImpl.java:277)
	at com.sun.faces.application.ApplicationAssociate.createAndMaybeStoreManagedBeans(ApplicationAssociate.java:527)
	at com.sun.faces.el.ManagedBeanELResolver.getValue(ManagedBeanELResolver.java:82)
	at javax.el.CompositeELResolver.getValue(CompositeELResolver.java:53)
	at com.sun.faces.el.FacesCompositeELResolver.getValue(FacesCompositeELResolver.java:64)
	at org.apache.el.parser.AstIdentifier.getValue(AstIdentifier.java:45)
	at org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:186)
	at com.sun.faces.config.ManagedBeanFactoryImpl.evaluateValueExpressionGet(ManagedBeanFactoryImpl.java:1003)
	at com.sun.faces.config.ManagedBeanFactoryImpl.setPropertiesIntoBean(ManagedBeanFactoryImpl.java:636)
	at com.sun.faces.config.ManagedBeanFactoryImpl.newInstance(ManagedBeanFactoryImpl.java:317)
	at com.sun.faces.application.ApplicationAssociate.createAndMaybeStoreManagedBeans(ApplicationAssociate.java:527)
	at com.sun.faces.el.ManagedBeanELResolver.getValue(ManagedBeanELResolver.java:82)
	at javax.el.CompositeELResolver.getValue(CompositeELResolver.java:53)
	at com.sun.faces.el.FacesCompositeELResolver.getValue(FacesCompositeELResolver.java:64)
	at org.apache.el.parser.AstIdentifier.getValue(AstIdentifier.java:45)
	at org.apache.el.parser.AstValue.getValue(AstValue.java:86)
	at org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:186)
	at org.apache.jasper.el.JspValueExpression.getValue(JspValueExpression.java:101)
	at javax.faces.component.UIData.getValue(UIData.java:582)
	at javax.faces.component.UIData.getDataModel(UIData.java:1063)
	at javax.faces.component.UIData.setRowIndex(UIData.java:417)
	at com.sun.faces.renderkit.html_basic.TableRenderer.encodeBegin(TableRenderer.java:85)
	at javax.faces.component.UIComponentBase.encodeBegin(UIComponentBase.java:788)
	at javax.faces.component.UIData.encodeBegin(UIData.java:879)
	at javax.faces.component.UIComponent.encodeAll(UIComponent.java:884)
	at javax.faces.render.Renderer.encodeChildren(Renderer.java:137)
	at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:812)
	at javax.faces.component.UIComponent.encodeAll(UIComponent.java:886)
	at javax.faces.component.UIComponent.encodeAll(UIComponent.java:892)
	at com.sun.faces.application.ViewHandlerImpl.doRenderView(ViewHandlerImpl.java:245)
	at com.sun.faces.application.ViewHandlerImpl.renderView(ViewHandlerImpl.java:176)
	at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:106)
	at com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:251)
	at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:144)
	at javax.faces.webapp.FacesServlet.service(FacesServlet.java:245)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
	at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230)
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
	at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:179)
	at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:84)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
	at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:157)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:262)
	at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
	at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
	at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:446)
	at java.lang.Thread.run(Thread.java:619)

Welcher Parameter soll da nicht stimmen? Der Aufruf der EntityManagerFactory:

    protected EntityManagerFactory emf2 = Persistence.createEntityManagerFactory("phoneexample", new HashMap());
    EntityManager em2 = emf2.createEntityManager();

Die Persistence-XML:

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="1.0" 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">

	<persistence-unit name="phoneexample" transaction-type="JTA">

	<class>model.User</class>
	<properties>
        <property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5InnoDBDialect" />        
        <property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver" />  
        <property name="hibernate.connection.username" value="root" />  
        <property name="hibernate.connection.password" value="root" />  
        <property name="hibernate.connection.url" value="jdbc:mysql://localhost:3306/test" /> 
	<property name="hibernate.show_sql" value="true"/>
        <property name="hibernate.hbm2ddl.auto" value="update" />  
        <property name="hibernate.cache.provider_class" value="org.hibernate.cache.EhCacheProvider" />  
	</properties>
        </persistence

Die Bezeichnungen stimmen ja überein... Hat jemand eine Idee woran es liegen könnte?


----------



## Guest (16. Nov 2007)

Provider fehlt. Das mit dem schliessenden Tag </persistence*>* ist ein Copy & Paste Fehler hier. Oder?
	
	
	
	





```
<persistence-unit name="phoneexample" transaction-type="JTA"> 
   <provider>org.hibernate.ejb.HibernatePersistence</provider>
   <class>model.User</class> 
   <properties> 
      <property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5InnoDBDialect" /> 
      <property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver" /> 
      <property name="hibernate.connection.username" value="root" /> 
      <property name="hibernate.connection.password" value="root" /> 
      <property name="hibernate.connection.url" value="jdbc:mysql://localhost:3306/test" /> 
      <property name="hibernate.show_sql" value="true"/> 
      <property name="hibernate.hbm2ddl.auto" value="update" /> 
      <property name="hibernate.cache.provider_class" value="org.hibernate.cache.EhCacheProvider" /> 
   </properties> 
</persistence>
```
Du kannst es auch über Datasources machen.
	
	
	
	





```
<persistence-unit name="phoneexample" transaction-type="JTA">
   <provider>org.hibernate.ejb.HibernatePersistence</provider>
   <jta-data-source>java:innodb_ds</jta-data-source>
   <properties>
      <property name="hibernate.archive.autodetection" value="class" />
      <property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5InnoDBDialect" /> 
      <property name="hibernate.show_sql" value="true" />
      <property name="hibernate.format_sql" value="false" />
      <property name="hibernate.use_sql_comments" value="false" />
   </properties>
</persistence-unit>
```
und die innodb-ds.xml (nach jboss-4.2.0.GA/server/default/deploy kopieren und den Treiber nach jboss-4.2.0.GA/server/default/lib)
	
	
	
	





```
<?xml version="1.0" encoding="UTF-8"?>
<datasources>
   <local-tx-datasource>
      <jndi-name>innodb_ds</jndi-name>
      <driver-class>com.mysql.jdbc.Driver</driver-class>
      <connection-url>jdbc:mysql://localhost:3306/test</connection-url>
      <user-name>root</user-name>
      <password>root</password>
      <metadata>
         <type-mapping>mySQL</type-mapping>
      </metadata>
      <exception-sorter-class-name>org.jboss.resource.adapter.jdbc.vendor.MySQLExceptionSorter</exception-sorter-class-name>
      <min-pool-size>1</min-pool-size>
      <max-pool-size>10</max-pool-size>
   </local-tx-datasource>
</datasources>
```


----------

