Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 324213

Summary: JPA: validation-only=True breaks EntityManager deploy because initializeDescriptors() is called before loginAndDetectDatasource() in login() causing a default to the generic DatabasePlatform superclass
Product: z_Archived Reporter: Michael OBrien <michael.f.obrien>
Component: EclipselinkAssignee: Michael OBrien <michael.f.obrien>
Status: RESOLVED WONTFIX QA Contact:
Severity: major    
Priority: P2 CC: eclipselink.orm-inbox
Version: unspecifiedFlags: michael.f.obrien: documentation+
Target Milestone: ---   
Hardware: PC   
OS: Windows 7   
URL: http://wiki.eclipse.org/EclipseLink/Development/JPA_2.0/metamodel_api#DI_106:_20100810:_322585:Metamodel_initialization_via_EMF.getMetamodel.28.29_before_EM_deploy_results_in_an_invalid_Metamodel_because_of_UNINITIALIZED_descriptor.initializationStage
Whiteboard:
Bug Depends on: 324243, 324194    
Bug Blocks: 324974, 322585    
Attachments:
Description Flags
Patch to auto-detect database platform before initializeDescriptors when validation-only=True (a db login but not a full session.login())
none
Comment only patch for EntityManagerFactoryProvider - we will nofix and require that target-database is set when validation-only=True
none
324213 patch3 add validation-only javadoc
none
324213 patch3 add validation-only javadoc none

Description Michael OBrien CLA 2010-09-01 11:25:36 EDT
>Problem: User turns on validation (em.deploy/login at the same time as emf.predeploy) but does not specify the [target-database] and fails deploy.
Set
<property name="eclipselink.validation-only" value="True"/>
Clear
<!-- property name="eclipselink.target-database" value="Derby"/-->

>Analysis
In the EntityManagerSetupIMpl.deploy() -  a call to initialize descriptors is made that includes processing sequences on identifier attributes.
The problem is that we have not identified the proper DatabasePlatform yet (which happens 7 lines below in login() via session.loginAndDetectDatasource()).
The result is that we default to a generic DatabasePlatform which does not support native sequences and fail deployment.
This issue with validation is blocking enhancement bug # 322585 when the following property is not specified in the persistence.xml or orm.xml
<property name="eclipselink.target-database" value="Derby"/>

