Everyone who programmed with C# knows that there is the Entity Framework as ORM (object-relational mapper) which enable programmer to query database using only C# code.
For example, if I have a database called Shop
, and in the Shop
database I have Products
table, i can get all product of Products
table where their price is less than 2 dollar in the following way:
ShopEntity _Db = new ShopEntity();
List<Product> products = _Db.Products.Where(p => p.Price < 2).ToList();
The above code is equivalent to this SQL statement:
Select * From Products Where Price < 2
I want to know is there any framework like that in Java?
I also saw quaere. But it just queries collections. I want to query against the database. There is another framework in java called Hibernate which does not provide good functionality for query the database.
In . NET, an easy way for you to simplify querying datasets is LINQ. Java doesn't have this, but since the introduction of Java 8 in 2014, you do now have the possibility to use "streams". Both LINQ and streams are ways to simplify querying datasets and to provide developers with an easy API to use.
nHibernate supports all types of databases but Entity framework need additional connectors to support databases other than MSSQL. nHibernate can be extended in terms of data loading, SQL generation, custom column types, custom collections etc but entity framework has limited extension points.
EF Core can use a ROWVERSION/TIMESTAMP column on SQL Server, or any of a list of columns, when updating a record. NHibernate offers richer capabilities, besides SQL Server ROWVERSION/TIMESTAMP, it can also use database native mechanisms such as Oracle's ORA_ROWSCN, but also timestamp or version columns.
The standard ORM API in Java it's called JPA, and is part of the Java EE specification. Another alternative would be to use Hibernate. Both provide their own query language (JPQL and HQL respectively), but no query framework exists under Java that provides a direct integration at the language level the way LINQ does for C#.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With