This is an easly plugable extension for the mangoo I/O framework to work with Hibernate.
Requires Java 17.
- Add the mangooio-hibernate-extension dependency to your pom.xml:
<dependency>
<groupId>de.svenkubiak</groupId>
<artifactId>mangooio-hibernate-extension</artifactId>
<version>x.x.x</version>
</dependency>
- Configure Hibernate in your mangoo I/O config.props, e.g.
[hibernate]
models = de.svenkubiak.mangooio.models
hbm2ddl.auto = create-drop
connection.driver_class = org.apache.derby.jdbc.EmbeddedDriver
connection.url = jdbc:derby:memory/derbydb
connection.username = username
connection.password = password
dialect = org.hibernate.dialect.DerbyTenSevenDialect
current_session_context_class = thread
- Inject the DataStore where needed
@Inject
DataStore dataStore;
- Using wrapper methods
Person person = new Person();
dataStore.save(person);
dataStore.update(person);
dataStore.saveOrUpdate(person);
- Using find methods
Person p = dataStore.findOne("FROM Person p WHERE p.firstname = 'Foo'");
- Using Hibernate Criteria
Session session = dataStore.getSession();
Criteria critera = session.createCriteria(Person.class);
criteria.add(Restrictions.eq("firstname", "Foo"));
Person p = (Person) critera.uniqueResult();