Not possible using NHibernate? - mysql

I am new learner to NHibernate. I am trying out samples with MSSQL database. We all know query using MSSQL is different from MYSQL database. If i need to use this sample for MYSQL, do i need to change anything other than configuration settings? Also i need to know is there anything that is not possible because of NHibernate?

There are multiple ways of configuring NHibernate.
What you need to set is called:
The dialect is responsible for converting IQueryable, ICriteria or so called HQL (hibernate query language) to the SQL of the corresponding database.
But if you want to have this general, you must pay attention to the ID (in some cases even use locking). SQL has so called auto-identity, while Oracle works with sequencers. But NHibernate has it's own ways of generating identity.
I would advise you to:
use latest NHibernate (not older than 3.3.x.x)
try out fluent nhibernate mapping
eventually find some example on nhibernate + fluent + unity/structure map (DI framework) - mostly you find something related to DDD projects

Related

I am getting error with native query when I shift from mysql to mongodb [duplicate]

After seeing this image:
http://2.bp.blogspot.com/_T-uXeKcGTnM/TIdoKBGwk9I/AAAAAAAABcs/CLW3_cRlN78/s1600/tumblr_kxovt0VLZy1qappj8.png
I wonder is exists any tool for translating SQL querys into MongoDB map/reduce query model??
Larger version of the image: http://rickosborne.org/download/SQL-to-MongoDB.pdf
Update to the question asked in Jan 2011:
A couple of sites exist now to convert sql to mongodb.
Convert MySQL Queries to MongoDB Syntax
http://www.querymongo.com/
And
Convert sql to mongodb
http://klaus.dk/sqltomongodb/
The simple anwser? No.
The slightly more complex anwser is some people have had luck translating more complex SQL to Mapreduce functions ...
http://rickosborne.org/blog/index.php/2010/02/08/playing-around-with-mongodb-and-mapreduce-functions/
http://rickosborne.org/blog/index.php/2010/02/19/yes-virginia-thats-automated-sql-to-mongodb-mapreduce/
However, that said ... generally speaking you might as well learn mapreduce properly because if the data is in MongoDB already ... you'll really need to know how to properly query MongoDB to get anything meaningful done!
MongoDB has wonderful and helpful docs http://www.mongodb.org/display/DOCS/Advanced+Queries
As well as an easy to use online tutorial: http://try.mongodb.org/
The simple answer: Yes. Hibernate OGM - JPA for NoSQL.
JPA is Java API for mapping objects to data stores.
It includes JPQL, a query language similar to SQL which adds the OOP concepts. It's not SQL, but you don't want pure SQL - that was designed for the relational paradigm.
Hibernate OGM proposes to simplify the programming model by embracing JPA/Hibernate APIs and semantics to store data in NoSQL stores like JBoss Enterprise Data Grid instead of the traditional RDBMS. (source)
Also see this Hibernate OGM: JPA for NoSQL talk by Hardy Ferentschik
Recently I happened to see this website mongoquery.com, you can try it.
You can use free sql to mongodb converter like: https://rapidapi.com/ariefsam/api/easy-sql-to-mongodb-aggregation/
Just to add to the last comment
re:The simple answer: Yes. Hibernate OGM - JPA for NoSQL.
JPA is Java API for mapping objects to data stores.
It includes JPQL, a query language similar to SQL which adds the OOP concepts. It's not SQL, but you don't want pure SQL - that was designed for the relational paradigm.
There is a company called UnityJDBC that has released a JDBC driver for Mongo that allows you to run SQL queries against mongo in any java application that supports JDBC.
you can download this driver free at
http://www.unityjdbc.com/mongojdbc/mongo_jdbc.php
hope this helps
You can also http://teiid.org which gives full range of SQL based access to MongoDB. You can use SQL through JDBC/ODBC or use REST/ODATA based access to MongoDB. Teiid uses MongoDB's aggregation framework to provide advanced SQL MongoDB query conversation.

Connecting to other database types in the 2sxc module

Is there currently anything in the 2sxc module that allows you to connect to other database types? Specifically I would like to connect to a MySQL database. I know you can connect to other tables within the database.
This depends a bit on your question. Let's split
Can you use Razor-Views in 2sxc to visualize data from any kind of database?
Yes, just use c# code to get the data. Just create the sql-objects or whatever in .net and use that. For example, I wrote about using PetaPoco http://2sxc.org/en/docs/docs/feature/feature/2583
Can you use non-sql-data in your Visual Query Designer
Yes, but you'll have to work a bit. The easiest way is to map your my-sql tables in the DNN SQL server. This is a bit like a translation layer, which then let's use use them as if they were in the SQL Server.
A harder way is to create your own data source. Best to inherit the SqlDataSource (which provides a lot of security around parameter injection etc.) https://github.com/2sic/eav-server/blob/master/ToSic.Eav.DataSources/SqlDataSource.cs - and then modify it to use your mysql

grails/gorm/mysql/hibernate

