Hello guys, What we need is two things:
1. check the <class>, <subclass>, <joined-subclass> mapping etc. against the database 2. check if the namedQueries are valid This stuff should be: - as correct as possible/necessary - as fast as possible/necessary ...but most important as usable and maintainable as possible! Using some clear mechanism to fetch out the correct sql for named sql queries or hibernate queries is to fragile IMHO Secondly, doing a find for each and every mapped class would be timeconsuming and not very usable since we would only be able to say: "bummer - your query xxx failed with error yyy" where yyy could be something as (un)usable as "ORA-00942: table or view not found" which does not help the user to identify which table is missing simply that something is wrong.... Thus I propose instead for each of the items above: Use JDBC metadata to verify if the table and columns are in the database (and they have the proper type etc.) Utilize the features/code in the mapping package or maybe even easier refactor SchemaExport to be able to check the existence of items (it already has the code for traversing the compiled model in SessionFactory to generate sql - so it should be quite easy to make it look up stuff in DatabaseMetaData). Doing that would allow us to precisly report any mapping "mismatches". Like: "Property 'name' of class 'Person' cannot be found on table 'A_PERSON'" instead of the unusable "ORA-009242" It will also be quite maintainable since it would be using schemaexport code (hopefully) Checking namedqueries should *not* be done by executing them - they could possible execute triggers and if they are wrong they could be doing other malicous stuff - even though you would do 1=0 to "trick" them to behave. IMHO we should simply just compile named hql queries and see if the HQL parser complains. If not - then we assume they are valid. Regarding sql queries it's harder - I would rather go for trying a way to "compile" them too and make it be better to report possible errors. That's my 2 cents - and I surely look forward for a hbmlint ;) Best regards, Max Rydahl Andersen mailto:[EMAIL PROTECTED] www.hibernate.org Tuesday, June 29, 2004, 1:02:02 PM, you wrote: > Emmanuel Bernard wrote: >> I don't see how HQL query can insert update delete. Even a trigger >> cannot do that. > I meant namedsqlqueries, but in the future, it could be possible to be > used for inserting / updating data. I don't know if hibernate is going > to go that way.. > Remember that I won't load any entity for real (1=0). > I know.. >> We could add the keyword in Dialect, but let's start with the HQL >> queries first. I'm not sure the syntaxt is always >> SPEIFIC_KEYWORD<select> on every DB. > I'm not sure either, but it doesn't have to be explain. It just needs to > be some way to check a query. And if the db does not support something > similar, you can just ignore it. frequently used databases support it, > so i think it's nice to add it. >> >> Joris Verschoor wrote: >> >>> compiling named queries only checks hql / mapping (sometimes hql is >>> correct, but the query it generates is not supported on the db) >>> NamedQueries can not only be heavy, but can also destroy / insert / >>> update data. >>> Maybe there we could add some sort of getCheckSyntaxString(String >>> queryString) to Dialect >>> This would allow checking on databases that support things like >>> explain (or maybe some other query that can be used to check a syntax) >>> If that's done, you can also check the sql syntax of the hql >>> namedqueries >>> >>> >>> Emmanuel Bernard wrote: >>> >>>> "from A as a where 1=0" should check the DB fields easily wo any >>>> data size drawbacks. >>>> For SQL Query this is a bit more complex because queries may be >>>> heavy, so we can't execute them for real. I'm not sure EXPLAIN is >>>> really portable. >>>> >>>> So to sumarize: >>>> - Compile all mapping documents to metamodel, check for persistent >>>> classes => building the sessionFactory should do the job. >>>> - Compile all named queries => OK except for SQL ones >>>> - Validate the database schema by querying each table or something >>>> => Shouldn't be too hard with the "from A as a where 1=0" >>>> >>>> >>>> >>>> Joris Verschoor wrote: >>>> >>>>> Hi, >>>>> >>>>> I've created that patch. The code in the ant task was all I could >>>>> think >>>>> of... >>>>> >>>>> A check for database fields would be quite nice actually, when working >>>>> on several machines, I sometimes forget to modify a table. >>>>> That could be done by doing a find on every perstisted class (load >>>>> will >>>>> throw an error when it's not foud), and checking the exceptions >>>>> >>>>> Another thing that's missing is checking the named sql queries >>>>> (getNamedSQLQueries) >>>>> Because of all dialects, the queries have to be executed. >>>>> Maybe an EXPLAIN <SQL> would do, or a TX <SQL> rollback >>>>> But it doesn't feel right.. >>>>> >>>>> >>>>> >>>>> >>>>> >>>>> Emmanuel Bernard wrote: >>>>> >>>>>> Actually the ant task wrapping is done and just call for a session >>>>>> factory build. Do you think it's enough? >>>>>> >>>>>> Christian Bauer wrote: >>>>>> >>>>>>> >>>>>>> On Jun 28, 2004, at 6:27 PM, Emmanuel Bernard wrote: >>>>>>> >>>>>>>> I would be ready to apply the YAGNI principle and not provide >>>>>>>> such param (yet). >>>>>>>> What do you guys think? >>>>>>> >>>>>>> >>>>>>> >>>>>>> >>>>>>> >>>>>>> >>>>>>> >>>>>>> I think it should be configurable. I've heard one or two requests >>>>>>> for a "mapping validation tool" that you could run independently >>>>>>> from Hibernate. It might be possible that we isolate such >>>>>>> functionality, or at least, wrap it in an Ant task or something. >>>>>>> >>>>>> >>>>> >>>>> >>>>> >>>>> >>>>> ------------------------------------------------------- >>>>> This SF.Net email sponsored by Black Hat Briefings & Training. >>>>> Attend Black Hat Briefings & Training, Las Vegas July 24-29 - >>>>> digital self defense, top technical experts, no vendor pitches, >>>>> unmatched networking opportunities. Visit www.blackhat.com >>>>> _______________________________________________ >>>>> hibernate-devel mailing list >>>>> [EMAIL PROTECTED] >>>>> https://lists.sourceforge.net/lists/listinfo/hibernate-devel >>>>> >>>> >>>> >>>> ------------------------------------------------------- >>>> This SF.Net email sponsored by Black Hat Briefings & Training. >>>> Attend Black Hat Briefings & Training, Las Vegas July 24-29 - >>>> digital self defense, top technical experts, no vendor pitches, >>>> unmatched networking opportunities. Visit www.blackhat.com >>>> _______________________________________________ >>>> hibernate-devel mailing list >>>> [EMAIL PROTECTED] >>>> https://lists.sourceforge.net/lists/listinfo/hibernate-devel >>>> >>>> >>> >>> >>> >>> ------------------------------------------------------- >>> This SF.Net email sponsored by Black Hat Briefings & Training. >>> Attend Black Hat Briefings & Training, Las Vegas July 24-29 - digital >>> self defense, top technical experts, no vendor pitches, unmatched >>> networking opportunities. Visit www.blackhat.com >>> _______________________________________________ >>> hibernate-devel mailing list >>> [EMAIL PROTECTED] >>> https://lists.sourceforge.net/lists/listinfo/hibernate-devel >>> >> >> >> ------------------------------------------------------- >> This SF.Net email sponsored by Black Hat Briefings & Training. >> Attend Black Hat Briefings & Training, Las Vegas July 24-29 - digital >> self defense, top technical experts, no vendor pitches, unmatched >> networking opportunities. Visit www.blackhat.com >> _______________________________________________ >> hibernate-devel mailing list >> [EMAIL PROTECTED] >> https://lists.sourceforge.net/lists/listinfo/hibernate-devel >> >> > ------------------------------------------------------- > This SF.Net email sponsored by Black Hat Briefings & Training. > Attend Black Hat Briefings & Training, Las Vegas July 24-29 - > digital self defense, top technical experts, no vendor pitches, > unmatched networking opportunities. Visit www.blackhat.com > _______________________________________________ > hibernate-devel mailing list > [EMAIL PROTECTED] > https://lists.sourceforge.net/lists/listinfo/hibernate-devel -- Best regards, Max Rydahl Andersen mailto:[EMAIL PROTECTED] www.hibernate.org ------------------------------------------------------- This SF.Net email sponsored by Black Hat Briefings & Training. Attend Black Hat Briefings & Training, Las Vegas July 24-29 - digital self defense, top technical experts, no vendor pitches, unmatched networking opportunities. Visit www.blackhat.com _______________________________________________ hibernate-devel mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/hibernate-devel