Topic
1 reply Latest Post - ‏2013-03-25T20:26:08Z by SystemAdmin
SystemAdmin
SystemAdmin
590 Posts
ACCEPTED ANSWER

Pinned topic Getting started with Liberty Profile JPA issue

‏2013-03-20T10:25:46Z |
Hello!

I closely followed your tutorial posted here https://www.ibm.com/developerworks/mydeveloperworks/blogs/wasdev/entry/getting_started_with_the_was_liberty_profile?lang=en - the Derby version and everything worked like a charm. I have a question though concerning the choice of architecture.
Why the class DBInteractions has to be a servlet? Can't it just be annotated with the @Resource annotation? The EntityManagerFactory is given as a parameter to the createTable() method so it is not instantiated in DBInteractions.

So I tried to modify the code so that the DBInteractions is not a servlet (I erased the @WebServlet annotation) and I run up into an exception at the creation of the Entity Manager that tells me to define a datasource or a jdbc driver.
The exact line of the exception is:
EntityManager em = emf.createEntityManager();

I still have my DBInteractions class annotated with:
@Resource(name = "jdbc/DerbyConnection", type = javax.sql.DataSource.class, shareable =true, authenticationType = AuthenticationType.CONTAINER)
Therefore I have defined a data source. The exact exception message bellow. Any idea about the exception?
ERROR SRVE0777E: Exception thrown by application class 'org.apache.openjpa.jdbc.schema.DataSourceFactory.newDataSource():72'
<openjpa-2.2.1-SNAPSHOT-r422266:1363644 fatal user error> org.apache.openjpa.persistence.ArgumentException: Un nom de classe de source de donn‚es ou de pilote JDBC doit ˆtre d‚fini dans la propri‚t‚ ConnectionDriverName. Les propri‚t‚s disponibles dans la configuration sont : "WsJpaJDBCConfigurationImpl@3bfa3bfa: PDQ disabled: AccessIntent Task=disable".
at org.apache.openjpa.jdbc.schema.DataSourceFactory.newDataSource(DataSourceFactory.java:72)
at org.apache.openjpa.jdbc.conf.JDBCConfigurationImpl.createConnectionFactory(JDBCConfigurationImpl.java:844)
at org.apache.openjpa.jdbc.conf.JDBCConfigurationImpl.getDBDictionaryInstance(JDBCConfigurationImpl.java:602)
at org.apache.openjpa.jdbc.meta.MappingRepository.endConfiguration(MappingRepository.java:1510)
at org.apache.openjpa.lib.conf.Configurations.configureInstance(Configurations.java:518)
at org.apache.openjpa.lib.conf.Configurations.configureInstance(Configurations.java:443)
at org.apache.openjpa.lib.conf.PluginValue.instantiate(PluginValue.java:104)
at org.apache.openjpa.conf.MetaDataRepositoryValue.instantiate(MetaDataRepositoryValue.java:68)
at org.apache.openjpa.lib.conf.ObjectValue.instantiate(ObjectValue.java:83)
at org.apache.openjpa.conf.OpenJPAConfigurationImpl.newMetaDataRepositoryInstance(OpenJPAConfigurationImpl.java:967)
at org.apache.openjpa.conf.OpenJPAConfigurationImpl.getMetaDataRepositoryInstance(OpenJPAConfigurationImpl.java:958)

AND in English
org.apache.openjpa.persistence.ArgumentException: A JDBC Driver or DataSource class name must be specified in the ConnectionDriverName property.
at org.apache.openjpa.jdbc.schema.DataSourceFactory.newDataSource(DataSourceFactory.java:72)
at org.apache.openjpa.jdbc.conf.JDBCConfigurationImpl.createConnectionFactory(JDBCConfigurationImpl.java:776)
at org.apache.openjpa.jdbc.conf.JDBCConfigurationImpl.getDBDictionaryInstance(JDBCConfigurationImpl.java:553)
at org.apache.openjpa.jdbc.meta.MappingRepository.endConfiguration(MappingRepository.java:1250)
at org.apache.openjpa.lib.conf.Configurations.configureInstance(Configurations.java:505)
at org.apache.openjpa.lib.conf.Configurations.configureInstance(Configurations.java:430)
at org.apache.openjpa.lib.conf.PluginValue.instantiate(PluginValue.java:103)
at org.apache.openjpa.conf.MetaDataRepositoryValue.instantiate(MetaDataRepositoryValue.java:68)
at org.apache.openjpa.lib.conf.ObjectValue.instantiate(ObjectValue.java:83)
at org.apache.openjpa.conf.OpenJPAConfigurationImpl.newMetaDataRepositoryInstance(OpenJPAConfigurationImpl.java:843)
at org.apache.openjpa.conf.OpenJPAConfigurationImpl.getMetaDataRepositoryInstance(OpenJPAConfigurationImpl.java:834)
  • SystemAdmin
    SystemAdmin
    590 Posts
    ACCEPTED ANSWER

    Re: Getting started with Liberty Profile JPA issue

    ‏2013-03-25T20:26:08Z  in response to SystemAdmin
    Hi,
    The Java™ Platform, Enterprise Edition (Java EE) Specification, v6, in section EE 5.2.5 - Annotations and Injections, mentions that resource injection works on container-managed component classes, and includes a list of those components, and servlets are included.

    If you just removed the @WebServlet annotation, and your class is a simple POJO, then is likely that the @Resource annotation is not working and that's why you are getting this error.

    Hope this helps.