0

I am new into java JPA and started to work in an old project.So,I have table name certificates in Postgres and the queries which I have written in code is actually working manually over there.

Also, I am dockerizing the app and running.

In the dao files, I am maintaining the queries like this:

NamedQueries({ @NamedQuery(name = "PosCertificate.findAll", query = "SELECT ce FROM PosCertificate ce"),
    @NamedQuery(name = "PosCertificate.findAllCount", query = "SELECT COUNT(d) FROM PosCertificate d"),
    @NamedQuery(name = "PosCertificate.findById", query = "SELECT d FROM PosCertificate d WHERE d.dev_id = :dev_id"),
    @NamedQuery(name = "PosCertificate.idExists", query = "SELECT COUNT(d) FROM PosCertificate d WHERE d.dev_id = :dev_id")})


@Entity
@Data 
@Table(name = "certificates")
public class PosCertificate implements Serializable {

    private static final long serialVersionUID = 1L;

Persistance.xml -

<persistence-unit name="PU_CSA">
        <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
        <non-jta-data-source>java:comp/env/jdbc/CSA</non-jta-data-source>
        <class>backend.dao.PosCertificate</class>
        <properties>
            <!-- EclipseLink should create the database schema automatically -->
            <property name="eclipselink.ddl-generation.output-mode" value="database" />
        
        </properties>
    </persistence-unit>
    
    <persistence-unit name="PU_CSB">
        <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
        <non-jta-data-source>java:comp/env/jdbc/CSB</non-jta-data-source>
        <class>backend.dao.PosCertificate</class>
        <properties>

Context.xml

<ResourceLink name="jdbc/CSA" global="jdbc/certServA" auth="Container" type="javax.sql.DataSource" />
    <Environment name="backend.dao.CSA.database.shortdesc" type="java.lang.String" value="AuthServer Development" />
    <Environment name="backend.dao.CSA.PosCertificate.table.name" type="java.lang.String" value="certificates" />

    <ResourceLink name="jdbc/CSB" global="jdbc/certServB" auth="Container" type="javax.sql.DataSource" />
    <Environment name="backend.dao.CSB.database.shortdesc" type="java.lang.String" value="AuthServer Productive" />
    <Environment name="backend.dao.CSB.PosCertificate.table.name" type="java.lang.String" value="certificates" />

After all these I am still facing 500- Internal Server error:

Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.5.2.v20140319-9ad6abd): org.eclipse.persistence.exceptions.DatabaseException

Exception

javax.persistence.PersistenceException: Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.5.2.v20140319-9ad6abd): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: org.postgresql.util.PSQLException: ERROR: relation "certificates" does not exist
  Position: 23
Error Code: 0
Call: SELECT COUNT(ID) FROM certificates
Query: ReportQuery(name="PosCertificate.findAllCount" referenceClass=PosCertificate sql="SELECT COUNT(ID) FROM certificates")
howlger
  • 31,050
  • 11
  • 59
  • 99
NoobCoder
  • 493
  • 8
  • 25
  • You might have some clues there: https://stackoverflow.com/questions/2034099/psqlexception-error-relation-table-name-does-not-exist – Pierre Demeestere Jan 23 '23 at 09:40
  • 1
    You are missing a few properties to have DDL generated - the only one you have just tells it where to go, not to actually do anything. See https://www.eclipse.org/eclipselink/documentation/2.5/jpa/extensions/p_ddl_generation.htm for EclipseLink specific DDL property examples. EclipseLink properties offer a few more options like create-or-extend-tables, but you might want to look at using JPA properties as described here instead: https://docs.oracle.com/javaee/7/tutorial/persistence-intro005.htm . – Chris Jan 23 '23 at 16:03
  • @Chris Let me try this. – NoobCoder Jan 24 '23 at 05:42

0 Answers0