Having played with Linq (to SQL and Objects) as well as the Entity Framework from Microsoft recently, I was wondering what the non-.Net (specifically Java) equivalents are?
-
2For Linq to objects check this one: github.com/nicholas22/jpropel-light, real example:new String[] { "james", "john", "john", "eddie" }.where(startsWith("j")).toList().distinct();– NT_Oct 8, 2011 at 10:20
8 Answers
Consider using Querydsl : http://www.querydsl.com
It supports JPA/Hibernate, JDO, SQL and Collections.
Querydsl is fully type-safe, supports autocomplete in IDEs and provides a common querying syntax on top multiple backends.
I am the maintainer of Querydsl, and I wrote a comparison to other frameworks some time ago.
It is slightly biased, but shows the different emphasis
- statically typed or not
- which backends are supported
- is the interface for query construction cascading or not
Newer frameworks experiment also with closure syntax.
-
1Why is this being flagged as spam? As far as I can see answers the question.– YacobyMay 16, 2010 at 10:00
-
@Yacoby, see meta.stackexchange.com/questions/50038/… (which has been resolved by Timo nicely, in my opinion)– ArjanMay 16, 2010 at 12:57
There is a Java project called JoSQL which provides object querying capabilities with a SQL-like syntax.
While I haven't used it myself, I know that it is used in some heavyweight applications.
-
This looks pretty interesting. It's not a database tool, but a way to use SQL to operate on Java objects (like LINQ to Objects). Jul 5, 2009 at 5:15
Java does not have a Linq equivalent. However Scala, a functional language that compiles to Java byte code, has something closes: an extended for loop syntax.
For database-heavy work, SQLJ might be an option. The downside is it's not pure Java and requires a pre-processor.
For LINQ (LINQ to Objects to be more accurate) you can use Streams starting from Java 8
This doesn't work for databases however, only for internal objects like Collections and Lists
It is really powerfull, but not as complete as LINQ (in my opinion)
Check out this tutorial - http://www.oracle.com/technetwork/articles/java/ma14-java-se-8-streams-2177646.html
As for Entity Framework there is nothing quite as powerful that I have found yet, but haven't tried all the solutions provided in the other answers
You won't find an equivalent of LINQ unless you use the javacc to create your own equivalent.
Until that day when someone finds a viable way to do so, there are some good alternatives, such as
There is no exact alternative which is universal as LINQ is. However if we are talking about LINQ to SQL then JPA is really an alternative when you use it with an IDE that supports "Inject language" feature. E.g. IDEA will do full scale completion of the JPA query within a string