Search code examples
javajdbcpersistencepersistence-unit

When/How does jdbc percistency enities get created


Question :

When and how do the JDBC tables get created ? Cause the wierd thing is that i can't find any User tabel. I find it wierd that there is a tabel for the many-on-many relationship between User and Dish yet there is no User tabel to store the name and password of this user.

Structure:

  • User :
    • String name
    • String password
    • List<Dish> shoppingList
  • Ingrediënt :
    • String name
  • IngredientQuantity :
    • Ingredient ingredient
    • Quantity quantity
  • Quantity :
    • int quantity
    • String unit
  • Dish :
    • String name
    • int people
    • Collection<IngredientQuantity> ingredients

JDBC:

JDBC

Persistence Unit:

<persistence version="2.1" xmlns="http://xmlns.jcp.org/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_1.xsd">
  <persistence-unit name="ShoppingCalendarPU" transaction-type="RESOURCE_LOCAL">
    <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
    <class>domain.Dish</class>
    <class>domain.Ingredient</class>
    <class>domain.User</class>
    <properties>
      <property name="javax.persistence.jdbc.url" value="jdbc:derby://localhost:1527/ShoppingCalendarDB"/>
      <property name="javax.persistence.jdbc.password" value="app"/>
      <property name="javax.persistence.jdbc.driver" value="org.apache.derby.jdbc.ClientDriver"/>
      <property name="javax.persistence.jdbc.user" value="app"/>
      <property name="javax.persistence.schema-generation.database.action" value="create"/>
    </properties>
  </persistence-unit>
</persistence>

Solution

  • Like JB Nizet said, table name "user" is reserved.