greeting Lucee-ites. I am having a very strange is...
# lucee
m
greeting Lucee-ites. I am having a very strange issue in Lucee, with MSSQL server, and using either the (deprecated) JDBC driver, or the Microsoft JDBC extension. (These appear to be the only two options). When retrieving a country from our
Countries
table, we have an NCHAR(2) field for isoAlpha2 country codes (e.g.,
US
or
DZ
or
EN
, etc.). However, when I select a single country using ORM (e.g.
c = EntityLoadByPK("Country", 220);
) the isoAlpha2 value comes back TRUNCATED to just a single letter (
U
or
D
or
E
). As mentioned, I've tried the (deprecated) JDBC driver that comes with Lucee as well as the Microsoft JDBC extension. This same select / retrieval works fine in the Adobe CF version of the app that we are migrating from. I have checked all the possible datasource settings, to no avail. Any advice on troubleshooting from here would be welcome.
p
What do you have as the cfsqltype in the Country object?
p
I work with Marc so I can comment. The properties of the Country object are simply
Copy code
property name="countryID" fieldtype="id" generator="identity";
property name="name";
property name="isoAlpha2";
p
Should assign it a sqlType=β€œnchar” or define the ormtype, for the column causing the issue.
e
What is the runlevel of your MSSQL server and language version as well as patch level. I ask as We have massive issues with SQL Server 2014 on a couple of Win 2016 installs. The issue, oddly enough went away by moving the very same code to SQL server 2019, same DB run level on Win 2019
p
With the full path it knows the exact
countries
object to use, with just the object name it must search for one which it could be finding a different one possibly? Thats one theory. But did you try to just change the
sqltype=
value to what you need it to be for that column?
m
if i modify the databse so that it's just a CHAR(2) field, both return the correct value.
i have not tried changing the sqltype yet.
i will put the db back to nchar(2) and modify the component's property declaration now...
p
property name="isoAlpha2" sqltype="char";
or string or whatever
m
yep. one moment...
adding a sqltype of EITHER
nchar
or
char
does not fix.
since i'm using a 100% clean app i just constructed this morning, there is no other
countries
table or object it could be finding.
and it appears to be just this datatype.
(so far)
p
but making that change in the object will require you to restart the app fyi
to reload the new/updated object when you make that sqltype change
m
i have an ORMReload() at the top of my template.
and all changes I have made this morning have been immediately recognized.
p
Ahh yea that would clear it then
Maybe try just setting it as a varchar prop
or the ormtype="string"
m
i'll publish my docker-compose later this morning that demonstrates it all for anyone to play with.
p
alright no prob; could be db related but with the minimal property config for the columns I was assuming it was that but it could relate to DB but I would confirm with those properties to define out your columns.
Also, be aware that sometimes Lucee can be caching your components which is why I prefer to restart the server or be sure to have that disabled during my development.
m
the issue is, while that may be the fix, it calls into question the entire codebase as converted from ColdFusion to Lucee, on something that should just work.
i feel confident I've eliminated all caching from the situation here. this is a demo app, the server is configured to read templates on every request, etc. And I can restart the server and reliably get the same results each time.
p
That is true, Lucee could have its issues in how it detects and sets what that column type is with that jdbc ext but I am not certain. Maybe check with @zackster who may have better insight on that.
z
ASL? πŸ™‚ what versions of lucee, extensions are you using. that's always the first question I'm ever going to ask
m
i have a demo docker-compose app that will answer all your questions πŸ˜ƒ
in the meantime, as i'm trying to finish that... I am putting the driver file/extension I downloaded --
org.lucee.mssql-8.4.1.jre8.lex
-- into the deploy directory of lucee, but I'm getting the following error when lucee starts up:
Copy code
"ERROR","main","09/21/2022","16:47:08","Extension","Unable to resolve org.lucee.mssql [57](R 57.0): missing requirement [org.lucee.mssql [57](R 57.0)] osgi.wiring.package; (osgi.wiring.package=org.bouncycastle.openssl) Unresolved requirements: [[org.lucee.mssql [57](R 57.0)] osgi.wiring.package; (osgi.wiring.package=org.bouncycastle.openssl)];lucee.runtime.exp.NativeException: Unable to resolve org.lucee.mssql [57](R 57.0): missing requirement [org.lucee.mssql [57](R 57.0)] osgi.wiring.package; (osgi.wiring.package=org.bouncycastle.openssl) Unresolved requirements: [[org.lucee.mssql [57](R 57.0)] osgi.wiring.package; (osgi.wiring.package=org.bouncycastle.openssl)]
        at org.apache.felix.framework.Felix.resolveBundleRevision(Felix.java:4368)
