Skip to content
This repository has been archived by the owner on Jul 30, 2021. It is now read-only.

SQL Foreign key generation: Duplicates #39

Open
fireplace009 opened this issue Sep 7, 2017 · 2 comments
Open

SQL Foreign key generation: Duplicates #39

fireplace009 opened this issue Sep 7, 2017 · 2 comments

Comments

@fireplace009
Copy link

Hello,

When generating my Q sources for SQL queryDsl, my foreign keys contain duplicates.

For instance:
public final com.querydsl.sql.ForeignKey lnk14051 = createForeignKey(Arrays.asList(cdRmrkDnr, cdRmrkDnr, cdRmrkDnr, cdRmrkDnr, cdRmrkDnr, cdRmrkDnr), Arrays.asList("DNR", "DNR", "DNR", "DNR", "DNR", "DNR"));

But it should jus tlook like:
public final com.querydsl.sql.ForeignKey lnk14051 = createForeignKey(Arrays.asList(cdRmrkDnr), Arrays.asList("DNR"));

After a bit of deeper diving into the code, I was wondering if it has something to do with missing config parameters (maybe something to do with 'Catalog' ... to limit the amount of found foreignkeys in the metadata)

I'm using plugin:

`

		<plugin>
			<groupId>com.querydsl</groupId>
			<artifactId>querydsl-maven-plugin</artifactId>
			<version>${querydsl.version}</version>
			<executions>
				<execution>
					<goals>
						<goal>export</goal>
					</goals>
				</execution>
			</executions>
			<configuration>
				<jdbcDriver>com.ibm.db2.jcc.DB2Driver</jdbcDriver>
				<jdbcUrl>jdbc:db2://server:port/dbname</jdbcUrl>
				<jdbcUser>user</jdbcUser>
				<jdbcPassword>password</jdbcPassword>
				<schemaPattern>NK</schemaPattern>
				<tableNamePattern>TNK14%</tableNamePattern>
				<targetFolder>${project.basedir}/target/generated-sources/java</targetFolder>
			</configuration>
			<dependencies>
				<dependency>
					<groupId>com.ibm.db2</groupId>
					<artifactId>db2jcc4</artifactId>
					<version>4.22.29</version>
				</dependency>
			</dependencies>
		</plugin>

`

Any help would be highly appreciated :)

@Shredder121
Copy link
Member

Could you maybe report this to the querydsl repository?
Also an example schema would help.
I think I can setup db2, so should not be an issue.
But yeah, finding where it goes wrong can be time consuming.

@fireplace009
Copy link
Author

Hello,
"Report this to querydsl repo" ... I'm not sure what you want me to do here ...

I debugged a bit more and found that my DB2 returns the same foreignkey multiple times (in the KeyDataFactory)

Example:

` ------------ LNK14081 -------------------
#########>>>>>>>>>>>>> null // PKTABLE_CAT
#########>>>>>>>>>>>>> NK // PKTABLE_SCHEM
#########>>>>>>>>>>>>> TNK14040 // PKTABLE_NAME
#########>>>>>>>>>>>>> DNR // PKCOLUMN_NAME
#########>>>>>>>>>>>>> null // FKTABLE_CAT
#########>>>>>>>>>>>>> NK // FKTABLE_SCHEM
#########>>>>>>>>>>>>> TNK14080 // FKTABLE_NAME
#########>>>>>>>>>>>>> CUST_ORD_DNR // FKCOLUMN_NAME
#########>>>>>>>>>>>>> 1 // KEY_SEQ
#########>>>>>>>>>>>>> 3 // UPDATE_RULE
#########>>>>>>>>>>>>> 0 // DELETE_RULE
#########>>>>>>>>>>>>> LNK14081 // FK_NAME
#########>>>>>>>>>>>>> null // PK_NAME
#########>>>>>>>>>>>>> 7 // DEFERRABILITY

------------ LNK14081 -------------------
#########>>>>>>>>>>>>> null
#########>>>>>>>>>>>>> TNG0000
#########>>>>>>>>>>>>> CUST_ORD
#########>>>>>>>>>>>>> DNR
#########>>>>>>>>>>>>> null
#########>>>>>>>>>>>>> NK
#########>>>>>>>>>>>>> TNK14080
#########>>>>>>>>>>>>> CUST_ORD_DNR
#########>>>>>>>>>>>>> 1
#########>>>>>>>>>>>>> 3
#########>>>>>>>>>>>>> 0
#########>>>>>>>>>>>>> LNK14081
#########>>>>>>>>>>>>> null
#########>>>>>>>>>>>>> 7`

So ... The differentiator I notice is the PKTALBE_SCHEME ... so maybe it would be good to add this as a configuration property, to be able to limit the retrieved keys.

B;

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants