[JBoss Seam] - persistence.xml and TestNG
by damianharvey
I'm sure I'm being an idiot on this, but I'm trying to get a unit test working with an EntityManagerFactory (as per the Seam reference) but I can't get it to find my persistence.xml.
The error I am getting is:
INFO 29-10 12:13:49,503 [org.hibernate.ejb.Version.<clinit>():15] Hibernate EntityManager 3.2.0.GA
| INFO 29-10 12:13:49,524 [org.hibernate.cfg.annotations.Version.<clinit>():15] Hibernate Annotations 3.2.0.GA
| INFO 29-10 12:13:49,534 [org.hibernate.cfg.Environment.<clinit>():500] Hibernate 3.2.1
| INFO 29-10 12:13:49,541 [org.hibernate.cfg.Environment.<clinit>():533] hibernate.properties not found
| INFO 29-10 12:13:49,543 [org.hibernate.cfg.Environment.buildBytecodeProvider():667] Bytecode provider name : cglib
| INFO 29-10 12:13:49,549 [org.hibernate.cfg.Environment.<clinit>():584] using JDK 1.4 java.sql.Timestamp handling
| INFO 29-10 12:13:49,632 [org.hibernate.ejb.Ejb3Configuration.configure():202] Could not find any META-INF/persistence.xml file in the classpath
| WARN 29-10 12:13:49,679 [org.hibernate.connection.UserSuppliedConnectionProvider.configure():23] No connection properties specified - the user must supply JDBC connections
| FAILED CONFIGURATION: @BeforeTest init
| javax.persistence.PersistenceException: org.hibernate.HibernateException: Hibernate Dialect must be explicitly set
| at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:698)
| at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:121)
| at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:51)
| at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:33)
| at com.locuslive.odyssey.test.TestUnLocodeList.init(TestUnLocodeList.java:36)
| Caused by: org.hibernate.HibernateException: Hibernate Dialect must be explicitly set
| at org.hibernate.dialect.DialectFactory.determineDialect(DialectFactory.java:57)
| at org.hibernate.dialect.DialectFactory.buildDialect(DialectFactory.java:39)
| at org.hibernate.cfg.SettingsFactory.determineDialect(SettingsFactory.java:409)
| at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:119)
| at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:2006)
| at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1289)
| at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:691)
| ... 23 more
It's a standard Seam Gen'd project with 3 persistence.xmls (dev, test, prod) in the resources/META-INF directory. I've added the 4 test jars (lib/test/jboss-embedded-all.jar, lib/test/hibernate-all.jar, lib/test/thirdparty-all.jar and lib/test/jboss-deployers.jar) to the top of the TestNG User classpath.
I've seen in some other posts that people have had success moving the persistence.xml file around. This hasn't worked for me.
My persistence.xml looks like this:
| <?xml version="1.0" encoding="UTF-8"?>
| <!-- Persistence deployment descriptor for dev profile -->
| <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="Odyssey0.5.0">
| <provider>org.hibernate.ejb.HibernatePersistence</provider>
| <jta-data-source>java:/Odyssey0.5.0Datasource</jta-data-source>
| <properties>
| <property name="hibernate.hbm2ddl.auto" value="validate"/>
| <property name="hibernate.cache.use_query_cache" value="true"/>
| <property name="hibernate.show_sql" value="true"/>
| <property name="jboss.entity.manager.factory.jndi.name" value="java:/Odyssey0.5.0EntityManagerFactory"/>
| </properties>
| </persistence-unit>
| </persistence>
|
Can anyone suggest a solution? Am I missing something obvious?
Thanks,
Damian.
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4099818#4099818
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4099818
18Â years, 6Â months
[JNDI/Naming/Network] - Missing EJB 3.0 Session bean name in Global JNDI Namespace!!
by benix
I have created an ear ?SampleEnterprise.ear? which consists of an ejb jar ?SampleEnterprise-ejb.jar? and a war file ?SampleEnterprise-war.war?. The ear file was deployed on a JBoss 4.0.5 server.
There is a EJB 3.0 stateless session bean ?EmployeeServiceBean? present in the ejb jar file which I need to access from a servlet ?EmployeeServlet? in the war file
Here?s the code from the servlet used to lookup the session bean
| try {
| Properties properties = new Properties();
| properties.put("java.naming.factory.initial","org.jnp.interfaces.NamingContextFactory");
| properties.put("java.naming.factory.url.pkgs","=org.jboss.naming:org.jnp.interfaces");
| properties.put("java.naming.provider.url","localhost:1099");
| Context context = new InitialContext(properties);
| EmployeeServiceRemote empService = (EmployeeServiceRemote)context.lookup("SampleEnterprise/EmployeeServiceBean/remote");
| } catch (Exception e) {}
|
Here's the session bean
| package sessionBeans;
| import entityBeans.Employee;
| import javax.ejb.Stateless;
| import javax.persistence.EntityManager;
| import javax.persistence.PersistenceContext;
|
| @Stateless()
| public class EmployeeServiceBean implements EmployeeServiceLocal, EmployeeServiceRemote {
|
| @PersistenceContext()
| EntityManager em;
|
| public EmployeeServiceBean() {}
|
| public Employee createEmployee(int id, String name, int salary) {
| Employee emp = new Employee(id);
| emp.setName(name);
| emp.setSalary(salary);
| em.persist(emp);
| return emp;
| }
|
here's the JndiView
| Global JNDI Namespace
|
| +- TopicConnectionFactory (class: org.jboss.naming.LinkRefPair)
| +- jmx (class: org.jnp.interfaces.NamingContext)
| | +- invoker (class: org.jnp.interfaces.NamingContext)
| | | +- RMIAdaptor (proxy: $Proxy42 implements interface org.jboss.jmx.adaptor.rmi.RMIAdaptor,interface org.jboss.jmx.adaptor.rmi.RMIAdaptorExt)
| | +- rmi (class: org.jnp.interfaces.NamingContext)
| | | +- RMIAdaptor[link -> jmx/invoker/RMIAdaptor] (class: javax.naming.LinkRef)
| +- HTTPXAConnectionFactory (class: org.jboss.mq.SpyXAConnectionFactory)
| +- ConnectionFactory (class: org.jboss.mq.SpyConnectionFactory)
| +- UserTransactionSessionFactory (proxy: $Proxy12 implements interface org.jboss.tm.usertx.interfaces.UserTransactionSessionFactory)
| +- HTTPConnectionFactory (class: org.jboss.mq.SpyConnectionFactory)
| +- XAConnectionFactory (class: org.jboss.mq.SpyXAConnectionFactory)
| +- UserTransaction (class: org.jboss.tm.usertx.client.ClientUserTransaction)
| +- UILXAConnectionFactory[link -> XAConnectionFactory] (class: javax.naming.LinkRef)
| +- UIL2XAConnectionFactory[link -> XAConnectionFactory] (class: javax.naming.LinkRef)
| +- queue (class: org.jnp.interfaces.NamingContext)
| | +- A (class: org.jboss.mq.SpyQueue)
| | +- testQueue (class: org.jboss.mq.SpyQueue)
| | +- ex (class: org.jboss.mq.SpyQueue)
| | +- DLQ (class: org.jboss.mq.SpyQueue)
| | +- D (class: org.jboss.mq.SpyQueue)
| | +- C (class: org.jboss.mq.SpyQueue)
| | +- B (class: org.jboss.mq.SpyQueue)
| +- topic (class: org.jnp.interfaces.NamingContext)
| | +- testDurableTopic (class: org.jboss.mq.SpyTopic)
| | +- testTopic (class: org.jboss.mq.SpyTopic)
| | +- securedTopic (class: org.jboss.mq.SpyTopic)
| +- console (class: org.jnp.interfaces.NamingContext)
| | +- PluginManager (proxy: $Proxy43 implements interface org.jboss.console.manager.PluginManagerMBean)
| +- UIL2ConnectionFactory[link -> ConnectionFactory] (class: javax.naming.LinkRef)
| +- HiLoKeyGeneratorFactory (class: org.jboss.ejb.plugins.keygenerator.hilo.HiLoKeyGeneratorFactory)
| +- UILConnectionFactory[link -> ConnectionFactory] (class: javax.naming.LinkRef)
| +- QueueConnectionFactory (class: org.jboss.naming.LinkRefPair)
| +- UUIDKeyGeneratorFactory (class: org.jboss.ejb.plugins.keygenerator.uuid.UUIDKeyGeneratorFactory)
|
however the EmployeeServiceBean does not appear in the above listing and I get the following exception when the lookup code is executed
javax.naming.NameNotFoundException: SampleEnterprise not bound
do i need to add any references to the session bean in the following files?
jboss-app.xml (is a <loader-repository> required?)
jboss.xml
jboss-web.xml
ejb-jar.xml
web.xml
or have i missed out something else?
there aren't any exceptions during deployment
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4099814#4099814
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4099814
18Â years, 6Â months