i'm writing a query that need UNION and hql doesn't support it. So the only workaround is to use standrad SQL query but the problem is i can't use it in iReport if i use hibernate.
There is a way to use sql in iReport with an hibernate connection?
Thanks.
Use a View. See this: Hibernate Union alternatives
Related
We are using django and sql, so we have written query in sql , here my request is how can I convert sql query to django query.Please let me know
You can use ModelName.objects.raw() to run SQL queries which will return model Instances.
Refer: https://docs.djangoproject.com/en/2.2/topics/db/sql/
or to execute directly from Database import connections from django.db.
Refer:https://docs.djangoproject.com/en/2.2/topics/db/sql/#executing-custom-sql-directly
Note: Django ORM is secure than normal SQL. If using raw SQL queries read docs on how to make raw SQL queries secure.
I am working on hadoop hive solutions. My requirement is to convert ansi sql queries to hive queries by using a tool or excel macro. Is there any tool/macro exist? if yes, what are they; if not need suggestions to implement it. Is this possible? Do we have alternative sql queries in Hive for DMLs (like insert,update ... )? What are the pros and cons?
Any suggestions is highly appreciated....
I do not think that whole ANSI sql can be ported to hive because it does not support joins different from equ-join. So such SQL can not be ported.
Another point - there is no updates in hive - data is read only...
The rest looks very similar to ANSI SQL and I would suggest to try running queries as-is.
I perform selects with linq to sql in my app and other things (insert,update,delete) by traditional sql syntax.
But, when I insert or delete something, my datacontext doesn't update. So, if I search for the ID of selected object, an empty query returns. I checked the DB and I'm sure that sql syntax works fine.
In short, when I do something with my DB with sql syntax it changes my db but not the DataContext instance!
Are you saving the data? E.g. calling Context.SaveChanges() or whatever the equivalent is?
Link to SQL DataContext have a cache system. Look at the DataContext.Refresh method group for methods to refresh your entities. Another simple solution is to reinstanciate your DataContext after doing some raw SQL.
If you want to use Linq to Sql you should do all operations with that,It means if you want to do some raw Sql still you should use Linq to Sql syntax if not your link to data base won't update.
So I switched to Linq to Sql completely.
Thanks All
Useful info : http://blogs.msdn.com/b/adonet/archive/2011/01/27/using-dbcontext-in-ef-feature-ctp5-part-1-introduction-and-model.aspx
I am new to LINQ and just wanna know; is there any application in which I type standard SQL and it gives me its representing statement in linq?
Previous SO on similar topic:
SQL to LINQ Tool
I am trying to execute a query against a MySQL database.
The query is fairly complex it has 5 inner joins, including 1 join to itself and
it returns 3 pieces of information from 2 different tables.
We are using hibernate and till now I have used it for simple queries only.
I have written the sql query and tested it too. I am wondering how to implement this using
hibernate, can I execute plain sql statements with hibernate? If so what do I need, a separate hbm.xml?
If I use hibernate and execute the plain sql query can I still utilize caching later on?
Yes, you can execute plain SQL queries with Hibernate.
No, you don't need a separate hbm.xml mapping file (unless you WANT to separate sql queries from the rest, in which case you can do so). You can map your named SQL query the same way you do with named HQL queries.
Whether you will be able to "utilize caching" depends on what exactly you understand by "caching" and how you're going to map your SQL query; it's impossible to answer without knowing more details.
All that said, you may not need to resort to SQL query; HQL is quite powerful and it may very well be possible (assuming appropriate mappings exist) to write your query as HQL. Can you post relevant mappings / schemas and your SQL query?
I strongly recommend criteria queries over HQL queries. They are much closer to your program code without sacrificing any expression power. They DO however depend on relations to be explicitly mapped, otherwise they get quite complicated.
To speed up development, set property hibernate.show_sql=true, and play with the system in the debugger, using the "reload modified class" and "drop stack frame" features of the IDE+jvm until the SQL emitted looks like the one you've posted.