The getColumnType() method of java.sql.ResultSetMetaData returns an
SQL type code (one of the constants in java.sql.Types). For some MySQL
types, the implementation of this method in the MariaDB Java Client
returns a different code than the implementation in MySQL
Connector/J. For example, for a column declared as "INT UNSIGNED", the
MariaDB Java Client returns BIGINT, but MySQL Connector/J returns
INTEGER.
This gives problems with Hibernate, which uses this metadata to do its
thing.
Here is the list of numerical types for which I found a mismatch:
Declared column type
MariaDB Java Client
MySQL Connector/J
FLOAT
FLOAT
REAL
FLOAT UNSIGNED
FLOAT
REAL
SMALLINT UNSIGNED
INTEGER
SMALLINT
INTEGER UNSIGNED
BIGINT
INTEGER
INT UNSIGNED
BIGINT
INTEGER
(INT and INTEGER are equivalent of course)
I'm attaching two patches:
The first one to make the current trunk compile (which it doesn't,
at least not for me, because of a '-' in a method name).
The second fixes the problem, fixes the unit tests and adds one more
unit tests, that combines test the metadata with actual data as
well.
If the metadata is retrieved through DatabaseMetadata, it seems to return wrong values for int unsigned and smallint unsigned:
// Example with smallint unsigned
// my_table has a single column my_col of type smallint unsigned
DatabaseMetaData connectionMetaData = connection.getMetaData();
ResultSet column = connectionMetaData.getColumns(null, null, "my_table", "my_col");
column.next(); // step to first row
int type = column.getInt(5); // column #5 contains the java sql type (see DatabaseMetaData.getColumns)
type will be 4 (INTEGER) instead of 5 (SMALLINT)!
This stems from org.mariadb.jdbc.MySQLDatabaseMetaData.dataTypeClause(...) which still has the "old" behavior:
WHEN 'smallint' THEN IF( " + fullTypeColumnName + " like '%unsigned%', "Types.INTEGER","+ Types.SMALLINT + ")
My apologies if I posted this in the wrong place.
Best regards,
Jacob
Jacob Poder
added a comment - Hi,
If the metadata is retrieved through DatabaseMetadata, it seems to return wrong values for int unsigned and smallint unsigned:
// Example with smallint unsigned
// my_table has a single column my_col of type smallint unsigned
DatabaseMetaData connectionMetaData = connection.getMetaData();
ResultSet column = connectionMetaData.getColumns(null, null, "my_table", "my_col");
column.next(); // step to first row
int type = column.getInt(5); // column #5 contains the java sql type (see DatabaseMetaData.getColumns)
type will be 4 (INTEGER) instead of 5 (SMALLINT)!
This stems from org.mariadb.jdbc.MySQLDatabaseMetaData.dataTypeClause(...) which still has the "old" behavior:
WHEN 'smallint' THEN IF( " + fullTypeColumnName + " like '%unsigned%', " Types.INTEGER ","+ Types.SMALLINT + ")
My apologies if I posted this in the wrong place.
Best regards,
Jacob
People
Vladislav Vaintroub
Davy Verstappen
Votes:
0Vote for this issue
Watchers:
3Start watching this issue
Dates
Created:
Updated:
Resolved:
Git Integration
Error rendering 'com.xiplink.jira.git.jira_git_plugin:git-issue-webpanel'. Please contact your Jira administrators.
{"report":{"fcp":1084.2000000476837,"ttfb":332.7000000476837,"pageVisibility":"visible","entityId":24397,"key":"jira.project.issue.view-issue","isInitial":true,"threshold":1000,"elementTimings":{},"userDeviceMemory":8,"userDeviceProcessors":64,"apdex":0.5,"journeyId":"da346737-c1d5-4157-9f17-1355ceac0b1a","navigationType":0,"readyForUser":1155.2000000476837,"redirectCount":0,"resourceLoadedEnd":1181.3999999761581,"resourceLoadedStart":337.89999997615814,"resourceTiming":[{"duration":251,"initiatorType":"link","name":"https://jira.mariadb.org/s/2c21342762a6a02add1c328bed317ffd-CDN/lu2bu7/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/css/_super/batch.css","startTime":337.89999997615814,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":337.89999997615814,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":588.8999999761581,"responseStart":0,"secureConnectionStart":0},{"duration":251.39999997615814,"initiatorType":"link","name":"https://jira.mariadb.org/s/7ebd35e77e471bc30ff0eba799ebc151-CDN/lu2bu7/820016/12ta74/8679b4946efa1a0bb029a3a22206fb5d/_/download/contextbatch/css/jira.browse.project,project.issue.navigator,jira.view.issue,jira.general,jira.global,atl.general,-_super/batch.css?agile_global_admin_condition=true&jag=true&jira.create.linked.issue=true&slack-enabled=true","startTime":338.10000002384186,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":338.10000002384186,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":589.5,"responseStart":0,"secureConnectionStart":0},{"duration":308,"initiatorType":"script","name":"https://jira.mariadb.org/s/fbf975c0cce4b1abf04784eeae9ba1f4-CDN/lu2bu7/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/js/_super/batch.js?locale=en","startTime":338.2999999523163,"connectEnd":338.2999999523163,"connectStart":338.2999999523163,"domainLookupEnd":338.2999999523163,"domainLookupStart":338.2999999523163,"fetchStart":338.2999999523163,"redirectEnd":0,"redirectStart":0,"requestStart":338.2999999523163,"responseEnd":646.2999999523163,"responseStart":646.2999999523163,"secureConnectionStart":338.2999999523163},{"duration":357.60000002384186,"initiatorType":"script","name":"https://jira.mariadb.org/s/099b33461394b8015fc36c0a4b96e19f-CDN/lu2bu7/820016/12ta74/8679b4946efa1a0bb029a3a22206fb5d/_/download/contextbatch/js/jira.browse.project,project.issue.navigator,jira.view.issue,jira.general,jira.global,atl.general,-_super/batch.js?agile_global_admin_condition=true&jag=true&jira.create.linked.issue=true&locale=en&slack-enabled=true","startTime":338.5,"connectEnd":338.5,"connectStart":338.5,"domainLookupEnd":338.5,"domainLookupStart":338.5,"fetchStart":338.5,"redirectEnd":0,"redirectStart":0,"requestStart":338.5,"responseEnd":696.1000000238419,"responseStart":696.1000000238419,"secureConnectionStart":338.5},{"duration":361,"initiatorType":"script","name":"https://jira.mariadb.org/s/94c15bff32baef80f4096a08aceae8bc-CDN/lu2bu7/820016/12ta74/c92c0caa9a024ae85b0ebdbed7fb4bd7/_/download/contextbatch/js/atl.global,-_super/batch.js?locale=en","startTime":338.60000002384186,"connectEnd":338.60000002384186,"connectStart":338.60000002384186,"domainLookupEnd":338.60000002384186,"domainLookupStart":338.60000002384186,"fetchStart":338.60000002384186,"redirectEnd":0,"redirectStart":0,"requestStart":338.60000002384186,"responseEnd":699.6000000238419,"responseStart":699.6000000238419,"secureConnectionStart":338.60000002384186},{"duration":361.3000000715256,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2bu7/820016/12ta74/1.0/_/download/batch/jira.webresources:calendar-en/jira.webresources:calendar-en.js","startTime":338.7999999523163,"connectEnd":338.7999999523163,"connectStart":338.7999999523163,"domainLookupEnd":338.7999999523163,"domainLookupStart":338.7999999523163,"fetchStart":338.7999999523163,"redirectEnd":0,"redirectStart":0,"requestStart":338.7999999523163,"responseEnd":700.1000000238419,"responseStart":700.1000000238419,"secureConnectionStart":338.7999999523163},{"duration":361.39999997615814,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2bu7/820016/12ta74/1.0/_/download/batch/jira.webresources:calendar-localisation-moment/jira.webresources:calendar-localisation-moment.js","startTime":339,"connectEnd":339,"connectStart":339,"domainLookupEnd":339,"domainLookupStart":339,"fetchStart":339,"redirectEnd":0,"redirectStart":0,"requestStart":339,"responseEnd":700.3999999761581,"responseStart":700.3999999761581,"secureConnectionStart":339},{"duration":445.39999997615814,"initiatorType":"link","name":"https://jira.mariadb.org/s/b04b06a02d1959df322d9cded3aeecc1-CDN/lu2bu7/820016/12ta74/a2ff6aa845ffc9a1d22fe23d9ee791fc/_/download/contextbatch/css/jira.global.look-and-feel,-_super/batch.css","startTime":339.2000000476837,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":339.2000000476837,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":784.6000000238419,"responseStart":0,"secureConnectionStart":0},{"duration":361.60000002384186,"initiatorType":"script","name":"https://jira.mariadb.org/rest/api/1.0/shortcuts/820016/47140b6e0a9bc2e4913da06536125810/shortcuts.js?context=issuenavigation&context=issueaction","startTime":339.2999999523163,"connectEnd":339.2999999523163,"connectStart":339.2999999523163,"domainLookupEnd":339.2999999523163,"domainLookupStart":339.2999999523163,"fetchStart":339.2999999523163,"redirectEnd":0,"redirectStart":0,"requestStart":339.2999999523163,"responseEnd":700.8999999761581,"responseStart":700.8999999761581,"secureConnectionStart":339.2999999523163},{"duration":445.3000000715256,"initiatorType":"link","name":"https://jira.mariadb.org/s/3ac36323ba5e4eb0af2aa7ac7211b4bb-CDN/lu2bu7/820016/12ta74/d176f0986478cc64f24226b3d20c140d/_/download/contextbatch/css/com.atlassian.jira.projects.sidebar.init,-_super,-project.issue.navigator,-jira.view.issue/batch.css?jira.create.linked.issue=true","startTime":339.39999997615814,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":339.39999997615814,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":784.7000000476837,"responseStart":0,"secureConnectionStart":0},{"duration":361.89999997615814,"initiatorType":"script","name":"https://jira.mariadb.org/s/3339d87fa2538a859872f2df449bf8d0-CDN/lu2bu7/820016/12ta74/d176f0986478cc64f24226b3d20c140d/_/download/contextbatch/js/com.atlassian.jira.projects.sidebar.init,-_super,-project.issue.navigator,-jira.view.issue/batch.js?jira.create.linked.issue=true&locale=en","startTime":339.60000002384186,"connectEnd":339.60000002384186,"connectStart":339.60000002384186,"domainLookupEnd":339.60000002384186,"domainLookupStart":339.60000002384186,"fetchStart":339.60000002384186,"redirectEnd":0,"redirectStart":0,"requestStart":339.60000002384186,"responseEnd":701.5,"responseStart":701.5,"secureConnectionStart":339.60000002384186},{"duration":830.3999999761581,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2bu7/820016/12ta74/1.0/_/download/batch/jira.webresources:bigpipe-js/jira.webresources:bigpipe-js.js","startTime":340.39999997615814,"connectEnd":340.39999997615814,"connectStart":340.39999997615814,"domainLookupEnd":340.39999997615814,"domainLookupStart":340.39999997615814,"fetchStart":340.39999997615814,"redirectEnd":0,"redirectStart":0,"requestStart":340.39999997615814,"responseEnd":1170.7999999523163,"responseStart":1170.7999999523163,"secureConnectionStart":340.39999997615814},{"duration":831.2000000476837,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2bu7/820016/12ta74/1.0/_/download/batch/jira.webresources:bigpipe-init/jira.webresources:bigpipe-init.js","startTime":340.39999997615814,"connectEnd":340.39999997615814,"connectStart":340.39999997615814,"domainLookupEnd":340.39999997615814,"domainLookupStart":340.39999997615814,"fetchStart":340.39999997615814,"redirectEnd":0,"redirectStart":0,"requestStart":340.39999997615814,"responseEnd":1171.6000000238419,"responseStart":1171.6000000238419,"secureConnectionStart":340.39999997615814},{"duration":239.69999992847443,"initiatorType":"xmlhttprequest","name":"https://jira.mariadb.org/rest/webResources/1.0/resources","startTime":795.7000000476837,"connectEnd":795.7000000476837,"connectStart":795.7000000476837,"domainLookupEnd":795.7000000476837,"domainLookupStart":795.7000000476837,"fetchStart":795.7000000476837,"redirectEnd":0,"redirectStart":0,"requestStart":795.7000000476837,"responseEnd":1035.3999999761581,"responseStart":1035.3999999761581,"secureConnectionStart":795.7000000476837},{"duration":135.39999997615814,"initiatorType":"link","name":"https://jira.mariadb.org/s/d5715adaadd168a9002b108b2b039b50-CDN/lu2bu7/820016/12ta74/be4b45e9cec53099498fa61c8b7acba4/_/download/contextbatch/css/jira.project.sidebar,-_super,-project.issue.navigator,-jira.general,-jira.browse.project,-jira.view.issue,-jira.global,-atl.general,-com.atlassian.jira.projects.sidebar.init/batch.css?agile_global_admin_condition=true&jag=true&jira.create.linked.issue=true&slack-enabled=true","startTime":1044.5,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":1044.5,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":1179.8999999761581,"responseStart":0,"secureConnectionStart":0},{"duration":130,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2bu7/820016/12ta74/e65b778d185daf5aee24936755b43da6/_/download/contextbatch/js/browser-metrics-plugin.contrib,-_super,-project.issue.navigator,-jira.view.issue,-atl.general/batch.js?agile_global_admin_condition=true&jag=true&jira.create.linked.issue=true&slack-enabled=true","startTime":1045.3999999761581,"connectEnd":1045.3999999761581,"connectStart":1045.3999999761581,"domainLookupEnd":1045.3999999761581,"domainLookupStart":1045.3999999761581,"fetchStart":1045.3999999761581,"redirectEnd":0,"redirectStart":0,"requestStart":1045.3999999761581,"responseEnd":1175.3999999761581,"responseStart":1175.3999999761581,"secureConnectionStart":1045.3999999761581},{"duration":135.69999992847443,"initiatorType":"script","name":"https://jira.mariadb.org/s/f51ef5507eea4c158f257c66c93b2a3f-CDN/lu2bu7/820016/12ta74/be4b45e9cec53099498fa61c8b7acba4/_/download/contextbatch/js/jira.project.sidebar,-_super,-project.issue.navigator,-jira.general,-jira.browse.project,-jira.view.issue,-jira.global,-atl.general,-com.atlassian.jira.projects.sidebar.init/batch.js?agile_global_admin_condition=true&jag=true&jira.create.linked.issue=true&locale=en&slack-enabled=true","startTime":1045.7000000476837,"connectEnd":1045.7000000476837,"connectStart":1045.7000000476837,"domainLookupEnd":1045.7000000476837,"domainLookupStart":1045.7000000476837,"fetchStart":1045.7000000476837,"redirectEnd":0,"redirectStart":0,"requestStart":1045.7000000476837,"responseEnd":1181.3999999761581,"responseStart":1181.3999999761581,"secureConnectionStart":1045.7000000476837},{"duration":127.69999992847443,"initiatorType":"script","name":"https://www.google-analytics.com/analytics.js","startTime":1078.7000000476837,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":1078.7000000476837,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":1206.3999999761581,"responseStart":0,"secureConnectionStart":0},{"duration":70.70000004768372,"initiatorType":"xmlhttprequest","name":"https://jira.mariadb.org/rest/webResources/1.0/resources","startTime":1205.3999999761581,"connectEnd":1205.3999999761581,"connectStart":1205.3999999761581,"domainLookupEnd":1205.3999999761581,"domainLookupStart":1205.3999999761581,"fetchStart":1205.3999999761581,"redirectEnd":0,"redirectStart":0,"requestStart":1205.3999999761581,"responseEnd":1276.1000000238419,"responseStart":1276.1000000238419,"secureConnectionStart":1205.3999999761581}],"fetchStart":0,"domainLookupStart":0,"domainLookupEnd":0,"connectStart":0,"connectEnd":0,"requestStart":166,"responseStart":333,"responseEnd":334,"domLoading":335,"domInteractive":1277,"domContentLoadedEventStart":1277,"domContentLoadedEventEnd":1316,"domComplete":1394,"loadEventStart":1394,"loadEventEnd":1394,"userAgent":"Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)","marks":[{"name":"bigPipe.sidebar-id.start","time":1247.2999999523163},{"name":"bigPipe.sidebar-id.end","time":1248.1000000238419},{"name":"bigPipe.activity-panel-pipe-id.start","time":1248.2000000476837},{"name":"bigPipe.activity-panel-pipe-id.end","time":1249.5},{"name":"activityTabFullyLoaded","time":1334.7000000476837}],"measures":[],"correlationId":"6ea81275043610","effectiveType":"4g","downlink":9.4,"rtt":0,"serverDuration":104,"dbReadsTimeInMs":14,"dbConnsTimeInMs":22,"applicationHash":"9d11dbea5f4be3d4cc21f03a88dd11d8c8687422","experiments":[]}}
Thank you for the patch!