I have a simples question. I have been trying to learn Grails by my own, and i managed to do a simple application using Grails/Gorm.
1 ) Later, i decided to use Mysql instead of Gorm - i just needed to configure the 'DataSource' and download the driver.
2 )So if i want to use hibernate between both (Grails and MYSQL) like this:
http://www.grails.org/doc/latest/guide/15.%20Grails%20and%20Hibernate.html, i need to make an 'hibernate.cfg.xml' file, and specify my mysql database url, user, pw etc .. and i have to map each Class in Grails for MySql columns.
So what is the diference between 1) and 2) ? and what exactly hibernate does. Give examples if possible
PS. Please correct me if i said something wrong, im kinda new to this
I think you are a bit confused here.
GORM is not a database, it is a ORM that maps you Groovy classes to database tables. It uses Hibernate under the covers to achieve this (Hibernate is also an ORM).
The default database Grails uses is an in-memory HSQL DB. If you want to use MySQL instead of that, all you need to do is change the settings in conf/DataSource.groovy.
You don't need to create any Hibernate xml files. That part of the documentation you've linked to is to allow people with existing Hibernate domain models to easily re-use them.
Hope this helps clear things up.
cheers
Lee

Database portability (sql server to mysql, postgresql)

I am working on a business app (asp.net). Right now I am using sql server. But I plan to support at least mysql and postgresql down the road.
What are the issues that I should consider to avoid future headaches? Especially about datatypes (column types). E.g. I think BIT column is not supported on some dbs so I use tinyint?
I mostly use plain sql (no entity framework or linq, etc) and try to keep it as simple as I can.
I am NOT using things like triggers, etc.
I do use stored procedures but they can be replaced with plain sql if I have to.
Your only hope is to separate data access into a proper data access layer, as Remus Rusanu suggests. The data access layer can have one consistent interface to the rest of your code, and be changed out for other versions for each DB platform. Keeping the SQL fairly standard will help, but it's not really possible to write one body of SQL code and have it work everywhere (the SQL standard isn't that well implemented.)
Consider (with some costs in term of learning curve) the adoption of a Domain Model and a data access layer based on an OR/M like NHibernate (https://www.hibernate.org/343.html)
Make sure you write all your client code using the abstract IDbConnection, IDbCommand, IDataReader instead of the concrete. You will also have to keep your SQL statements in check all the time to ensure you use only compatible syntax.
You can also try connecting via the OdbcConnection/OdbcCommand components and use generic ODBC syntax and generic ODBC data types (ie. the {fn SUBSTRING(...)} stuff, aka. the ODBC Escaped Syntax).
As an alternative what I prefer to do is to isolate the data access and create specific DAL classes for each back end. I use XML and XSLT to generate the DAL code. Similar to this the technique of integrating XSLT code generation from my blog, but with XSLTs geared specifically for each back-end specific code.

Pattern for compile time discovery of unsafe/wrong queries

My team is developing a large java application which extensively queries a MySQL database (in different classes and modules).
I'd like to known if there is a pattern that allows me to be notified at compile time if there are queries that refer to a wrong table structure (for instance if I remove or add a field on a table and the query string refers to it), in order to prevent runtime errors.
This should work also for JOIN queries.
Querydsl is similar to LiquidForm and supports both JPA / Hibernate and SQL based backends.
For the SQL based version we currently support MySQL (5.? tested), Oracle (10g tested) and HSQLDB.
In a nutshell a query like this
select count(*) from test where name = null
would become
long count = query.from(test).where(test.name.isnull()).count();
Querydsl SQL uses code generation to reflect SQL schemas into Java classes.
There's an open-source tool called DODS (Data Object Design Studio) that could do what you want. The DODS tool was originally part of the Enhydra Java application server project, and since the company backing that project went kablooey in 2002, DODS has been hosted and maintained at ObjectWeb. Anyway, it's open-source (LGPL).
http://forge.objectweb.org/projects/dods
The concept is that you describe your schema in an XML file, and DODS generates Java POJO classes with which you can query and manipulate the database tables. Of course every time you change your schema, you need to run DODS again to re-generate the ORM classes, and recompile your app against them.
But the result is that if a table or column disappears, and your app is querying database metadata that no longer exists, you do get a compile-time error, because your code is now calling a corresponding class or method that no longer exists.
I would say that the simple answer is "no". The more complete answer is "yes, to some degree", depending on your willingness to jump through hoops.
Unless you have a java representation of your database schema you will never be able to get compile time notification if your queries are wrong (these classes can be generated). Also, you must use these classes to build your queries, so the method you use today (query strings) must be abandoned. To be able to use the java classes to build your queries, you must also use tricks. LiquidForm uses the required tricks to build JPA queries, but I have not seen a similar library for constructing SQL queries (LiquidForm is new and quite brilliant). You would actually have to build a similar library yourself. So, as you see, getting compile time warnings when constructing SQLs is hard, but not impossible (only nearly impossible). But even if you should be able to create what I suggest, your java representation of the schema must be updated immediately after a schema change, so the generation of java classes would have to be built into your IDE or build tool.
I would suggest you rather have good unit tests that will notice when your queries become illegal as a result of schema change. This is the most common way to achieve what you want. Also, should you decide to "upgrade" to JPA, you could use LiquidForm to get what you want.