DEV Community

Guillaume Mary for Codefilarete

Posted on

Stalactite ORM 1.0.0 is out !

After many years of dev, Stalactite ORM is finally released ! It has a brand new approach about persistence :

  • mapping is defined by method references instead of Annotations or XML
  • its fluent API helps you see the complexity of you graph
  • it eagerly fetches your relations to avoid hidden sql queries

Here is a short view of what can be achieved with it :

DataSource dataSource = ... // use whatever JDBC DataSource you want
PersistenceContext persistenceContext = new PersistenceContext(dataSource, new HSQLDBDialect());

EntityPersister<Country, Long> countryPersister = MappingEase.entityBuilder(Country.class, long.class)
    .mapKey(Country::getId, IdentifierPolicy.afterInsert())
    .map(Country::getName)
    .map(Country::getDescription)
    .mapOneToOne(Country::getPresident, MappingEase.entityBuilder(Person.class, long.class)
        .mapKey(Person::getId, IdentifierPolicy.afterInsert())
        .map(Person::getName))
    .build(persistenceContext);

Country country = new Country(42L);
country.setPresident(new Person(12L));
countryPersister.persist(country);

// you can also map an SQL query to build a projection
List<Car> allCars = persistenceContext.newQuery("select id, model, rgb from Car", Car.class)
    .mapKey(Car::new, "id", long.class)
    .map("model", Car::setModel)
    .map("rgb", Car::setColor, int.class, Color::new)
    .execute();
Enter fullscreen mode Exit fullscreen mode

Give it a try, see documentation here

Top comments (0)