on 10-29-2007 7:12 PM
hello:)
looked through forums of all kind, but found nothing!
1. I downloaded SAPNW CE7.1 SP1 J2EE only.
2. Deleveloped WD Application, works perfectly.
3. Wanted to test JPA -> getting the same error over and over again....
=> No Persistence provider for EntityManager named XXX
What I did so far:
<b>3.1 DB connection to MAXDB created: </b>
Server: CE1
Scheme: SUPERDBA
User: superdba
Password: ****
<b>3.2 Entities created, only one:)</b>
<b>3.3 Java Persistence added to the project.</b>
<b>3.4 persistence.xml created:</b>
<?xml version="1.0" encoding="UTF-8"?>
<persistence>
<persistence-unit name="foo">
<provider>javax.persistence.spi.PersistenceProvider</provider>
<jta-data-source>superdba_test</jta-data-source>
<class>mycom.demo.entities.WelcomeTest</class>
<properties>
<property
name="com.sap.engine.services.orpersistence.generator.versio
ntablename" value="WELCOME_VERSIONGEN" />
</properties>
</persistence-unit>
</persistence>
<b>3.5 data-sources.xml created like this:</b>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE data-sources SYSTEM "data-sources.dtd" >
<data-sources>
<data-source>
<data-source-name>superdba</data-source-name>
<driver-name>SYSTEM_DRIVER</driver-name>
<!--<sql-engine>native_sql</sql-engine>-->
<sql-engine>vendor_sql</sql-engine>
<jdbc-1.x>
<driver-class-name>com.sap.dbtech.jdbc.DriverSapDB</driver-class-name>
<url>jdbc:sapdb://mungo01/CE1</url>
<user-name>superdba</user-name>
<password>****</password>
</jdbc-1.x>
</data-source>
</data-sources>
<b>3.6 data-source-aliases.xml created</b>
<?xml version="1.0" encoding="UTF-8"?>
<data-source-aliases>
<aliases>
<data-source-name>superdba</data-source-name>
<alias>superdba_test</alias>
</aliases>
</data-source-aliases>
<b>3.7 Execution of Persistence:</b>
...
StringBuffer queryTxt = new StringBuffer("SELECT * FROM WelcomeTest");
EntityManager em = null;
EntityManagerFactory emf = Persistence.createEntityManagerFactory("foo");
em = emf.createEntityManager();
Query query = em.createQuery(queryTxt.toString());
...
I am desperate at this point. So any ideas are more than welcome!:)
best regards
simon:)
Hi Simon,
you are not using EJBs: this is the reason that the annotations doesnt work. The specification of EJB 3 says that they must be supported in EJB container and Web Container. WD is not a standard container, its a proprietary one.
I think that the persistence.xml, data-sources.xml and data-source-aliases.xml descriptors are ignored by the WD container. Why do you not separate the persistence layer and the presentation layer?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello all again:)
thanks for all answers so far, unfortunately I couldn't solve my problem.
I did try it with EJB also.
I created WEB, EJB, EAR projects, persistence.xml,
I created 'my_data_source' in "SAP NetWeaver Administration"
and this son of a gun still says:
<b>No Persistence provider for EntityManager named </b>
I would really appreciate, someone helped me with this one. It's got to be possible.
How can I actually make sure, that he read my persistence.xml file, hmm? And if he read it, why does the Persistence cannot create a factory??
regards
simon
well I tried to debug the
<b>Persistence.createEntityManagerFactory("...");</b>
and on some point he tried to load
<b>META-INF/services/javax.persistance.spi....</b>
which is a bit strange. Can this be a reason why the exception is thrown??
Because, I have nothing else in META-INF beside persistence.xml
best regards
simon:)
Hi Simon,
Please make sure that you have removed the <provider> tag from the persistence.xml.
You might also remove the <class> tag from the persistence.xml as the classes are detected automatically.
I do also suggest that you use JPA inside an EJB module and use dependency injection to have the entity manager injected into a session bean.
@Stateless
public class MySessionBean implements MyBusinessInterface {
@PersistenceContext(unitName="foo")
EntityManager em;
....
This is the cleanest easiest approach. You may also have an entity manager factory injected but then, your application has to control the lifecycle of the entity manager. I am not sure this is what you want to do.
If you don't like dependency injection, you may also look up the entity manager or the entity manager factory in JNDI. But dependency injection is simpler.
I discourage you from obtaining an entity manager through Persistence.createEntityManagerFactory. This is for standalone usage only. You would have to package the SAP JPA implementation with your application to get this running. This is not what you want to do.
Your data-sources.xml and data-source-aliases.xml look fine to me.
Still injection of an entity manager might fail for various reasons. If it doesn't work, please have a look at the engine traces under
...\j2ee\cluster\server0\log\defaultTrace*trc
I hope this gets you further.
Regards,
Adrian
hello Adrian,
well, this solved my problem!!!:) I'm SOOOO grateful:) It was so obvious, stupid me;)
The whole time I was tapping around it. I obtained the
<b>EntityManager</b>
with the annotation like you said without creating the factory with
<b>Persistence.createEntityManagerFactory</b>.
I have already done this before, but i've always used emf anywhere, stupid, isn't it.
As far as the data-sources.xml and data-source-aliases.xml are concerned, it seems, that they are not needed since I create the data source in NW Administrator. Is that right?
So to review the steps that I've done:
1. Created EJB, EAR, WEB projects.
2. in EJB created src/META-INF/persistence.xml
<?xml version="1.0" encoding="UTF-8"?>
<persistence>
<persistence-unit name="foo">
<jta-data-source>my_data_source</jta-data-source>
<class>com.sap.tutorial.javaee.WelcomeTest</class>
</persistence-unit>
</persistence>
3. in EJB created Bean:
@Stateless
public class BeanTest implements BeanLocal {
@PersistenceContext(unitName="foo")
EntityManager em;
public void test() {
EntityTest test = new EntityTest();
test.setUname("SAPFOO");
test.setName("FooName");
em.persist(test);
}
}
4. I invoke test method form
index.jsp
in the WEB part.
5. in SAP NW Administrator under
Operation Management->Systems->Start & Stop: Java EE Applications->Start & Stop: Java EE Applications
created
my_data_source
as
JDBC Custom DataSource
SYSTEM_DRIVER
native SQL
Driver Class Name: com.sap.dbtech.jdbc.DriverSapDB
Database Url: jdbc:sapdb://<host>/CE1
User Name: superdba
Password: *******
6. i used MaxDB as a database and NW CE 7.1 SP1 as a server.
so thanks again Adrian:) and best regards
simon:)
Hi Simon,
you should remove the <provider> tag from the persistence.xml.
The SAP JPA-persistence provider is chosen by default. With the provider-tag, you could advise the JPA container to use an alternative persistence provider (i.e. JPA implementation) which would have to be bundled with the application. Moreover, "javax.persistence.spi.PersistenceProvider" is just an abstract interface and hence cannot be loaded.
I hope this gets you further.
Best regards,
Adrian
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Simon,
I have a question about the 3.7 point: Are this code executed from EJB container? If this is true, why dont use dependency injection in order to inject the EntityManager.
Do you have taken a look into the log viewer?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello, Simon!
Concerning the Java EE environment, I think it would be a better idea if you obtain the Entity Manager instance by means of dependency injection:
@PersistenceUnit
EntityManagerFactory emf;
EntityManager em = emf.createEntityManager();
You can have a look at the official documentation for NW CE 7.1 SP1 on the SAP help portal:
http://help.sap.com/saphelp_nwce10/helpdata/en/45/0029b3515224dee10000000a114a6b/frameset.htm
P.S. I am not certain if this is the exact problem that threw you into despair but I think that the way you initiated the Entity Manager is (more) relevant for Java SE environment.
Hope this helps!
Regards,
Yordan
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello:)
Thanks:) already tried that and I got NullPointerException.
That is why I have the strange feeling, that the anntotations are beeing ignored, or never parsed at all. And that my XML ffiles(persistence.xml, data-sources.xml, data-source-aliases.xml) are also beeing ignored, even if everything is beeing built into the output folder - <b>.../bin (from Java Build Path) </b>.
Another option would be, the XML files are never deployed(even if built) to
<b>C:\usr\sap\CE1\J01\j2ee\cluster\server0\temp\deploy\work\deploying</b>
Any suggesions on this one?
Right now I am trying to find out wether the XMLs are beeing read at all, and wether annotations are beeing parsed on runtime?
But still, any suggestions/experiences on tis topic generally would be great.
best regards
simon:)
User | Count |
---|---|
98 | |
11 | |
11 | |
10 | |
10 | |
8 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.