Jakarta EE Persistence: tables not showing in DB for new entities registered in persistence.xml

722 Views Asked by At

I am currently studying a postgrad software development course, and the current part of the course involves setting up a Jakarta EE project utilising Persistence and JSF to create a basic application to enable CRUD operations on entities through a web interface.

I am using Netbeans 12.4, JDK 11 LTS, Payara Server 5.2021.5.

I have successfully setup a Maven project and generated all of the MVC components using the built in tools. One of my three entity classes is as follows:

 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package entities;

import java.io.Serializable;
import java.util.List;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Table;

/**
 *
 * @author ruebenchandler
 */
@Entity
public class Room implements Serializable
{

   private static final long serialVersionUID = 1L;
   @Id
   @GeneratedValue(strategy = GenerationType.AUTO)
   private Long id;
   
   
   @OneToMany(mappedBy = "room")
   private List<CurrentBooking> currentBookings;
   
   
   public Long getId ()
   {
      return id;
   }

   public void setId (Long id)
   {
      this.id = id;
   }

   @Override
   public int hashCode ()
   {
      int hash = 0;
      hash += (id != null ? id.hashCode () : 0);
      return hash;
   }

   @Override
   public boolean equals (Object object)
   {
      // TODO: Warning - this method won't work in the case the id fields are not set
      if (!(object instanceof Room))
      {
         return false;
      }
      Room other = (Room) object;
      if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals (other.id)))
      {
         return false;
      }
      return true;
   }

   @Override
   public String toString ()
   {
      return "entities.Room[ id=" + id + " ]";
   }
   
}

My persistence.xml is as follows (using the sample Java DB database):

<persistence version="2.2" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_2.xsd">
  <persistence-unit name="prod" transaction-type="JTA">
    <class>entities.Room</class>
    <class>entities.Guest</class>
    <class>entities.CurrentBooking</class>
    <properties>
      <property name="javax.persistence.schema-generation.database.action" value="create"/>
      <property name="javax.persistence.jdbc.url" value="jdbc:derby://localhost:1527/sample"/>
      <property name="javax.persistence.jdbc.user" value="app"/>
      <property name="javax.persistence.jdbc.driver" value="org.apache.derby.jdbc.ClientDriver"/>
      <property name="javax.persistence.jdbc.password" value="app"/>
    </properties>
  </persistence-unit>
</persistence>

On running the application, everything works fine, all CRUD operations work as expected, and when shutting down the application and re-launching it, the records have persisted. But I can't see the new tables in DB view:

Screenshot of tables list

As far as I can tell, the tables are being created and stored somewhere, but I am at a loss as to where.

My tutor had suggested checking my @Table annotations, which I did try without success, but from what I see they aren't required as the database will just use some default values.

Many thanks.

1

There are 1 best solutions below

0
Tadas B. On

I think the Derby DB is pointed to the wrong DB location in Netbeans