Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 368653 - MaxDB: Duplicate schema name on sequence when table qualifier is set
Summary: MaxDB: Duplicate schema name on sequence when table qualifier is set
Status: RESOLVED FIXED
Alias: None
Product: z_Archived
Classification: Eclipse Foundation
Component: Eclipselink (show other bugs)
Version: unspecified   Edit
Hardware: PC Windows 7
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Nobody - feel free to take it CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-01-16 04:38 EST by Sabine Heider CLA
Modified: 2022-06-09 10:21 EDT (History)
2 users (show)

See Also:


Attachments
Remove table qualifier from MaxDBPlatform.buildSelectQueryForSequenceObject (1.16 KB, patch)
2012-01-16 04:52 EST, Sabine Heider CLA
no flags Details | Diff
Test case for sequence object with schema name set plus patch for MaxDB platform (8.74 KB, patch)
2012-01-31 05:56 EST, Sabine Heider CLA
tom.ware: iplog+
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Sabine Heider CLA 2012-01-16 04:38:57 EST
If the application sets a table qualifier (using a session customizer), the SQL statement for accessing a sequence on MaxDB is incorrectly rendered. The table qualifier is duplicated:
SELECT ECLIPSELINK.ECLIPSELINK.SEQ_GEN_SEQUENCE.NEXTVAL FROM DUAL

The reason for this is that both MaxDBPlatform.buildSelectQueryForSequenceObject and NativeSequence.buildSelectQuery add the table qualifier to the sequence name. The attached patch removes the table qualifier from the MaxDBPlatform.

I would actually like to add a regression test for this, but I don't know how to integrate the table qualifier into your test framework. Could someone please help? 
This is how to reproduce the issue:


Have a test entity with a sequence:

@Entity
public class MyEntity {

	@Id
	@GeneratedValue(strategy = SEQUENCE)
	private int id;

(...)	
}

Implement a session customizer like that:

public class TestSessionCustomizer implements SessionCustomizer {

	@Override
	public void customize(Session session) throws Exception {
		String schemaName = "ECLIPSELINK";
	    session.getPlatform().setTableQualifier(schemaName);
	}

}

Declare it in the persistence.xml:

<property name="eclipselink.session.customizer" value="test.TestSessionCustomizer"/>

Create and persist the entity:

        EntityManagerFactory emf = Persistence.createEntityManagerFactory("testmodel");
        EntityManager em = emf.createEntityManager();
        try {
	        MyEntity e = new MyEntity();
	        em.getTransaction().begin();
	        em.persist(e);
	        em.getTransaction().commit();
	        em.clear();
        } finally {
        	emf.close();
        }
Comment 1 Sabine Heider CLA 2012-01-16 04:52:17 EST
Created attachment 209535 [details]
Remove table qualifier from MaxDBPlatform.buildSelectQueryForSequenceObject
Comment 2 Sabine Heider CLA 2012-01-16 04:53:25 EST
We would need the patch for 2.3 as well.
Comment 3 Tom Ware CLA 2012-01-16 11:02:39 EST
The @Table annotation (and most other table related annotations)allows you to set schema (as does persistence-unit-defaults) in orm.xml.  Do those allow you to get a test working?
Comment 4 Sabine Heider CLA 2012-01-18 05:59:49 EST
I can reproduce the error only with a session customizer. Neither setting a schema in <persistence-unit-defaults> nor in the @Table annotation produces the duplication, as both don't result in the tableQualifier being set on the DatabasePlatform (don't know whether that is another bug).

My issue is rather how to get a reasonable value to set in the setTableQualifier method. I would like to set the name of the (default) schema used in the test setup in order to execute a statement like
SELECT <NAME_OF_DEFAULT_SCHEMA>.SEQ_GEN_SEQUENCE.NEXTVAL FROM DUAL
instead of 
SELECT SEQ_GEN_SEQUENCE.NEXTVAL FROM DUAL.

In my local test setup, I know that value of course, so that I could hardcode it for testing - but how can I do it in general? A mandatory additional property in the test.property is ugly. An optional property (skipping the test if the property is not set) would basically disable the test for everyone not knowing that property (i.e. everyone except me...). Hmm. Any other ideas?
Comment 5 Tom Ware CLA 2012-01-18 11:12:15 EST
It might be possible to unwrap the JDBC connection, send a query down the connection and get the schema from the ResultSetMetadata.
Comment 6 Sabine Heider CLA 2012-01-31 05:56:14 EST
Created attachment 210304 [details]
Test case for sequence object with schema name set plus patch for MaxDB platform
Comment 7 Sabine Heider CLA 2012-01-31 05:57:07 EST
Thanks Tom.

I've just uploaded a new patch containing both a test case reproducing the issue and a fix for the MaxDB platform. I placed the test in the ...jpa.advanced.EntityManagerJUnitTestSuite - don't know whether that's a suitable location for it.

The patch has been tested successfully on MaxDB and MySQL (where the test is actually skipped). I don't have an Oracle DB available, so unfortunately I couldn't test on that platform.

As we need the patch for 2.3 as well: How do you organize that? Should I manually provide a 2.3 patch here or do you have some more sophisticated tooling to downport changes?

Please let me know if there's anything else I can actively provide for that patch.

Thanks and best regards,
Sabine
Comment 8 Tom Ware CLA 2012-01-31 09:02:21 EST
The changes look good to me.

We do not have any tools (beyond the typical SVN toolset) for merging changes into previous streams.  Most of the time it is a manual process.

I assume one of the SAP committers will be committing this.
Comment 9 Sabine Heider CLA 2012-01-31 10:49:46 EST
Actually I don't think there really is a SAP committer left... *sigh* Adrian has moved to a different team and is no longer involved with persistency (I think he had informed you about that?). The same with Andreas, who had left long before Adrian. 

So, may I kindly ask you to commit that for me, please? :-)

Thanks and best regards,
Sabine
Comment 10 Tom Ware CLA 2012-01-31 15:30:48 EST
Fix checked in to trunk and 2.3

Reviewed by Tom Ware - reviewed Sabine's fix

Testing is added in EntityManagerJunitTestSuite as part of the patch
Comment 11 Sabine Heider CLA 2012-02-01 04:41:00 EST
Fix checked in by Tom. Thank you for your help!
Comment 12 Eclipse Webmaster CLA 2022-06-09 10:21:37 EDT
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink