Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    Question regarding use of JPA data sources..

    So, I'm wondering a few things after studying the JPADS sample.. I'm currently getting errors like this when running my code :

    Code:
    === 2012-02-10 23:15:48,185 [l0-5] WARN  RequestContext - dsRequest.execute() failed: 
    javax.persistence.PersistenceException: Unable to initialize default EMF provider: com.isomorphic.jpa.EMFProviderLMT
    .
    .
    .
    Caused by: javax.persistence.PersistenceException: No Persistence provider for EntityManager named ds
    Currently my ds.xml files look like the following :

    Code:
    <DataSource 
    	ID="Organization" 
        serverConstructor="com.isomorphic.jpa.JPADataSource"
        beanClassName="com.mydomain.app.server.Organization"
    	>
    </DataSource>
    
    <DataSource 
    	ID="Address" 
        serverConstructor="com.isomorphic.jpa.JPADataSource"
        beanClassName="com.mydomain.app.server.Address"
    	>
     </DataSource>
    My Beans then look like the following (for example):

    Code:
    package com.mydomain.app.server;
    
    import java.io.Serializable;
    import java.util.Date;
    import java.util.List;
    import javax.persistence.Column;
    import javax.persistence.ElementCollection;
    import javax.persistence.Entity;
    import javax.persistence.GeneratedValue;
    import javax.persistence.GenerationType;
    import javax.persistence.Id;
    import javax.persistence.JoinColumn;
    import javax.persistence.ManyToOne;
    import javax.persistence.Table;
    
    @Entity
    @Table (name="Address")
    public class Address implements Serializable {
    
        @Id
        @Column (nullable = false)
        @GeneratedValue (strategy = GenerationType.IDENTITY)
        private Long addressId;
        
        @Column (nullable = false)
        private String address;
    
        @Column (nullable = false)
        private String city;
    
        @Column (nullable = false)
        private String state;
        
        @Column (nullable = false)
        private String zipcode;
    
        public Address() {
        }
    
        public Long getAddressId() {
            return addressId;
        }
    
        public void setAddressId(Long addressId) {
            this.addressId = addressId;
        }
    
        public String getAddress() {
            return address;
        }
    
        public void setAddress(String address) {
            this.address = address;
        }
    
        public String getCity() {
            return city;
        }
    
        public void setCity(String city) {
            this.city = city;
        }
    
        public String getState() {
            return state;
        }
    
        public void setState(String state) {
            this.state = state;
        }
    
        public String getZipcode() {
            return zipcode;
        }
    
        public void setZipcode(String zipcode) {
            this.zipcode = zipcode;
        }
    }
    
    package com.mydomain.app.server;
    
    import java.io.Serializable;
    import java.util.Date;
    import java.util.List;
    import javax.persistence.Column;
    import javax.persistence.ElementCollection;
    import javax.persistence.Entity;
    import javax.persistence.GeneratedValue;
    import javax.persistence.GenerationType;
    import javax.persistence.Id;
    import javax.persistence.JoinColumn;
    import javax.persistence.ManyToOne;
    import javax.persistence.OneToOne;
    import javax.persistence.Table;
    
    @Entity
    @Table (name="Organization")
    public class Organization implements Serializable {
    
        @Id
        @Column (nullable = false)
        @GeneratedValue (strategy = GenerationType.IDENTITY)
        private Long orgId;
        
        @Column(name = "ADDRESS_ID")
        private long addressId;
    
        @Column (nullable = false)
        private String organizationName;
    
        @Column (nullable = false)
        private String organizationPhone;
    
        @Column (nullable = false)
        private String adminName;
    
        @Column (nullable = false)
        private String adminPhone;
    
        @Column (nullable = false)
        private String adminEmail;    
    
        @OneToOne(optional=false)
        @JoinColumn(name = "addressId", referencedColumnName="addressId", nullable=false, insertable=true, updatable=true)
        private Address address;
    
        public Organization() {
        }       
    
        public Long getOrgId() {
            return orgId;
        }
    
        public void setOrgId(Long orgId) {
            this.orgId = orgId;
        }
    
        public long getAddressId() {
            return addressId;
        }
    
        public void setAddressId(long addressId) {
            this.addressId = addressId;
        }
    
        public String getOrganizationName() {
            return organizationName;
        }
    
        public void setOrganizationName(String organizationName) {
            this.organizationName = organizationName;
        }
    
        public String getOrganizationPhone() {
            return organizationPhone;
        }
    
        public void setOrganizationPhone(String organizationPhone) {
            this.organizationPhone = organizationPhone;
        }
    
        public String getAdminName() {
            return adminName;
        }
    
        public void setAdminName(String adminName) {
            this.adminName = adminName;
        }
    
        public String getAdminPhone() {
            return adminPhone;
        }
    
        public void setAdminPhone(String adminPhone) {
            this.adminPhone = adminPhone;
        }
    
        public String getAdminEmail() {
            return adminEmail;
        }
    
        public void setAdminEmail(String adminEmail) {
            this.adminEmail = adminEmail;
        }
    
        public Address getAddress() {
            return address;
        }
    
        public void setAddress(Address address) {
            this.address = address;
        }
    }
    Here's the persistence.xml file:
    Code:
    <?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="ds" transaction-type="RESOURCE_LOCAL">
        <provider>org.hibernate.ejb.HibernatePersistence</provider>
    
        <class>com.mydomain.app.server.Organization</class>
        <class>com.mydomain.app.server.Address</class>
    
        <exclude-unlisted-classes>true</exclude-unlisted-classes>
        <properties>
          <property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect"/>
          <property name="hibernate.connection.driver_class" value="org.postgresql.Driver"/>
          <property name="hibernate.connection.username" value="foo"/>
          <property name="hibernate.connection.password" value="bar"/>
          <property name="hibernate.connection.url" value="jdbc:postgresql://localhost/foobar"/>
    
          <property name="hibernate.show_sql" value="true"/>
          <property name="hibernate.format_sql" value="true"/>
          <property name="hibernate.max_fetch_depth" value="3"/>
          <property name="hibernate.hbm2ddl.auto" value="create-drop" />
        </properties>
      </persistence-unit>
    </persistence>
    Here's my server.properties file too..
    Code:
    webRoot: __AUTODETECT__
    
    # Set this to the GWT module name.
    gwtModuleName: mydomain
    
    isomorphicPathRootRelative: $gwtModuleName/sc
    
    # administration apps
    apps.adminConsole.location: $webRoot/$gwtModuleName/sc/tools
    ui.adminConsole.location: $webRoot/$gwtModuleName/sc/tools
                                                                  
    sql.defaultDatabase: PostgreSQL
    
    sql.PostgreSQL.autoJoinTransactions: true
    sql.PostgreSQL.interface.credentialsInURL: false
    sql.PostgreSQL.driver.context: _container_
    sql.PostgreSQL.driver.portNumber: 5432
    sql.PostgreSQL.driver: org.postgresql.Driver
    sql.PostgreSQL.driver.driverName: postgresql
    sql.PostgreSQL.driver.networkProtocol: tcp
    sql.PostgreSQL.interface.type: driverManager
    sql.PostgreSQL.database.type: postgresql
    sql.PostgreSQL.driver.name: PostgreSQL
    sql.PostgreSQL.driver.driverType: thin
    sql.PostgreSQL.driver.serverName: localhost
    sql.PostgreSQL.driver.databaseName: myscrip
    sql.PostgreSQL.driver.user: myscrip
    sql.PostgreSQL.driver.password: myscrip
    
    project.datasources: $webRoot/ds
    project.ui: $webRoot/shared/ui
    project.apps: $webRoot/shared/app
    
    sql.PostgreSQL.driver.url: 
    
    jpa.emfProvider: com.isomorphic.jpa.EMFProviderLMT  
    jpa.persistenceUnitName: ds  
      
    jpa.entityManager: persistence/em  
    jpa.entityManagerFactory: persistence/emf

    One thing I noticed that I'm doing differently than the JPADS example is that it's ds.xml files also carry the fields as well as in the respective "*.java" classes.. If I'm using the JPA flavor do I need to specify the fields in both sides (ds.xml + java) like the example? Is that what is causing my issues way above? Ideas?

    #2
    Anyone?? One more question that's related.. The first error I'm getting is claiming I'm using inheritsFrom: when I'm not -- I grepped my entire tree.. Why is this happening? I'm completely stumped..!!!

    Code:
    === 2012-02-11 22:24:33,434 [l0-3] WARN  JPA2DataSource - Failed to derive data source 'Address_inheritsFrom' for class com.mydomain.app.server.Address
    javax.persistence.PersistenceException: Unable to initialize default EMF provider: com.isomorphic.jpa.EMFProviderLMT
    	at com.isomorphic.jpa.EMF.initializeProvider(EMF.java:259)
    	at com.isomorphic.jpa.EMF.getProvider(EMF.java:243)
    	at com.isomorphic.jpa.EMF.getEntityManager(EMF.java:129)
    	at com.isomorphic.jpa.JPA2DataSource.deriveDS(JPA2DataSource.java:46)
    	at com.isomorphic.jpa.JPADataSource.init(JPADataSource.java:244)
    	at com.isomorphic.datasource.DataSource.initialize(DataSource.java:374)
    	at com.isomorphic.datasource.BasicDataSource.fromConfig(BasicDataSource.java:158)
    	at com.isomorphic.datasource.DataSource.fromConfig(DataSource.java:359)
    	at com.isomorphic.datasource.FileSystemDSRepo.loadDS(FileSystemDSRepo.java:110)
    	at com.isomorphic.datasource.DataSource.forName(DataSource.java:178)
    	at com.isomorphic.datasource.DataSource.forName(DataSource.java:170)
    	at com.isomorphic.datasource.DataSource.forName(DataSource.java:165)
    	at com.isomorphic.datasource.PoolableDataSourceFactory.makeUnpooledObject(PoolableDataSourceFactory.java:95)
    	at com.isomorphic.datasource.PoolableDataSourceFactory.makeObject(PoolableDataSourceFactory.java:102)
    	at com.isomorphic.pool.PoolManager.borrowObject(PoolManager.java:82)
    	at com.isomorphic.datasource.DataSourceManager.getDataSource(DataSourceManager.java:87)
    	at com.isomorphic.servlet.DataSourceLoader.processRequest(DataSourceLoader.java:109)
    	at com.isomorphic.servlet.DataSourceLoader.doGet(DataSourceLoader.java:83)
    	at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
    	at com.isomorphic.servlet.BaseServlet.service(BaseServlet.java:152)
    	at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    	at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:487)
    	at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:362)
    	at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
    	at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:181)
    	at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:729)
    	at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:405)
    	at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
    	at org.mortbay.jetty.handler.RequestLogHandler.handle(RequestLogHandler.java:49)
    	at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
    	at org.mortbay.jetty.Server.handle(Server.java:324)
    	at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:505)
    	at org.mortbay.jetty.HttpConnection$RequestHandler.headerComplete(HttpConnection.java:829)
    	at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:513)
    	at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:211)
    	at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:380)
    	at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:395)
    	at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:488)
    Caused by: javax.persistence.PersistenceException: No Persistence provider for EntityManager named ds
    	at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:54)
    	at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:32)
    	at com.isomorphic.jpa.EMFProviderLMT.<init>(EMFProviderLMT.java:73)
    	at com.isomorphic.jpa.EMFProviderLMT.<init>(EMFProviderLMT.java:52)

    Comment


      #3
      When you use autoDeriveSchema or schemaBean, your DataSource acquires an implicit parent DataSource that it inherits field definitions from via the DataSource.inheritsFrom mechanism.

      As far as the error message, difficult-to-debug messages like this are one of the reasons we recommend the SQLDataSource as a first choice. If you want to continue to beat on JPA, we'd recommend calling JPA APIs directly to test whether the configuration is valid.

      Comment


        #4
        If I want to use the SQLDataSource (which I was using until recently), I tried looking for a few good examples showing OneToMany, OneToOne and related associations but couldn't find any hence my move to the JPA..

        When using the SQLDataSource, do I have to build my own relations between tables (I know I'll have to identify foreign keys and primary keys) -- In looking at the one example that's in the showcase, it seemed like I would.. I'd be happy to go back to the SQLDataSource if I can get past the table relations I got stuck on. TIA!

        Comment


          #5
          The EE Showcase shows multiple examples of 1 to Many related tables. For Many to Many, use the classic relational structure of a "join table".

          Comment

          Working...
          X