Alternative to Hibernate or TopLink?

Is there a viable alternative to Hibernate? Preferred is not based on JPA.

Our problem is that we are building a complex (like many, objects refer to each other) to the state-protected RIA system. Hibernate seems to be intended for use mainly in one-time applications - JSF, etc.

The problem is mainly lazy loading. Since there can be several HTTP requests between initialization and actual loading of lazy collections, there is no question of a transaction session. A long-lived session (one for each application) also does not work, because as soon as the transaction falls into the trap and throws an exception, the entire session is invalid, so lazy loaded objects break. Then there are all kinds of things that just don't work for us (for example, implicit data stored in data outside of an initialized transaction).

My poor explanations aside, the bottom line is that Hibernate does magic that we don't like. TopLink doesn't seem to be better; it is also written on top of EJB.

Thus, the level of persistence without state preservation (or even a sufficiently bright object-oriented level of database abstraction) is what we need most.

Any thoughts, or am I asking for something that does not exist?

Edit: I apologize for my ambiguous terminology and thank you all for the corrections and insightful answers. Those who corrected me, you are all right, I meant JPA, not EJB.

+6
java java-ee hibernate jpa eclipselink
source share
11 answers

As already mentioned, JPA <> EJB, they are not even related. EJB 3 uses leverage from the JPA, but more on that. We have a bunch of things using JPA that isn't even suitable for running EJB.

Your problem is not in technology, but in its design.

Or, I must say, your design is not easy to fit into almost any modern structure.

In particular, you are trying to save transactions across multiple HTTP requests.

Naturally, most of the common idioms are that each request in itself is one or more transactions, and not every request that is part of a larger transaction.

There is also an obvious confusion when you used the terms “stateless” and “transaction” in the same discussion, because transactions are inherently restrained.

Your big problem is simple manual transaction management.

If you are making a transaction on multiple HTTP requests and these HTTP requests are executed "very fast" immediately after each other, then you really should not have a real problem, except that you must ensure that your HTTP requests use the same database connection to use the database transaction mechanism.

Thus, you get a connection to the database, fill it in a session and make sure that throughout your transaction all your HTTP requests pass not only in the same session, but also in such a way that the actual connection is still valid. In particular, I do not believe that there is a JDBC connection on the shelf that will actually survive a failure or load balancing from one machine to another.

So, simply, if you want to use database transactions, you need to make sure that you are using the same database connection.

Now, if your long transaction has "user interactions" inside it, that is, you start the transaction from the database and expect the user to "do something", then, quite simply, this design is wrong. You DO NOT want to do this, as long-running transactions, especially in interactive environments, are just plain bad. Like "Thread Crossing" Bad. Do not do this. Batch transactions are different, but interactive long-lived transactions are bad.

You want your online transactions to be as short as possible.

Now, if you can’t guarantee that you can use the same database connection for your transaction, then, congratulating, you can implement your own transactions. This means that you can design your systems and data streams as if you did not have transactional capabilities on the back panel.

This essentially means that you will need to create your own mechanism for “fixing” your data.

A good way to do this is to gradually build up your data in a single transaction document, and then load that document into a “saving” procedure that does most of the real work. For example, you can save a row in the database and mark it as "unsaved." You do this with all your lines, and finally, call a procedure that looks at all the data you just saved and marks everything as “saved” in one transactional batch process.

Meanwhile, all your other SQLs are ignoring data that is not “saved”. Throw a few time stamps and clear the header process (if you really want to worry - it’s quite possible that it’s actually cheaper to just leave dead rows in the database, depending on the volume), these dead “unsaved” rows, since they are “unauthorized” transactions.

This is not as bad as it seems. If you really need a stateless environment, which seems to me, then you will need to do something like this.

Of course, in all of this, persistence technology really has nothing to do with it. The problem is how you use your transactions, not so many technologies.

+6
source share

If you're after another JPA provider (one of them is Hibernate), check out EclipseLink . This is much more complete than the standard implementation of TopLink Essentials JPA 1.0. In fact, EclipseLink will be the reference JPA 2.0 implementation shipped with Glassfish V3 Final.

JPA is good in that you can use it both inside and outside the container. I wrote Swing clients who use JPA for a good effect. It does not have the same XML stigma and baggage as EJB 2.0 / 2.1.

If you are after a lighter weight solution, look no further than ibatis , which I consider to be my preservation technology for the Java platform. It's lightweight, relies on SQL (it's amazing how much time ORM users take to make ORM a good SQL product) and does 90-95% of what JPA does (including lazy loading related objects if you want).

Just fix a couple of points:

  • JPA is an EJB strength layer not built on an EJB;
  • Any worthy JPA provider has whole caching going on, and it can be hard to understand (this would be a good example of “Why is simplicity so complicated?”). If you do not do what you did not specify, exceptions should not be a problem for your managed objects. In run-time exceptions, rollback transactions are usually performed (if you use Spring transaction management and who doesn't?). The provider will store cached copies of the downloaded or saved objects. This can be problematic if you want to update the external part of the entity manager (requiring an explicit cache reset or using EntityManager.refresh() ).
+7
source share

I think you should take a look at apache cayenne , which is a very good alternative to the "big" frameworks. With his worthy fashion designer, the learning curve is reduced thanks to good documentation.

+3
source share

Last year I looked at SimpleORM and was very impressed with its lightweight design without magic. Now there seems to be version 3, but I have no experience with this.

+2
source share

Ebean ORM ( http://www.avaje.org )

This is a simpler and clearer ORM.

  • Uses JPA annotations for matching (@Entity, @OneToMany, etc.)
  • Session-less API - no hibernation session or JPA entity manager
  • Easy loading only works
  • Partial object support for better performance
  • Automatically configure a query using the "Autostart" function
  • Spring Integration
  • Large request support
  • Excellent batch processing support
  • Background fetch
  • DDL Generation
  • You can use raw SQL if you want (as good as Ibatis)
  • LGPL License

  • Rob.

+2
source share

BEA Kodo (formerly Solarmetric Kodo) is another alternative. It supports JPA, JDO and EJ3. It is highly customizable and can support aggressive prefetching, detaching / attaching objects, etc.

Although, from what you described, Toplink should be able to cope with your problems. Basically, it looks like you should be able to attach / detach objects from the save level when requests start and end.

+1
source share

Just for reference, why the OP design is its biggest problem: using transactions on multiple user requests means that you can have as many open transactions as possible at certain times, since there are users connected to your application - the transaction keeps the connection busy until those as long as it is completed / rolled back. With thousands of simultaneously connected users, this could potentially mean thousands of connections. Most databases do not support this.

+1
source share

Neither Hibernate nor Toplink (EclipseLink) is EJB-based, they are both object-oriented POJO (ORM) structures.

I agree with the previous answer: iBatis is a good alternative to ORM structures: full control over sql, with a good caching mechanism.

0
source share

Another option is Torque, I'm not saying that it is better than any of the above options, but it's just another option. Now it is becoming quite old, but may meet some of your requirements.

Torque

0
source share

When I was looking for a Hibernate replacement myself, I came across the DataNucleus Access Platform , which is an ORM with an Apache2 license. This is not just ORM, as it provides persistence and retrieval of data in data sources other than RDBMS, such as LDAP, DB4O, and XML. I have no experience using it, but it looks interesting.

0
source share

Consider completely a violation of your paradigm with tox . If you need Java classes, you can load the XML result into the JDOM .

0
source share

All Articles