This did not work as says it cannot find the partnumber field on CatalogHitCountObject, which is correct, it does not exist (and I messed up the query in the conversion).
The only solution I now find to get it working, is to create the partnumber field on the CatalogHitCountObject with the annotation
Thanks, but for both examples I get the same error:
Error: 1052-23000: Column ‘partnumber’ in field list is ambiguous
case #1
java.lang.Exception: Records Not Updated : org.hibernate.exception.ConstraintViolationException: JDBC exception executing SQL [update cataloghitcounts chcdo1_0 join catalog cd1_0 on cd1_0.partnumber=chcdo1_0.partnumber set partnumber=? where cd1_0.partnumber=?] [(conn=115) Column ‘partnumber’ in field list is ambiguous] [n/a]
case #2
java.lang.Exception: Records Not Updated : org.hibernate.exception.ConstraintViolationException: JDBC exception executing SQL [update cataloghitcounts chcdo1_0 join catalog cd1_0 on cd1_0.partnumber=chcdo1_0.partnumber set partnumber=? where chcdo1_0.partnumber=?] [(conn=115) Column ‘partnumber’ in field list is ambiguous] [n/a]
I am trying to update the CatalogHitCountObject partnumber
field, not the CatalogueObject partnumber field.
CatalogHitCountObject @Table(name = “cataloghitcounts”)
1 id Primary varchar(48)
2 partnumber Index varchar(48)
3 username Index varchar(255)
This is a bug. Please try to create a reproducer with our test case template and if you are able to reproduce the issue, create a bug ticket in our issue tracker and attach that reproducer.
Well my Jira ticket got closed. I did some more testing and it does work in the producer.
On my system I get this for the query:
query = “update HitCount c set c.catalogue.id=:newPartnumber where c.catalogue.id=:partnumber”;
Hibernate:
update
cataloghitcounts chcdo1_0
join
catalogue cd1_0
on cd1_0.partnumber=chcdo1_0.partnumber
set
partnumber=?
where
cd1_0.partnumber=?
[ WARN] (ajp-nio-127.0.0.1-8009-exec-6) Error: 1052-23000: Column ‘partnumber’ in field list is ambiguous
========
The producer for the query:
query = “update HitCount set catalogue.id=:newPartnumber where catalogue.id=:partnumber”;
Hibernate:
merge
into
HitCount as t
using (
select
cast(? as varchar),
hc1_0._rowid_ from
HitCount hc1_0
join
Catalogue c1_0
on c1_0.partNumber=hc1_0.partNumber
where
c1_0.partNumber=?
) s(c0, c1)
on t._rowid_=s.c1
when matched
then update set
t.partNumber=s.c0
The fact that the queries are different had me concerned.
The producer is jakarta.persistence.EntityManagerFactory whilst we are using org.hibernate.SessionFactory via spring: org.springframework.orm.hibernate5.LocalSessionFactoryBean.
Reading up, the spring hibernate5 classes should be migrated to JPA style configs but I cannot find much info on how to do this migration.
I would have thought by now this would be a well trodden path.
The jakarta.persistence package contains just interfaces, Hibernate ORM is the implementation. You can code against these interfaces if you want, since that is more “portable”, but you can also stick to Hibernate ORM classes directly if you prefer and want to leverage Hibernate specific features.
After some debugging it looks like its todo with the dialect. The ORMUnitTestCase test case uses org.hibernate.dialect.H2Dialect. I am not setting a dialect since HHH90000025, and my junit test uses class MariaDBSqlAstTranslator class to work out the statement. The reason why the sql statements are different.
If I change my junit test to H2Dialect I get the same sql as the producer (but does not work due to the syntax and database mismatch):
Hibernate:
merge
into
hitcount as t
using (
select
cast(? as varchar(255)),
chcdo1_0._rowid_ from
hitcount chcdo1_0
join
catalogue cd1_0
on cd1_0.partnumber=chcdo1_0.partnumber
where
cd1_0.partnumber=?
) s(c0, c1)
on t._rowid_=s.c1
when matched
then update set
t.partnumber=s.c0
[main] WARN org.mariadb.jdbc.message.server.ErrorPacket - Error: 1064-42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'merge into hitcount as t using (select cast('TestPartNumberJunit1Rena...' at line 1
If I update the producer to my use my mariadb (rather than org.h2.Driver) I get the same sql statement and error as my junit:
Hibernate:
update
HitCount hc1_0
join
Catalogue c1_0
on c1_0.partNumber=hc1_0.partNumber
set
partNumber=?
where
c1_0.partNumber=?
2024-11-21 09:56:12 WARN SqlExceptionHelper:145 - SQL Error: 1052, SQLState: 23000
2024-11-21 09:56:12 ERROR SqlExceptionHelper:150 - (conn=114) Column 'partNumber' in field list is ambiguous
Luckily I only have one of these pojos so I guess I have to use my work around and add the column.
This is a bug on hibernate not supporting mariadb/mysql and others??