Note that there are some explanatory texts on larger screens.

plurals
  1. POWeb app with multiple projects using Java EE and Hibernate
    primarykey
    data
    text
    <p>I have a general design question that's bothering me for some time now.</p> <p><strong>Goal:</strong></p> <ul> <li>Create a web application using Vaadin for the Front End</li> <li>User must be able to create projects during runtime. Every project uses the same (Domain) Model, but different data</li> <li>Data for every project must be separated (into different databases)</li> <li>User can login, select project and get access to the specific Database</li> <li>Different user can work on different projects at the same time</li> <li>Application uses Hibernate with Annotations and Programmatic Configuration</li> </ul> <p><strong>Current Situation</strong></p> <ul> <li>Static HibernateUtil use in many places (getSessionFactory.getCurrentSession)</li> <li>Partially Implementation of Session-Per-View Pattern with ThreadLocal to get current Application instance, that works as Session-(and Transaction) Manager by using HTTPServletRequestListener to open and close session and transaction before and after view request</li> <li>Logic layer with no direct access to View Layer: <ul> <li>In some parts, Current Session is get by using the static HibernateUtil</li> <li>in other places, by setting the Session Manager via the constructor. This session manager then is passed to a DAO to provide session for Data Retrieval an manipulation</li> <li>When project is created, Hibernates create option is used to let the database be created (in future this could be switched to static ddl import at creation)</li> </ul></li> </ul> <p><strong>Problems</strong></p> <p>As one can imagine, there are various problems:</p> <ul> <li>Static access to sessionfactory to get session cannot work for multiple projects, as static HibernateUtil can only carry one (db)url at the same time and so sessions get mixed</li> <li>Access to SessionManager from Logic Layer is not nice (need to provide it through several constructors)</li> <li>mixture of different approaches is ugly, but goal is to straighten this</li> </ul> <p><strong>Thoughts</strong></p> <ul> <li>Implement Dependency injection to provide correct DAOFactory even in Logic Layer. Tried it with Guice, but get Null Pointer Exceptions if Instances are not created via Injector (see my other question). Therefore it does not work. </li> </ul> <p>I wish i could just inject/use the correct Instance of DAO Factory (which has access to the correct session/db) anywhere in the code without e.g. the logic layer knowing which current database is loaded. So the logic layer should not care about session handling or anything. I just want to make a call do xyDAO.find(id) or similar from anywhere and it gets the correct database. I also think that its not nice to pass the SessionManager through several classes by constructor, if only one class deep down in the logic needs it.</p> <p>What approach would you take to meet the goals stated?</p> <p>I would really appreciate if someone could help. If you need additional info, please let me know and I will provide!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload