HbnContainer
HbnContainer is a data connector for Vaadin based on Hibernate. It is used for binding entities with database records to feed components like tables, forms and trees.
** Please note ** This project is inactive and in need of a maintainer. If you would like to take it over please fork it on github and add the support and features that you need. Because of its popularity I don't want to just take the codebase offline so if anyone has interest please take it over for the benefit of the community.
HbnContainer is a data connector for Vaadin based on the popular Hibernate ORM from JBoss. It is distributed as a Vaadin Add-on and it is used for binding entities with database records to feed components like tables, forms and trees.
Compatibility:
- Vaadin 6 + Hibernate 3.x: HbnContainer 1.0
- Vaadin 6 + Hibernate 4.x: HbnContainer 1.1
- Vaadin 7 + Hibernate 4.x: HbnContainer 2.0
License:
- HbnContainer is licensed under the Apache 2.0 License.
- You are free to use HbnContainer in commercial applications.
Notes:
- I will maintain a branch for 1.1 code for bug fixes
- I currently have no plans to add features to 1.1
- New features will be added to 2.x only
- Please use the project page for reporting bugs
- Please use the project page for feature requests
- Please contribute any enhancements back to the community
Origins: HbnContainer originated with Matti Tahvonen at Vaadin who created it for an article explaining how to use Hibernate with Vaadin. I took over as maintainer in 2012 when Matti found that he didn't have time to maintain this project along with all the other work he was doing for Vaadin and for the open source community. Matti continues to advise and consult on this project occasionally, as needed.
Sample code
table.setContainerDataSource(new HbnContainer(Workout.class, this));
public class HibernateServletFilter implements Filter { private static final Logger logger = LoggerFactory.getLogger(HibernateServletFilter.class); @Override public void init(FilterConfig filterConfig) throws ServletException { logger.debug("Initializing HibernateServletFilter"); } @Override public void destroy() { logger.debug("Destroying HibernateServletFilter"); final Session session = HibernateUtil.getSessionFactory().getCurrentSession(); if (session.getTransaction().isActive()) { logger.debug("Committing the final active transaction"); session.getTransaction().commit(); } if (session.isOpen()) { logger.debug("Closing the final open session"); session.close(); } } @Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { final Session session = HibernateUtil.getSessionFactory().getCurrentSession(); try { logger.debug("Starting a database transaction"); session.beginTransaction(); chain.doFilter(request, response); logger.debug("Committing the active database transaction"); session.getTransaction().commit(); } catch (StaleObjectStateException e) { logger.error(e.toString()); if (session.getTransaction().isActive()) { logger.debug("Rolling back the active transaction"); session.getTransaction().rollback(); } throw e; } catch (Throwable e) { logger.error(e.toString()); if (session.getTransaction().isActive()) { logger.debug("Rolling back the active transaction"); session.getTransaction().rollback(); } throw new ServletException(e); } } }
<filter> <filter-name>HibernateServletFilter</filter-name> <filter-class>com.vaadin.demo.HibernateServletFilter</filter-class> </filter> <filter-mapping> <filter-name>HibernateServletFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping>
public class HibernateUtil { private static final Logger logger = LoggerFactory.getLogger(HibernateUtil.class); private static SessionFactory sessionFactory; static { try { logger.debug("Initializing HibernateUtil"); final Configuration configuration = new Configuration(); configuration.configure(); final ServiceRegistryBuilder serviceRegistryBuilder = new ServiceRegistryBuilder(); final ServiceRegistry serviceRegistry = serviceRegistryBuilder .applySettings(configuration.getProperties()) .buildServiceRegistry(); sessionFactory = configuration.buildSessionFactory(serviceRegistry); } catch (Throwable e) { logger.error(e.toString()); throw new ExceptionInInitializerError(e); } } public static SessionFactory getSessionFactory() { return sessionFactory; } }
Links
- Original Article Introducing HbnContainer
- Getting Started - HbnContainer & Vaadin 7
- Project Page
- Issue Tracker
- Source Code
Compatibility
Was this helpful? Need more help?
Leave a comment or a question below. You can also join
the chat on Discord or
ask questions on StackOverflow.
Version
Changes in version 2.0.1 November 6, 2012
HbnContainer will remain in beta until Vaadin 7 is released. The following changes have occurred:
- Support for Vaadin 7 beta7
- Ivy dependencies available on project wiki
- Fixed several bugs and added unit tests
- Replaced entity cache with a Google Guava LoadingCache
- Improved trace logging
As usual, please report bugs via the project page on GitHub. Suggestions for improvement are always welcome in the form of code or patch submissions.
- Released
- 2012-11-07
- Maturity
- BETA
- License
- Apache License 2.0
Compatibility
- Framework
- Vaadin 7.0+
- Vaadin 6.0+ in 1.1.0
- Vaadin 6.1+ in 1.0
- Browser
- Browser Independent
HbnContainer - Vaadin Add-on Directory
HbnContainer is a data connector for Vaadin based on Hibernate. It is used for binding entities with database records to feed components like tables, forms and trees.Getting Started - HbnContainer & Vaadin 7
Project Page
Issue Tracker
Source Code
HbnContainer version 1.0.1
* Small patch to improve MySQL compatibility with some versions. Thanks to Kristoffer Jansson.
* Upgraded to stable maturity level. Used in a large public web application without known issues.
HbnContainer version 1.0.2
Added stub methods to resolve issues with Container.Filterable (changed in Vaadin 6.6). This version should work with Vaadin 6.6, but the new style filterable API doesn't work. Old API and overriding getBaseCriteria() should work as before.
HbnContainer version 1.0.3
SimpleStringFilter now somehow works. Should give a bit better Vaadin 6.6 support. Untested, please let me know if it doesn't work.
HbnContainer version 1.0.4
indexOfId method now works always, but is slow in some situations. Needed to make ComboBoxes work properly in Vaadin 6.6.
HbnContainer version 1.0.5
A patch from Michal Stehlik:
* Extendable filtering API (not only by overriding the getBaseCriteria() method)
* updateEntity now uses update() instead of save()
HbnContainer version 1.1.0
HbnContainer v1.1 was released on April 20, 2012. This new release contains some potentially breaking changes for existing projects so before upgrading please see the change log for details. Highlights include:
* Support for Hibernate 4.x
* Implemented Container.Hierarchical
* Replaced log4j with the slf4j facade.
* Cleaned up deprecated code and minor bug fixes
Thanks to Oleg Kuznecov for contributing to this release.
HbnContainer version 2.0.0
Release 2.0.0 (beta)
October 14, 2012
This release contains breaking changes due to the fact that data component interfaces have changed between Vaadin 6 and Vaadin 7. Users wanting to use HbnContainer with Vaadin 6 projects should continue to use 1.1 or earlier.
* Added support for Vaadin 7 beta4 and Hibernate 4.1.7
* Switched to Ivy for dependency management and removed the dependency jars
* Removed WorkoutLog from HbnContainer and made it a standalone demo project
* Moved HbnContainer project page to GitHub https://github.com/gpiercey/HbnContainer
* Moved WorkoutLog project page to GitHub https://github.com/gpiercey/WorkoutLog
Release 1.1.0
April 20, 2012
This new release contains some potentially breaking changes for existing projects due to a minor change in Hibernate between 3.x and 4.x so before upgrading please see the change log for details.
* Support for Hibernate 4.x
* Implemented Container.Hierarchical
* Replaced log4j with the slf4j facade.
* Cleaned up deprecated code and minor bug fixes
HbnContainer version 2.0.1
Changes in version 2.0.1
November 6, 2012
HbnContainer will remain in beta until Vaadin 7 is released. The following changes have occurred:
* Support for Vaadin 7 beta7
* Ivy dependencies available on project wiki
* Fixed several bugs and added unit tests
* Replaced entity cache with a Google Guava LoadingCache
* Improved trace logging
As usual, please report bugs via the project page on GitHub. Suggestions for improvement are always welcome in the form of code or patch submissions.