Hmm, jndi names work great so something might be wrong elsewhere. Would be great to identify it if thats true. Le 6 juin 2013 14:36, "Andrew Clarke" <[email protected]> a écrit :
> THANK YOU! This resolved my problem. I moved persistence.xml into > WEB-INF/classes/META-INF, and suddenly it all worked. It was a beautiful > moment. > > Thanks to all of you who responded. I'll provide some notes from my > experiences below in case anyone else reads this later. > > jta-data-source and non-jta-data-source both seem to get ignored by TomEE. > I experimented with using these, naming them randomly, and leaving them > out, and it made no difference. catalina.out showed that they got hooked > up regardless. Maybe this becomes important when one has more than one > datasource. > > I switched persistence.xml from JPA 1.0 to 2.0. Thanks for noticing, > whether or not it makes a difference. > > Yes I've set up Hibernate, in the main TomEE lib folder for now for > prototyping simplicity. > > Regarding bean names, I'm porting an existing site from JBoss to TomEE. > I'm trying to avoid having to change hard-coded JNDI names all over the > existing code. They're not centrally managed so I think switching them all > out if there's a better solution will possibly add more bugs. Plus, the > way I have things set up now it seems to be working. > > Thanks again, everyone. > - Andrew. > > On 2013-06-05, at 21:32, John D. Ament <[email protected]> wrote: > > > So, the root META-INF? > > What happens when it goes in WEB-INF/classes/META-INF ? > > > > > > On Wed, Jun 5, 2013 at 9:29 PM, Andrew Clarke <[email protected]> wrote: > > > >> Thanks again John. I'll include an example TestManagerBean.java below. > >> My persistence.xml is in my WAR file under /META-INF. > >> > >> package com.example; > >> > >> import com.example.account.Application; > >> import com.example.system.SystemPropertiesBean; > >> import org.apache.commons.logging.Log; > >> import org.apache.commons.logging.LogFactory; > >> import javax.ejb.EJB; > >> import javax.ejb.Local; > >> import javax.ejb.Remote; > >> import javax.ejb.Stateless; > >> import javax.persistence.*; > >> > >> @Stateless( name = "TestManager" ) > >> @Local( TestManager.class ) > >> @Remote( TestManagerRemote.class ) > >> public class TestManagerBean implements TestManager { > >> private static final Log logger = > >> LogFactory.getLog(TestManagerBean.class); > >> > >> @EJB(beanName = "AnotherEJBManager") > >> private AnotherEJBManager anotherEJBManager; > >> > >> @EJB(beanName = "SystemProperties") > >> private SystemPropertiesBean systemProperties; > >> > >> @PersistenceContext(unitName = "ExampleEngine") > >> private EntityManager entityManager; > >> > >> @PersistenceUnit(unitName = "ExampleEngine") > >> private EntityManagerFactory entityManagerFactory; > >> > >> public String passItBack(String inOut) { > >> logger.debug("TestManagerBean.inOut('" + inOut + "')"); > >> Application entity = entityManager.find(Application.class, > >> "8f466445ab"); > >> logger.debug("Entity: " + entity); > >> return anotherEJBManager.passItBack(inOut); > >> } > >> } > >> > >> > >> On 2013-06-05, at 20:43, "John D. Ament" <[email protected]> > wrote: > >> > >>> Hmm yeah I missed that part. > >>> > >>> So wait, is your persistence.xml in your war file somewhere? Where is > it? > >>> How do you get a reference to your entity manager? > >>> > >>> > >>> On Wed, Jun 5, 2013 at 8:39 PM, Andrew Clarke <[email protected]> wrote: > >>> > >>>> Yes I did, thanks. I did mention that in the email, but I know there > >> was > >>>> a lot in there. This was the syntax of my persistence.xml when I > tried > >>>> that: > >>>> > >>>> <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="ExampleEngine"> > >>>> <provider>org.hibernate.ejb.HibernatePersistence</provider> > >>>> <exclude-unlisted-classes>false</exclude-unlisted-classes> > >>>> > >>>> <properties> > >>>> <property name="hibernate.show_sql" value="true"/> > >>>> <property name="hibernate.format_sql" value="true"/> > >>>> <property name="hibernate.hbm2ddl.auto" value="update"/> > >>>> </properties> > >>>> </persistence-unit> > >>>> </persistence> > >>>> > >>>> - Andrew. > >>>> > >>>> On 2013-06-05, at 20:30, John D. Ament <[email protected]> > wrote: > >>>> > >>>>> Andrew, > >>>>> > >>>>> Did you try using the setting exclude-unlisted-classes, with the > value > >> of > >>>>> false? > >>>>> > >>>>> John > >>>>> > >>>>> > >>>>> On Wed, Jun 5, 2013 at 8:27 PM, Andrew Clarke <[email protected]> > wrote: > >>>>> > >>>>>> I've set up my database in TomEE such that it works fine with SQL > >> Query. > >>>>>> When I attempted to do a simple entityManager.find() as a JPA test, > I > >>>> got > >>>>>> the following error: > >>>>>> java.lang.RuntimeException: org.apache.cxf.interceptor.Fault: The > bean > >>>>>> encountered a non-application exception; nested exception is: > >>>>>> java.lang.IllegalArgumentException: Unknown entity: > >>>>>> com.example.account.Application > >>>>>> I've gotten around this by adding > >>>>>> <class>com.example.account.Application</class> to my persistence.xml > >>>> file. > >>>>>> However, in JBoss everything Just Works thanks to annotations and I > >>>> don't > >>>>>> need to use XML to set up my entities at all. On the one hand it's > a > >>>> bit > >>>>>> of a bummer to add in all that XML but I can handle it if I have to. > >>>> I'm > >>>>>> experiencing some other issues though so I'm wondering if there's a > >>>> bigger > >>>>>> configuration problem that I should address. > >>>>>> > >>>>>> I've also tried using > >>>>>> <exclude-unlisted-classes>false</exclude-unlisted-classes> and > >> <property > >>>>>> name="hibernate.archive.autodetection" value="class" /> but neither > of > >>>>>> these seems to have made a difference for me. > >>>>>> > >>>>>> Because of the custom JNDI naming system in my code, and to keep > >> things > >>>>>> simple, I've been slowly adding in files into > >>>> WEB-INF/classes/com/example. > >>>>>> I could package them into WEB-INF/lib/example.jar but then I think > I'd > >>>>>> have to rewrite a LOT of JNDI naming, and my (limited) understanding > >> is > >>>>>> that it's not necessary to package the classes into a JAR for any > >>>> reason. > >>>>>> > >>>>>> Here are some of my other files: > >>>>>> > >>>>>> persistence.xml: > >>>>>> > >>>>>> <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="ExampleEngine"> > >>>>>> <provider>org.hibernate.ejb.HibernatePersistence</provider> > >>>>>> <class>com.example.account.Application</class> > >>>>>> > >>>>>> <properties> > >>>>>> <property name="hibernate.show_sql" value="true"/> > >>>>>> <property name="hibernate.format_sql" value="true"/> > >>>>>> <property name="hibernate.hbm2ddl.auto" value="update"/> > >>>>>> </properties> > >>>>>> </persistence-unit> > >>>>>> </persistence> > >>>>>> > >>>>>> > >>>>>> tomee.xml: > >>>>>> > >>>>>> <?xml version="1.0" encoding="UTF-8"?> > >>>>>> <tomee> > >>>>>> <Resource id="example_db_prod" type="DataSource"> > >>>>>> JdbcDriver com.mysql.jdbc.Driver > >>>>>> JdbcUrl > >>>>>> jdbc:mysql://localhost:3306/example_db_prod?autoReconnect=true > >>>>>> UserName myusername > >>>>>> Password mypassword > >>>>>> validationQuery = SELECT 1 > >>>>>> JtaManaged true > >>>>>> </Resource> > >>>>>> </tomee> > >>>>>> > >>>>>> Thank you very much for any help you can provide. It's a very steep > >>>>>> learning curve trying to do this migration and I keep running into > >>>>>> roadblock after roadblock. > >>>>>> > >>>>>> - Andrew. > >>>> > >>>> > >> > >> > >
