13 ms·
JOOQ: an alternative approach to traditional ORMs
- levosmetalo 11y agoLooked interesting until the moment I saw it's not free. Sorry, but in this day and year I'm not gonna consider using a piece of basic infrastructure that is not free and open source, at least not for something as fundamental as ORM layer.
- morgo 11y agoThat's not quite correct. It is free if your database is free (using Apache 2.0): http://www.jooq.org/download/ http://www.jooq.org/download/
- DoubleMalt 11y agoAnd if you sold your soul (I mean infrastructure) to oracle already, jOOQ is the least of your worries! Also supporting Oracle is a huge PITA. So charging for that is completely understandable :)
- moondowner 11y agoExactly, if you use an Open Source database (e.g. MariaDB or PostgreSQL) you'll be OK with the Open Source version of jOOQ.
- eropple 11y agoIt is "free" if you squint, but they kind of screw with you when you don't pay them, to the point where I ditched jOOQ entirely because I didn't feel like I could trust them to deal straight with me. They spam your application output like nagware unless you dig into the code for an undocumented flag (which has a really godawful guilt-trip comment next to it begging you to allow them to continue littering your logs with unparseable garbage that can't even be bothered to go through logback to be piped correctly) and they hide their unit tests (and are real jerks about them, calling them "an enterprise feature", when in reality they're both documentation and verification that the stuff they say works actually does work). It's their prerogative to do that, of course, but it's not behavior I'd support. Team's kind of shitty on Twitter, too, trolling around keyword searches and looking for a fight. I don't recommend its use, both from a "can I trust this" perspective as well as a "do I want to support these guys" one. If you can use Slick, I recommend it, as its developers have in my experience been uniformly solid people; I haven't needed either recently, as I've switched stacks for the project I was going to use one or the other for, but Slick's developers don't make me feel icky to support.
- deleted 11y ago[deleted]
- lukaseder 11y agoHow do you explain this to management?
- mgkimsal 11y agoIf you're already paying for a database (MS, Oracle, etc) then you're paying for another tool to work with that database. If you're using an open source database, you're using an open source tool. Not sure there's all that much to explain…?
- DasIch 11y agoThis looks suspiciously similar to SQLAlchemy[1]. [1]: http://www.sqlalchemy.org/ http://www.sqlalchemy.org/
- devy 11y agoSyntactically similar but in fact SQLAlchemy is the Hibernate for Python (because it adopts the data mapper pattern.)
- ZitchDog 11y agoThat is a gigantic compliment, given the restrictions of Java.
- DasIch 11y agoIt's just my first impression. The experience when using it may feel very different.
- mediumdave 11y ago> jOOQ is SQL-centric. Your database comes "first". This approach has always seemed completely backwards to me. Isn't the database simply a mechanism for persisting records/objects whose structure is determined by domain modeling? To me, it would make about as much to say of a GUI framework "foobarWidgets is GUI-centric. Your UI comes 'first'.", as though the application itself was just an afterthought. Don't get me wrong - I like SQL, and I happily use relational databases to store objects. I just see the database as a means, not an end.
- lukaseder 11y agoYour data will live for the next 30 years. Your UIs are replaced with every new fad. Do you think it is more important to thoroughly design your database or your client domain model? Of course, projects are different, and some projects are more user-centric, others are more data-centric, but chances are that you're successful and then you'll regret working with a horrible database schema that you didn't properly design 5 years ago, cause all you cared for were your fancy foobarWidgets that you implemented in a tech that no longer exists...
- matwood 11y ago> Your data will live for the next 30 years. Your UIs are replaced with every new fad. Do you think it is more important to thoroughly design your database or your client domain model? This cannot be repeated enough. It is an argument I have over and over with people who want to treat the database as a dumb store usually because they do not want to understand databases. Any successful software that stores or generates data will see that data live and used way beyond the original program. The database used will absolutely be the foundation multiple different pieces of software are built on.
- insulanian 11y ago10x this! I always get a shiver when I hear people saying "... and it just generates the DB for you...". DB is what I always start with and it shall stay so. BTW, is there some jOOQ equivalent for .NET? EntityFramework 7 is all about code-first, which I really don't like.
- critium 11y agoSorry if I did too much TL;DR but this reads very much like Apache Torque, which has been around for a very loooooooong time. https://db.apache.org/torque/torque-4.0/index.html https://db.apache.org/torque/torque-4.0/index.html Apache Torque is an object-relational mapper for java. In other words, Torque lets you access and manipulate data in a relational database using java objects. Unlike most other object-relational mappers, Torque does not use reflection to access user-provided classes, but it generates the necessary classes (including the Data Objects) from an XML schema describing the database layout. The XML file can either be written by hand or a starting point can be generated from an existing database. The XML schema can also be used to generate and execute a SQL script which creates all the tables in the database. As Torque hides database-specific implementation details, Torque makes an application independent of a specific database if no exotic features of the database are used. Usage of code generation eases the customization of the database layer, as you can override the generated methods and thus easily change their behavior. A modularized template structure allows inclusion of your own code generation templates during the code generation process.
- agentgt 11y agoThey are not the same and probably many modern ORM's share more in common with jOOQ than Torgue has in common with jOOQ. An example would be schema generation. jOOQ is reverse schema based. You make your schema with whatever schema evolution tools you like (Flyway is the most common) and then run the code generator. Torque is the opposite (notice they say starting point not final) not to mention its also XML based. Oh and jOOQ has an extremely powerful DSL that is close to 1-1 with SQL and whole bunch of reflection based conversion abilities (including dotted path data binding which I am happy to say I inspired the author of jOOQ to add :) )
- lukaseder 11y agoThat was a great steal. Thanks again for the idea, Adam! :)
- critium 11y agoTorque does code-gen as well. This was before any fancy tools so we basically just had hand generated DDL. https://db.apache.org/torque/torque-4.0/documentation/orm-reference/running-the-generator.html https://db.apache.org/torque/torque-4.0/documentation/orm-re... Regen, then fix compile issues. Thats how I used it a long long (10 years?) time ago. jOOQ DSL is nice, this is just as readable(ABC is a generated class) Criteria crit = new Criteria() .where(ABC.A, 1, Criteria.LESS_THAN) .and(ABC.B, 2, Criteria.GREATER_THAN) .or(ABC.A, 5, Criteria.GREATER_THAN); Working with XML, not the nicest thing, i do agree, but also not the worst thing. Not a flag-bearer in any way, but I just wanted to point out that if code-gen db access is your thing, there are also other tools to consider. It most certainly had its warts. Like issues handling complicated joins. Or more seriously, whos maintaining it. Its been a long time since i've look at it with any seriousness, not sure if they have fixed them or not. edit: formatting
- ahachete 11y agoI have been using jOOQ for quite some time. Indeed, it's the only mechanism (definitely not an ORM) to access the database that we use in my company. From my own experience, and this is general consensus, it's a big win to use it. Its SQL inspired fluent syntax brings you back the power of SQL, including really advanced stuff. But at the same time, in a Java native manner, type safe, by the way. If you haven't tried it yet, you definitely should.
- matwood 11y agoSame. jOOQ is great and makes dealing with databases from Java land simple. After dealing with some many hibernate WTF issues jOOQ was a breath of fresh air. I could finally write queries again using a simple DSL and get what I was expecting to happen.
- vtman2002 11y agoA fully open source equivalent: https://github.com/keredson/DKO https://github.com/keredson/DKO I wrote this for Two Sigma's internal use back in 2010.
- agentgt 11y agoI too wrote my own crappy (anti)ORM-like library a few years back as well https://github.com/agentgt/jirm https://github.com/agentgt/jirm . The most notably difference from other libraries was focusing on immutable objects and embracing real SQL (not a DSL like jOOQ) using a better SQL template language (instead of the JDBC '?') https://github.com/agentgt/jirm/blob/master/jirm-core/README.md https://github.com/agentgt/jirm/blob/master/jirm-core/README... . I guess the closest library would be MyBatis. The problem with writing your own library is the massive and continuous support that is required. This is where I eventually gave in and used jOOQ. Its an extremely well maintained and documented library. People complain about it not being completely opensource but neither is intellij so I don't have a problem (as well I also only use opensource databases).
- vtman2002 11y agoMassive and continual support? That has not been my experience. Even after leaving TS, it looks like Lynch (who took over internal support: https://github.com/salynch/DKO https://github.com/salynch/DKO) has make only a dozen or so commits. SQL is not a fast-changing target.
- lukaseder 11y agoThis is because you consider DKO to be "equivalent" :)
- vtman2002 11y agoFair enough. I don't know enough about jOOq to claim equivalency to your baby. I just wrote DKO to scratch an itch. (That itch being Hibernate!) Fully supportive of the general pattern, and glad you're free now for open source databases. In hindsight, perhaps I should have sought out VC funding. :)
- guiye 11y agoThis is another option: http://ebean-orm.github.io/ http://ebean-orm.github.io/ sound very nice and complete
- ehartsuyker 11y agoOr you could use Slick[0] for free. [0]: http://slick.typesafe.com/ http://slick.typesafe.com/
- tokenizerrr 11y agoJOOQ is completely free to use for Open Source databases. Here is a list: http://www.jooq.org/legal/licensing#databases http://www.jooq.org/legal/licensing#databases
- deleted 11y ago[deleted]
- Ciantic 11y agoI think this is not fully comparable, since it's Scala library. I tried to use JOOQ with Scala in past, it does not feel good solution for it, all that generated code seemed really difficult to keep in order. JOOQ is clearly Java tool first and foremost.
- lukaseder 11y agoYou don't use Slick's code generator? How big is your schema, then?
- cwyers 11y agoI am not sure that a Scala FRM is a one-for-one replacement for a Java-based ORM.
- solutionyogi 11y agoNever heard of this before as I mainly use MS stack. However, my first impression is very positive. 1. Database First Great way to distinguish your product from traditional ORMs. I am personally not a fan of code first approach especially as a LOB applications developer. I have been writing code for 15 years and the database/schema has outlived each and every application that I wrote. (I am in full agreement with lukaseder's comment: https://news.ycombinator.com/item?id=10880942 https://news.ycombinator.com/item?id=10880942) As an experienced developer, they immediately made their value proposition clear to me and I wanted to learn more. 2. Examples Side by side example comparing jOOQ to SQL. A great way for me to quickly see if I like their DSL design. 3. Convince your manager page. I absolutely loved this: http://www.jooq.org/why-jOOQ.pdf http://www.jooq.org/why-jOOQ.pdf We all have worked with 'a technical manager' who isn't really technical. When you need to purchase a tool, you need to convince your manager and this page is as good as I have seen. All commercial software development tool product websites should feature a 'Convince your manager' page.
- habitue 11y agoI came across JooQ when looking for LINQ in Java. I believe that's the original inspiration
- cwyers 11y agoI mean, the JOOQ guys all seem to hate the hell out of LINQ for abstracting the query language across data stores.
- hiram112 11y ago>We all have worked with 'a technical manager' who isn't really technical. When you need to purchase a tool, you need to convince your manager and this page is as good as I have seen. All commercial software development tool product websites should feature a 'Convince your manager' page. Agreed. The electrical metaphors and accompanying images are marketing gold!
- lawpoop 11y ago> Side by side example comparing jOOQ to SQL. A great way for me to quickly see if I like their DSL design. I'm always astounded how many times this is neglected. It seems pandemic. I live in the PHP world, and it seems that every hot new framework wants to do its own SQL re-hash. They always seem created by programmers who either hate SQL and want to avoid it as much as possible in favor of OO paradigms, or have never used it beyond its basic features. Sooner or later, I'll find myself wanting to do something moderately complex, like delete through a join, and all of a sudden the interface breaks down. I'll scour the internet or ask a question, and it either can't be done, or relies on some arcane, poorly documented part of the API, or uses weird, unintuitive syntax that makes you wonder if the API is any improvement over plain SQL at all.
- ssijak 11y agoDoes it "feel" natural to use it with spring boot instead of jpa and hibernate?
- lukaseder 11y agoIt depends on the nature of your project. Using JPA as a default is probably a bit of a historic issue. For a lot of time (2005-2010), Hibernate has been the de-facto standard way to access RDBMS from Java, unrightfully so in many cases that would have really fared much better with a SQL-based solution, not an ORM-based one. I'm talking about reporting, analytics, complex queries (outside of reporting), data-centric middle ware, batch processing, i.e. everything that isn't plain old CRUD. While Spring also often defaults to JPA, it isn't required at all to use JPA with Spring. Spring has always included JdbcTemplate, a JDBC extension for convenience when working with plain SQL. Apart from that, jOOQ is part of the Spring Boot manual. It cannot be feel that unnatural :) https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-jooq.html https://docs.spring.io/spring-boot/docs/current/reference/ht...
- continuational 11y ago> type safe SQL queries Really? So the compiler will catch this error? create.select().from(AUTHOR).where(BOOK.LANGUAGE.eq("DE")) No it won't, because `where` has this type: SelectConditionStep<R> where(Field<Boolean> field) If it was type safe, `Field<Boolean>` would have to mention the type of the records that can be queried. Type safety is what is being sold on the front page as the main value proposition. Needless to say, I'm not sold on it.
- HCIdivision17 11y agoI'm not sure I understand; doesn't BOOK.LANGUAGE.eq("DE") mean something like Book.Language = 'DE' in SQL? That's certainly a boolean expression. I've only started reading the manual, though, so it's possible I got the semantics wrong, but I've had SSMS point out to me this sort of thing before.
- continuational 11y agoIf we had selected from or joined on BOOK, it would be a Boolean expression. But in this case, BOOK is undefined, so BOOK.LANGUAGE.eq("DE") shouldn't type check at all. The corresponding SQL is nonsensical: select * from AUTHOR where BOOK.LANGUAGE = 'DE'
- lukaseder 11y agoYour criticism is certainly valid. The SQL language can be type checked using Java types only to a certain degree. There is no way to type check SQL thoroughly without an actual parser, though. For example, your query would be fine again (although a bit pointless) as a subquery: create.select() .from(BOOK) .where(exists( create.select().from(AUTHOR).where(BOOK.LANGUAGE.eq("DE")) )) Other frameworks may have jumped to the conclusion that predicates should be strictly tied to whatever is placed in the FROM clause. This is possible only if you completely limit the scope of what your framework can do (namely CRUD).
- kimi 11y agoA simple library that is similar (but not multi-database; this said, at least you don't have to learn another syntax for SQL) https://github.com/l3nz/ObjectiveSync https://github.com/l3nz/ObjectiveSync - Minimal wrapper over JDBC. - Querying done in SQL. You should not be afraid of SQL. If you are, you should not be doing anything above the trivial CRUD. - Centralizing object marshaling and unmarshaling - each object should know how to sync itself and its descendents - Single syntax for inserting and updating - Ruby-like objectivized JDBC fetching with exception handling - User-definable deep fetching and updating (almost Hibernate-like). - Batch API to avoid round-trips when submitting multiple queries. - Stats collection and similar stuff.
- matdrewin 11y agoNot too sure what's special about this thing. I also wonder why people keep making DSLs to replace SQL. I was using iBatis back in 2005 (now called MyBatis - http://blog.mybatis.org/?m=1 http://blog.mybatis.org/?m=1) and it worked great.
- lukaseder 11y ago... which is, essentially, an XML-based external DSL
- hutteman 11y agoNo, it's essentially a way to automatically map between manually written SQL and custom object types; you can use MyBatis with annotations only; no XML required. The advantage is that, as you're writing and embedding actual SQL, you can take advantage of any database-vendor-specific extensions to SQL, plus you can easily run, debug and test such SQL from another tool. Having full control over the actual SQL also means you don't risk potentially horribly inefficiently generated SQL, or risk running into unexpected N+1 scenarios. At the same time, you don't have to deal with JDBC and instead get a DAO layer that uses strongly typed objects. Of course the disadvantage is that you lose portability; moving for instance a MyBatis/SqlServer app to Oracle will mean verifying, testing and potentially rewriting every single SQL statement in your app. If you're willing to accept that risk though, MyBatis is a great lightweight library to manage your database access layer.