[ 
https://issues.apache.org/jira/browse/OPENJPA-2839?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17234556#comment-17234556
 ] 

CHAN Shih-Ping edited comment on OPENJPA-2839 at 11/18/20, 12:26 PM:
---------------------------------------------------------------------

A reproducer is  the (wildfly+hibernate) tutorial

[https://github.com/wildfly/quickstart/tree/master/greeter]

 This project has an Entity table named {{Users}}.
 * Deploy to a OpenJPA container, e.g. TomEE 8.0.4 + H2
 * Remove hibernate-isms from {{persistence.xml}} and use JPA 2.1 schema 
generation
{code:java}
 <?xml version="1.0" encoding="UTF-8"?>
<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="primary">
    <!-- If you are running in a production environment, add a managed data
      source, this example data source is just for development and testing! -->
    <!-- The datasource is deployed as WEB-INF/greeter-quickstart-ds.xml,
      you can find it in the source at 
src/main/webapp/WEB-INF/greeter-quickstart-ds.xml -->
    
<jta-data-source>java:jboss/datasources/GreeterQuickstartDS</jta-data-source>
    <properties>
      <!-- Properties for Hibernate -->
      <!-- <property name="hibernate.hbm2ddl.auto" value="create-drop" />
        <property name="hibernate.show_sql" value="false" />
      -->
      <property
        name="javax.persistence.schema-generation.database.action"
        value="drop-and-create" />
      <property name="javax.persistence.sql-load-script-source"
        value="initial-data.sql" />
      <property name="openjpa.Log"
        value="DefaultLevel=WARN, Runtime=INFO, Tool=INFO, SQL=TRACE" />
    </properties>
  </persistence-unit>
</persistence>
{code}

 
 * Workaround JBoss/Wildfly-isms *-ds.xml; add a unmanaged data-source to 
{{web.xml}}

{code:java}
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.1" xmlns="http://xmlns.jcp.org/xml/ns/javaee";
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; 
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee 
http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd";>
 <data-source>
  <name>jboss/datasources/GreeterQuickstartDS</name>
  <class-name>org.h2.Driver</class-name>
  <url>jdbc:h2:mem:testdb;DB_CLOSE_ON_EXIT=FALSE;DB_CLOSE_DELAY=-1</url>
  <user>sa</user>
  <password>sa</password>
  <transactional>true</transactional>
 </data-source>
 <servlet>
  <servlet-name>Faces Servlet</servlet-name>
  
<servlet-class&amp;amp;amp;gt;javax.faces.webapp.FacesServlet</servlet-class&amp;amp;amp;gt;
  <load-on-startup>1</load-on-startup>
 </servlet>
 <servlet-mapping>
  <servlet-name>Faces Servlet</servlet-name>
  <url-pattern>*.xhtml</url-pattern>
 </servlet-mapping>
 <session-config>
  <session-timeout>30</session-timeout>
 </session-config>
 <welcome-file-list>
  <welcome-file>greet.xhtml</welcome-file>
 </welcome-file-list>
</web-app>

  {code}


was (Author: spchan):
A reproducer is  the (wildfly+hibernate) tutorial

[https://github.com/wildfly/quickstart/tree/master/greeter]

 This project has an Entity table named {{Users}}.
 * Deploy to a OpenJPA container, e.g. TomEE 8.0.4 + H2
 * Remove hibernate-isms from {{persistence.xml}} and use JPA 2.1 schema 
generation
{code:java}
 <?xml version="1.0" encoding="UTF-8"?>
<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="primary">
    <!-- If you are running in a production environment, add a managed data
      source, this example data source is just for development and testing! -->
    <!-- The datasource is deployed as WEB-INF/greeter-quickstart-ds.xml,
      you can find it in the source at 
src/main/webapp/WEB-INF/greeter-quickstart-ds.xml -->
    
<jta-data-source>java:jboss/datasources/GreeterQuickstartDS</jta-data-source>
    <properties>
      <!-- Properties for Hibernate -->
      <!-- <property name="hibernate.hbm2ddl.auto" value="create-drop" />
        <property name="hibernate.show_sql" value="false" />
      -->
      <property
        name="javax.persistence.schema-generation.database.action"
        value="drop-and-create" />
      <property name="javax.persistence.sql-load-script-source"
        value="initial-data.sql" />
      <property name="openjpa.Log"
        value="DefaultLevel=WARN, Runtime=INFO, Tool=INFO, SQL=TRACE" />
    </properties>
  </persistence-unit>
</persistence>
{code}

 
 * Wildfly-isms *-ds.xml; need to add a data-source to web.xml
{code:java}
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.1" xmlns="http://xmlns.jcp.org/xml/ns/javaee";
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; 
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee 
http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd";>
 <data-source>
  <name>jboss/datasources/GreeterQuickstartDS</name>
  <class-name>org.h2.Driver</class-name>
  <url>jdbc:h2:mem:testdb;DB_CLOSE_ON_EXIT=FALSE;DB_CLOSE_DELAY=-1</url>
  <user>sa</user>
  <password>sa</password>
  <transactional>true</transactional>
 </data-source>
 <servlet>
  <servlet-name>Faces Servlet</servlet-name>
  
<servlet-class&amp;amp;gt;javax.faces.webapp.FacesServlet</servlet-class&amp;amp;gt;
  <load-on-startup>1</load-on-startup>
 </servlet>
 <servlet-mapping>
  <servlet-name>Faces Servlet</servlet-name>
  <url-pattern>*.xhtml</url-pattern>
 </servlet-mapping>
 <session-config>
  <session-timeout>30</session-timeout>
 </session-config>
 <welcome-file-list>
  <welcome-file>greet.xhtml</welcome-file>
 </welcome-file-list>
</web-app>

  {code}

> OpenJPA+H2 is finding USERS table from INFORMATION_SCHEMA
> ---------------------------------------------------------
>
>                 Key: OPENJPA-2839
>                 URL: https://issues.apache.org/jira/browse/OPENJPA-2839
>             Project: OpenJPA
>          Issue Type: Bug
>          Components: jpa
>    Affects Versions: 3.1.0
>         Environment: Java 11, OpenJPA 3.1.0 (from TomEE), H2 1.4.200
>            Reporter: CHAN Shih-Ping
>            Priority: Major
>
> With Entity table named USERS, OpenJPA+H2 is incorrectly detecting that table 
> exists because it finds INFORMATION_SCHEMA.USERS.
>  
> Using H2 as JDBC driver and metadata-only DDL schema generation:
> {code:java}
> <property name="javax.persistence.schema-generation.database.action" 
> value="drop-and-create" />
> <property name="javax.persistence.sql-load-script-source" 
> value="initial-data.sql" />{code}
> The connection string is {{jdbc:h2:mem:testdb}}.
>  
> The Entity table is named "Users" but OpenJPA misdetects that the table 
> exists (it searches in the INFORMATION_SCHEMA as well, it seems), and so does 
> not send "CREATE TABLE..".
> Instead it sends "ALTER TABLE...". In H2 this targets the PUBLIC schema and 
> so will fail as the "Users" table does not exist in the PUBLIC schema.
> In contrast, hibernate correctly detects that the table does not exist, and 
> sends "CREATE TABLE...".



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to