The Beangle Data Library is a Scala 3 ORM framework built on JPA/Hibernate, providing a convention-over-configuration domain model, a fluent query API, DDL generation and JSON:API serialization.
- Convention-based ORM — plain Scala classes mapped to tables by convention; entity, component and collection support via
Entity,Componentand thepojotraits - DSL mapping module — declare tables, columns, indexes, caches, generators and relationships in a
MappingModulewith a Scala DSL (inline macros) - Fluent query API —
OqlBuilderwith type-safe expressions, group/aggregate functions, conditions and pagination - DAO abstraction —
EntityDaofor CRUD, search,executeUpdate, cache eviction and transaction operations; Hibernate-backed implementation - DDL generation — generate database schemas from mappings via
DdlGenerator, withEJB3NamingPolicy/RailsNamingPolicyand schema profiles - JSON:API support — serialize entities into JSON:API documents with sparse fields, includes and relationships
- Rich type mapping — JSON columns, enums,
YearMonth, value types and theDecimal5/TinyDecimal5fixed-point decimals mapped todecimal(p,5)columns - Transaction management — Spring-based
HibernateTransactionManager, declarative transactions viaTransactionalProxy - ID generators — auto-increment, date-time, code-style, uuid and assigned strategies
libraryDependencies += "org.beangle.data" % "beangle-data-model" % "5.12.6"
libraryDependencies += "org.beangle.data" % "beangle-data-hibernate" % "5.12.6"Requires Scala 3 and JDK 21+.
beangle-data-model— domain model, DAO interfaces, OQL builder, ORM metadata and DDL generation (no Hibernate dependency)beangle-data-hibernate— Hibernate integration:EntityDaoimplementation, session factory, transaction management, type registration and ID generators
import org.beangle.data.model.*
import org.beangle.data.model.pojo.Named
class User extends LongId, Named {
var member: NamedMember = _
var roles: scala.collection.mutable.Buffer[Role] = _
var age: Option[Int] = _
}
class NamedMember extends Component {
var name: Name = _
}
class Name extends Component {
var firstName: String = _
var lastName: String = _
}import org.beangle.data.orm.{IdGenerator, MappingModule}
object DefaultMappings extends MappingModule {
def binding(): Unit = {
bind[User].declare { e =>
e.member.name.first is(notnull, length(20), unique)
e.member.name.first & e.member.name.last are notnull
e.roles is ordered
}.generator(IdGenerator.DateTime)
bind[Role].declare { e =>
e.name is(notnull, length(20), unique)
}.generator(IdGenerator.Native)
}
}<?xml version="1.0" encoding="UTF-8"?>
<beangle>
<jpa>
<mapping class="com.example.DefaultMappings"/>
<naming>
<profile package = "com.example.model" pluralize="true"/>
</naming>
</jpa>
</beangle>import org.beangle.data.hibernate.{HibernateEntityDao, LocalSessionFactoryBean}
import javax.sql.DataSource
val ds: DataSource = ...
val builder = new LocalSessionFactoryBean(ds)
builder.ormLocation = "classpath*:beangle.xml"
builder.init()
val entityDao = new HibernateEntityDao(builder.getObject)
entityDao.init()import org.beangle.data.dao.OqlBuilder
val q = OqlBuilder.from(classOf[User], "u")
import q.given
q.where { u =>
(u.member.name.first like "bil")
.and(u.age isNotNull)
}
val users = entityDao.search(q)entityDao.findBy(classOf[User], "member.name.first" -> "Bill")
entityDao.count(classOf[User], "roles.id" -> 1L)Beangle Data is released under the GNU Lesser General Public License v3.