Closed phdbutbachelor closed 1 year ago
Did you register the function in Hibernate as well?
To be honest, I didn’t even remember that Jinq had this functionality, so I could be mistaking things, but after dumpster diving through the code, I did find this code snippet that seems to register a SQL function in Hibernate:
{
Query q = session.createNativeQuery("CREATE FUNCTION isRegexMatch( str VARCHAR(200), regex VARCHAR(200) ) RETURNS INTEGER LANGUAGE JAVA PARAMETER STYLE JAVA NO SQL EXTERNAL NAME 'org.jinq.hibernate.CreateHibernateDb.isRegexMatch_DbFunction' ");
q.executeUpdate();
}
Or maybe not? To be honest, I no longer remember exactly how any of this works. If you can’t figure it out, let me know and I can look more deeply into the code.
Actually, maybe you don’t need to register anything. Yeah, I don’t know. I don’t even remember implementing this functionality, let alone whether I tested it with a database other than Apache Derby.
This page here
https://thorben-janssen.com/database-functions/
Seems to say that if Hibernate can’t figure out how to type a function, you may need to register the types with Hibernate using some messy process.
Sorry, I misunderstood the usage of registerCustomSqlFunction, I already solved this problem.
I'm trying to add the MySQL customer function into jinq. I defined the function in database as:
then I registerd it into jinq as:
and used it like:
then the program threw exception below:
I don't know what's wrong with my code, it seems that generated sql "SELECT function('date_formatter', A.createTime, '%Y%m%d')" is illegal for "select date_formatter(A.createTime, '%Y%m%d')" is the correct one?