Search code examples
jakarta-eemockingejb-3.0rad

how to simulate a db using jpa and ejb 3


i'm been assigned the development of an ejb 3, jpa application . I need to provide at least a demo before the end of the year, yet i have a couple of problems : this is my first project with ejb and jpa, then i'll probably will not have a db available in short times. I'd like the opinion of more experienced developers about the way i've choosen to try and some hints about how to solve some specific problems. I'm going to add a jpa project to the workspace (i'm using rational application developer) , with all entities i need but i'm not going to map them to any table so that they will be immediatly available to session beans and ready to be mapped when the db will be created. There are a couple of flaws in this great plan : how do i simulate the entitymanager which instatiate entities bean and , above all , how do i simulate the database ? i'll need to do insert, update and retrieve operations in my demo. Is it reasonable to setup a singleton (say entityManagerMock) which holds some dictionary to fake tables ?


Solution

  • Have you considered use a In-Memory Database like HSQLDB or H2?. I think that it will be more easy than try to mock a PersistenceContext and EntityManagers. JPA provide the functionality of create the structure of tables so you don't worried aobut the update of structures because your Database will run on memory.