other extensions get installed just fine during the same build process.
once the container starts, I can go to the lucee admin and install the package via the Applications area.
the previous version of the sql server extension also installs without issue as far as I can tell.
e
in your Application.CFC, change all your double quotes to single quotes or all your single quotes to double quotes. It's stupid, but it's one of those gotchas.
m
why on earth should that matter?
P.S. the "datasources" block in my Application.cfc in my demo is a direct copy from the Lucee admin UI, so the mixed quoting is coming "straight from the horse's mouth" =D
P.S. this made no difference.
z
try scare quotes?
πŸ™‚
m
"maybe."
As promised, here is a quick Loom video that demonstrates the docker compose app uncovering the issue I've described.
p
property name="isoAlpha2" ormtype="string";
loads it as expected and same as example #2 which casts it as a string also
Objects should be fully defined out otherwise you are leaving it up to the orm engine to take a guess at what to cast it as. As to why your full table name gets it to work is another random issue but proper object creation you should define out your objects rather than allow auto detection of each column and type etc.
m
interesting. this code is a direct port from ACF, which never had this problem -- and it seems the ORM is capable of determining the right value so long as the table name is fully qualified, so do you think this is a shortcoming in the Hibernate layer/extension?
p
Yea and Lucee vs ACF and what orm engines they are running are another story. But for best compatibility just define out your objects. This could be a hibernate shortcoming but I am not certain what ACF utilizes either.
Either way, an engine being allowed to detect (with success) is a risk in my book
m
ok. thanks for the clarification. not sure we can commit to modifying an entire working codebase adding the additional parameters to cfproperty tags (and possibly injecting more issues in the process) but we will definitely give it some good discussion. Truly appreciate your time and insight.
p
No problem, anytime!
m
For anyone interested, i have an updated docker compose that demonstrates the issue and shows that it's not an issue with MariaDB.
kinda leaning towards this being a DB driver/extension issue.
e
The issue with your DEMO is your insert value for IsoAlpha2 is the US, which should be a VCHAR value, not an NCHAR value as NCHAR values reference ASCII values. You are, in effect truncating your truncating storage and not using it correctly. US. US in effect is 2 ASCII Values of 85,83. https://learn.microsoft.com/en-us/sql/t-sql/functions/nchar-transact-sql?view=sql-server-ver16
m
you may be right but for the wrong reason (especially since ACF can handle this without issue - this is strictly a Lucee / ORM / Hibernate issue). The page you linked to mentions database collation and the returning of a single character, which is damned spot on with regards to the behavior we're seeing. The field holds two characters, and the N simply allows extended character set (Unicode). again, this has worked forever in our ACF implementation and only broke when porting to Lucee.
e
I think its the opposite. AFC does a lot of hand-holding under the hood which is why 100 percent of my AFC code always works. When moving said code onto lucee, it breaks not because its LUCEE per say, its LUCEE isnt correcting anything I am doing. Instead, Lucee has forced me to dig deeper and write better functioning SQL Statements and other bits of code.
m
If i eliminate Lucee from the equation, and simply
select * from countries
using Azure Studio or SSMS or any other DB client, I get the correct results. There's no hand-holding going on, and I don't think I am mis-using the datatype on the field (though one could successfully argue that we aren't going to need unicode on that particular piece of data). I would expect to see single character retrieval from the database itself if what you've postulated were in play.
p
Appears its a hibernate bug for the version Lucee is using. Here is the bug ticket: https://hibernate.atlassian.net/browse/HHH-2304
Again, based on the autowiring casting it as a Character not a Char....so just need to define it with what I mentioned above
e
Open up SQL STUDIO, type in PRINT CHAR(85)+CHAR(83), that is what is being asked here. Database, Please SHOVE NCHAR (NUMBERIC VALUE CHARACTER) into DB table, Microsoft. OK, UM, Not a NUMBER, but WHO CARES Store "US" Now code, AFC bring me a result, AFC OK RESULT is US, LUCEE BRING ME THE SAME RESULT, LUCEE DB, How big are you 2 NUMBER CHARACTERS, LUCEE, OKAY, JAVA TELL ME WHAT IS 85 --"U" , LUCEE, HERE IS RESULT = "U"
PER MS Docs, NVAR DATA takes up 2 bytes per Unicode/Non-Unicode character
m
@Evil Ware by that logic, i should be able to go into the database, change the datatype to NCHAR(4) and i should get 2 characters back, right?
NCHAR is NOT "Numeric value character" - N is for internationalization - UNICODE character set.
MySQL has the same thing.
And patrick has nailed it for the win. It's appearing to be a hibernate bug. https://hibernate.atlassian.net/browse/HHH-2304 - possibly a regression ?
e
If you can read Unicode characters, Cool, as for the bug, dbo.table name works. table name only works as a DSN defined.