August 22, 2012

Create a JPA EntityManager programmatically

I've been using this kind of PersistenceUnit creation for some unit tests, because they had to run along with some integration tests, and because of that the persistence.xml files were messing between them.

So, how to create an EntityManager programmatically?

  • Solution link: http://docs.jboss.org/hibernate/stable/entitymanager/reference/en/html/configuration.html

August 5, 2012

Development tips

I've worked in some projects so far and I learned some things that can save you a lot of time even if they sound very expensive. These tips are meant for small/medium size projects, perhaps you can apply them to big projects, but I'm not sure.


  1. Revision control system from the beginning.
  2. Define your goals and milestones, even without dates.
  3. Define what you are going to build, with use cases or user stories, or just use whatever you feel comfortable with.
  4. Define an architecture, don't go on without this. The architecture must define the form of the system, not the details.
  5. Define the contexts you are going to be working on, this means that you have to separate your project into smaller micro-projects (if it applies).
  6. Define your frameworks/libraries stack.
  7. Define your project(s) structure, this involves folders and files.
  8. Define your automated build scripts, something like Gradle would do it.
  9. Think in the tests before the implementation, if it's testable, it's implementable.
  10. Use continuous integration from the beginning.
  11. Keep you source files small and readable.
  12. Periodically check your system and update the architecture if some changes have been made.
I omitted several things, but I consider these the most important from a developer's perspective.

I didn't have this information at the beginning because I was too lazy to read about it, and had to learn it the hard way, by suffering the consequences...