Normally we would see the following via the use of VendorNameToPlatformMapping.properties in loginAndDetectDatasource()
[EL Finest]: 2010-09-01 09:32:36.065--Thread(Thread[main,5,main])--DBPlatform:
org.eclipse.persistence.platform.database.JavaDBPlatform, RegularExpression:
(?i).*derby.
[EL Fine]: 2010-09-01 09:32:36.065--Thread(Thread[main,5,main])--Detected
Vendor platform: org.eclipse.persistence.platform.database.JavaDBPlatform
[EL Config]: 2010-09-01
09:32:36.075--ServerSession(15184449)--Connection(23370564)--Thread(Thread[main,5,main])--connecting(DatabaseLogin(
>	platform=>JavaDBPlatform

>Exception
Exception [EclipseLink-7144] (Eclipse Persistence Services - 2.2.0.qualifier): org.eclipse.persistence.exceptions.ValidationException
Exception Description: EL_CELL_SEQ: platform DatabasePlatform does not support NativeSequence.
	at org.eclipse.persistence.exceptions.ValidationException.platformDoesNotSupportSequence(ValidationException.java:1959)
	at org.eclipse.persistence.sequencing.NativeSequence.onConnect(NativeSequence.java:143)
	at org.eclipse.persistence.sequencing.Sequence.onConnect(Sequence.java:270)
	at org.eclipse.persistence.internal.sequencing.SequencingManager.onConnectAllSequences(SequencingManager.java:843)
	at org.eclipse.persistence.internal.sequencing.SequencingManager.onConnect(SequencingManager.java:706)
	at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.initializeSequencing(DatabaseSessionImpl.java:148)
	at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.initializeDescriptors(DatabaseSessionImpl.java:420)
	at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.initializeDescriptors(DatabaseSessionImpl.java:406)
	at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.deploy(EntityManagerSetupImpl.java:376)

>Proposed fix: Move database regular expression detection - before initializeDescriptors
Comment 1 Michael OBrien CLA 2010-09-01 11:32:14 EDT
>Roughly, the code should change from
EntityManagerSetupImpl.375
  if (isValidationOnly(deployProperties, false)) {
>    session.initializeDescriptors();
  } else {
    if (isSessionLoadedFromSessionsXML) {
      if (!session.isConnected()) {
        session.login();
      }
    } else {
>      login(session, deployProperties);
  }

>to
  if (isValidationOnly(deployProperties, false)) {
>    session.loginAndDetectDatasource(); // NEW for 324213
>    session.initializeDescriptors();
  } else {
    if (isSessionLoadedFromSessionsXML) {
      if (!session.isConnected()) {
        session.login();
      }
    } else {
>      login(session, deployProperties);
  }

>where we now get auto-detected
[EL Finest]: 2010-09-01 11:27:59.641--Thread(Thread[main,5,main])--DBPlatform: org.eclipse.persistence.platform.database.JavaDBPlatform, RegularExpression: (?i).*derby.
[EL Fine]: 2010-09-01 11:27:59.641--Thread(Thread[main,5,main])--Detected Vendor platform: org.eclipse.persistence.platform.database.JavaDBPlatform
[EL Config]: 2010-09-01 11:27:59.681--ServerSession(15184449)--Connection(30293957)--Thread(Thread[main,5,main])--connecting(DatabaseLogin(
	platform=>JavaDBPlatform
Comment 2 Michael OBrien CLA 2010-09-01 11:54:12 EDT
Created attachment 177977 [details]
Patch to auto-detect database platform before initializeDescriptors when validation-only=True (a db login but not a full session.login())
Comment 3 Michael OBrien CLA 2010-09-02 10:58:49 EDT
>Alternative to logging into the database #2
The issue with validation-only=True is that if the target-database is not specified - we fail because we have not detected the database platform yet.
We can avoid a login to the database to get the vendor string by parsing the connection URL - this may a valid alternative to logging into the DB server
Comment 4 Michael OBrien CLA 2010-09-02 13:34:36 EDT
>Note: DB login when validation-only=True occurs on em.deploy() (no descriptor validation is done in emf.predeploy()
>Just for reference: EE JTA injected EM fails on WebLogic 10.3.3.0 as expected
When no target-database specified
>Otherwise deployment works without target-database (for JTA) when validation is off

<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="example" transaction-type="JTA">
        <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
        <jta-data-source>localJTA</jta-data-source>
        <class>org.eclipse.persistence.example.jpa.server.business.Cell</class>
        <properties>
            <!-- 323148: force an early em.deploy() as part of the emf.predeploy() - normally done on first entityManager login -->
            <property name="eclipselink.validation-only" value="True"/>

>Exception
<2-Sep-2010 1:24:49 o'clock PM EDT> <Alert> <EclipseLink> <BEA-2005000> <2010-09-02 13:24:49.045--ServerSession(39163449)--Local Exception Stack: 
Exception [EclipseLink-7144] (Eclipse Persistence Services - 2.2.0.qualifier): org.eclipse.persistence.exceptions.ValidationException
Exception Description: EL_CELL_SEQ: platform DatabasePlatform does not support NativeSequence.
	at org.eclipse.persistence.exceptions.ValidationException.platformDoesNotSupportSequence(ValidationException.java:1959)
	at org.eclipse.persistence.sequencing.NativeSequence.onConnect(NativeSequence.java:143)
	at org.eclipse.persistence.sequencing.Sequence.onConnect(Sequence.java:270)
	at org.eclipse.persistence.internal.sequencing.SequencingManager.onConnectAllSequences(SequencingManager.java:843)
	at org.eclipse.persistence.internal.sequencing.SequencingManager.onConnect(SequencingManager.java:706)
	at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.initializeSequencing(DatabaseSessionImpl.java:148)
	at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.initializeDescriptors(DatabaseSessionImpl.java:420)
	at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.initializeDescriptors(DatabaseSessionImpl.java:406)
	at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.deploy(EntityManagerSetupImpl.java:380)
	at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.getServerSession(EntityManagerFactoryImpl.java:157)
	at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManagerImpl(EntityManagerFactoryImpl.java:214)
	at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:202)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:597)
	at weblogic.deployment.EntityManagerFactoryProxyImpl.invoke(EntityManagerFactoryProxyImpl.java:87)
	at $Proxy89.createEntityManager(Unknown Source)

>in EntityManagerSetupImpl.deploy()
                        if (isValidationOnly(deployProperties, false)) {
                            session.initializeDescriptors();
Comment 5 Michael OBrien CLA 2010-09-03 09:15:17 EDT
Created attachment 178141 [details]
Comment only patch for EntityManagerFactoryProvider - we will nofix and require that target-database is set when validation-only=True

>After a review by the JPA team, the option to nofix this was suggested
The change in EntityManagerFactoryProvider that would have called DB auto-detection and logged into the DB will not be done so we can preserve the "no login" behavior of validation.
We will nofix and require that target-database property is set when validation-only=True
Comment 6 Michael OBrien CLA 2010-09-03 09:16:48 EDT
>Validation users need to specify the database platform in order for full validation to occur
target-database property should be set when validation-only=True
Comment 7 Michael OBrien CLA 2010-09-13 10:00:33 EDT
Created attachment 178742 [details]
324213 patch3 add validation-only javadoc
Comment 8 Michael OBrien CLA 2010-09-13 10:30:30 EDT
Created attachment 178745 [details]
324213 patch3 add validation-only javadoc
Comment 9 Michael OBrien CLA 2010-09-13 10:33:35 EDT
>comment javadoc changes in 8165 and 8166
Comment 10 Eclipse Webmaster CLA 2022-06-09 10:02:31 EDT
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink