Reputation: 35276
I know hibernate but I wonder if there would be a lighter ORM engine for a read only database. I mean, I don't need some transactional queries or to update some records. On the other side, I need to handle some large list of records:
List<MyRecord> list= object.getMyRecords(); // list.size() > 1E7
Does such engine exist ? Many thanks,
Pierre
Upvotes: 5
Views: 1960
Reputation: 36
Bean Searcher is a very lightweight read-only ORM focused on advanced queries:
A read-only ORM focused on advanced queries, naturally supporting linked tables and eliminating DTO/VO conversion, making it possible to achieve complex list retrieval with just one line of code!
Github: https://github.com/troyzhxu/bean-searcher
Document: https://bs.zhxu.cn/
Upvotes: 1
Reputation: 49095
You can check out JIRM (yes, that is a shameless plug) which is an ORM focused on using immutable objects.
It sits right on top of Spring JDBC so, if you're using Spring, it's very low risk to try it.
It also has really nice SQL placeholder templates that do not require Spring.
Another project you should checkout is jOOQ.
Upvotes: 2
Reputation: 2552
If you are looking for a lightweight ORM I would recommend jORM. Note that my answer is biased, since I'm one of the contributors to the project.
The main reasons why we decided to write a lightweight alternative are (the need for):
In short; rapid development.
Example configuration
DataSource dataSource = new DataSource();
dataSource.setDriverClassName("org.postgresql.Driver");
dataSource.setUrl("jdbc:postgresql://localhost:5432/moria");
dataSource.setUsername("gandalf");
dataSource.setPassword("mellon");
Database.configure("moria", dataSource); // now there's a named database
Example record
@Jorm(database="moria", table="goblins", id="id")
public class Goblin extends Record {
public Integer getId() {
return get("id", Integer.class);
}
public void setId(Integer id) {
set("id", id);
}
public Integer getTribeId() {
return get("tribe_id", Integer.class);
}
public void setTribeId(Integer id) {
set("tribe_id", id);
}
public Tribe getTribe() {
return get("tribe_id", Tribe.class);
}
public void setTribe(Tribe tribe) {
set("tribe_id", tribe);
}
public String getName() {
return get("name", String.class);
}
public void setName(String name) {
set("name", name);
}
}
Example mapped queries
Goblin goblin = Record.findById(Goblin.class 42);
List<Goblin> goblins = Record.findAll(Goblin.class);Goblin bolg = Record.find(Goblin.class, new Column("name", "Bolg"));
Example custom queries
Tribe tribe = new Tribe();
tribe.setId(1);
String name = "Azog";
Goblin azog = Record.select(
Goblin.class,
"SELECT * FROM goblins WHERE name = #1# AND tribe_id = #2:id#",
name, // #1#
tribe // #2#
);
Goblin bolg = Record.find(Goblin.class, "SELECT * FROM goblins WHERE name = #1#", "Bolg");
Upvotes: 0
Reputation: 747
I think you should consider MyBatis (IBatis 3) ORM library. It fits the requirements from light-weight work to some heavy batch executions. So it'll fit your current needs very well and won't through you out of luck when you require some heavy-lifting work from your underlying ORM library.
Upvotes: 2
Reputation: 11184
Spring's SimpleJDBCTemplate combined with result mappers worked marvels for me in read only scenarios, you don't get the unneeded overhead of hibernate, all your pseudo-ORM mapping is bundled together, it is a true win for such scenarios.
Upvotes: 0
Reputation: 570505
Have a look at Ebeans which is a light ORM tool:
Worth the look IMO.
Upvotes: 1
Reputation: 4850
I searched lite ORM too for one project about a year ago. And tried a couple of them. I was a bit unsatisfied with all solutions because each of them was trying to move in certain direction.
Hibernate is a huge and it can be a source of extra troubles when you want just simple solution. Currently I am working on the one nice project it uses little custom layer over tables.
You can probably try to implement a little layer over your database with JDBC using some patterns like Active Record or Table Gateway, etc.
Any ORM solution just tries to be very unified and ads extra tails to your project. But you can create your own custom layer-less solution - this will especially work fine if you database have predefined set of tables and doesn't change it's structure too often.
Upvotes: 1
Reputation: 45263
If you are looking for a lightweight ORM framework, look no further than OrmLite. It allows you to avoid most of the overhead of setting up more complicated ORM frameworks like Hibernate. The downside to this framework is that it does not support standard JPA annotations so it would not be easy to swap this ORM out for a different one later on.
I would suggest trying out OpenJPA which is a JPA standard compliant ORM framework maintained by the Apache foundation. It is one of Hibernate major competitors. It does have a bit more overhead to setup but it has the advantage of allowing you to swap it out in the future for a different JPA compliant framework (like Hibernate) if it no longer suits your needs.
Both of these frameworks are Open Source as well which is always a good reason for using them.
Upvotes: 1