Quick post – hibernate.cfg.xml with Hibernate 4.0.0

Hello, everyone! Yesterday I spent many hours trying to make Hibernate 4.0 (hibernate-core-4.0.0) work with a hibernate.cfg.xml file. I just could not obtain a Session Factory from a file similar to this one:

<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD//EN"
<property name="connection.url">jdbc:mysql://localhost/noob</property>

<property name="connection.driver_class">com.mysql.jdbc.Driver</property>

<property name="dialect">org.hibernate.dialect.MySQLInnoDBDialect</property>

<property name="connection.username">root</property>
<property name="connection.password"></property>
<!-- DB schema will be updated if needed -->
<property name="hbm2ddl.auto">create-drop</property>
<property name="show_sql">false</property>
<property name="format_sql">false</property>


Besides, I was trying to obtain a SessionFactory with a code like this:

public class HibernateUtil {

private static SessionFactory sessionFactory;
private static ServiceRegistry serviceRegistry;

private static SessionFactory configureSessionFactory() throws HibernateException {
Configuration configuration = new Configuration();
serviceRegistry = new ServiceRegistryBuilder().applySettings(configuration.getProperties()).buildServiceRegistry();
sessionFactory = configuration.buildSessionFactory(serviceRegistry);
return sessionFactory;

public static SessionFactory getSessionFactory() {
return configureSessionFactory();


And no, it was not working. So I made some changes:
Into my hibernate.cfg.properties, I did something like this:

<?xml version='1.0' encoding='utf-8'?>

<!-- Database connection settings -->
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost/noob</property>
<property name="hibernate.connection.username">root</property>

<property name="hibernate.connection.password"></property>

<!-- JDBC connection pool (use the built-in) -->
<property name="hibernate.connection.pool_size">1</property>

<!-- SQL dialect -->
<property name="hibernate.dialect">org.hibernate.dialect.MySQLInnoDBDialect</property>

<!-- Enable Hibernate's automatic session context management -->
<property name="hibernate.current_session_context_class">thread</property>

<!-- Disable the second-level cache -->
<property name="hibernate.cache.provider_class">org.hibernate.cache.internal.NoCacheProvider

<!-- Echo all executed SQL to stdout -->
<property name="hibernate.show_sql">true</property>

<!-- Drop and re-create the database schema on startup -->
<property name="hibernate.hbm2ddl.auto">update</property>


Notice the “hibernate.” in front of the properties. It was very very helpful, without it things did not work.

Also, for my SessionFactory, I did a code like this:

ServiceRegistry serviceRegistry = new ServiceRegistryBuilder().configure().buildServiceRegistry();
MetadataSources metadataSources = new MetadataSources(serviceRegistry);
SessionFactory factory = metadataSources.buildMetadata().buildSessionFactory();

And win!!! Things started working!


March 21, 2012 at 11:55 am 2 comments

EJB Lookup w/ JNDI on Jboss AS 7

Hello everyone!

I was kinda busy last months, so I did not have time to publish more posts here :/

Anyway, some weeks ago i have noticed a little (big) issue on JBoss AS 7 – I couldn’t make EJB lookup using JNDI!

I had to Google a lot to find a concrete answer.

So I’d like to share a way to do it.

First of all, you must have AS 7.1.x, even if it is not at the final version yet. You can download it here.

Then, create a file named jboss-ejb-client.properties into your src folder, and add this content



remote.connection.default.port = 4447

remote.connection.two.port = 4447

Now the disgusting part. You’ll need to make a big workaround here.
Your class is going to have lots of information. And one BIG important thing – this first example only works for Stateful EJBs. I’ll show an example for Stateless EJBs later. So remember – STATEFUL EJBs:

public class ClientMyStatefulBean {

static {
Security.addProvider(new JBossSaslProvider());


public static void main(String[] args) throws NamingException {

final Hashtable jndiProperties = new Hashtable();
final Context context = new InitialContext(jndiProperties);

final String appName = "";

final String moduleName = "myBeans";
// THIS IS THE NAME OF THE JAR WITH YOUR EJBs. Write its name here, without the .jar.

final String distinctName = "";
//    AS7 allows deployments to have an distinct name. If you don't use this feature, let this field empty.

final String beanName = MyBean.class.getSimpleName();

final String viewClassName = Bean.class.getName();

Bean bean = (Bean) context.lookup("ejb:" + appName + "/"
+ moduleName + "/" + distinctName + "/" + beanName + "!"
+ viewClassName + "?stateful");



Now for STATELESS BEANS, do this:

public class ClientMyStatelessBean {

static {
Security.addProvider(new JBossSaslProvider());


public static void main(String[] args) throws NamingException {

final Hashtable jndiProperties = new Hashtable();
final Context context = new InitialContext(jndiProperties);

final String appName = "";

final String moduleName = "myBeans";
// THIS IS THE NAME OF THE JAR WITH YOUR EJBs. Write its name here, without the .jar.

final String distinctName = "";
//    AS7 allows deployments to have an distinct name. If you don't use this feature, let this field empty.

final String beanName = MyBean.class.getSimpleName();

final String viewClassName = Bean.class.getName();

Bean bean = (Bean) context.lookup("ejb:" + appName + "/" + moduleName + "/" + distinctName + "/" + beanName + "!" + viewClassName)




It is not over yet!
Now you must add some jars to your classpath!
You’ll need these jars:

  • jboss-transaction-api_1.1_spec-1.0.0.Final.jar
  • jboss-ejb-api_3.1_spec-1.0.1.Final.jar
  • jboss-ejb-client-1.0.0.Beta10.jar
  • jboss-marshalling-1.3.0.GA.jar
  • xnio-api-3.0.0.CR5.jar
  • jboss-remoting-3.2.0.CR6.jar
  • jboss-logging-3.1.0.Beta3.jar
  • xnio-nio-3.0.0.CR5.jar
  • jboss-sasl-1.0.0.Beta9.jar
  • jboss-marshalling-river-1.3.0.GA.jar

You can find all these jars into your Jboss AS 7 folder inside “modules” folder.
Or, to make things more simple, I’ve created this project at github ->https://github.com/hannelita/jboss-as-libs-ejb-lookup

All necessary libs are there, just include them into your classpath and things should work 🙂

Need more references? You can find the here:

Docs -> https://docs.jboss.org/author/display/AS71/EJB+invocations+from+a+remote+client+using+JNDI

Issue discussion -> https://issues.jboss.org/browse/AS7-1338

Project example -> https://github.com/jaikiran/quickstart/tree/master/ejb-remote

I’d like to thank a guy called Jaikiran Pai for publishing this information into JBoss Docs! 🙂

Well, just to finish the topic – I think its still an ugly way to do ejb lookup. For xample, that static block and all those strings are disgusting. Hope to have a better solution for further versions! 🙂

December 30, 2011 at 8:40 pm 3 comments

Instalando a gem do PostgreSQL no Rails 3

Recentemente, após instalar o dmg do PostgreSQL 9.1, fui usar a gem pg (gem do Postgres) e tomei uns erros estranhos:

checking for pg_config... no
No pg_config... trying anyway. If building fails, please try again with
checking for libpq-fe.h... no
Can't find the 'libpq-fe.h header
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of
necessary libraries and/or headers.  Check the mkmf.log file for more
details.  You may need configuration options.

Provided configuration options:

Gem files will remain installed in /Users/hannelitavante/.rvm/gems/ruby-1.9.2-p180/gems/pg-0.11.0 for inspection.

Bizarramente, no MacOSX 10.6+, ele dá uns paus muito loucos. para resolver, basta fazer isso:

export ARCHFLAGS='-arch x86_64'
gem install pg

October 26, 2011 at 8:52 pm 1 comment

JBoss in Bossa 2011 – Sucesso total!


Neste último sábado, 08 de outubro, ocorreu mais uma edição do Jboss In Bossa, dessa vez em Brasília. O evento foi sensacional e tive a honra de participar como palestrante!

Além do lugar ser muito bacana, o público estava extremamente interessado e com uma vontade imensa de obter novos conhecimentos das tecnologias da JBoss! Foi uma troca de experiência e networking muito bons!

O keynote foi realizado pelo @salaboy (Mauricio Salatino), famoso por manjar absurdamente de jbpm, Drools e recentemente ele está desenvolvendo uma projeto de Human tasks, o Smart Tasks. (slides aqui)

Em seguida, @jedgarsilva (Edgar Silva) apresentou uma divertida palestra sobre KVM e Cloud (com demos sobre Openshift). Ele já publicou o conteúdo, você pode acessa-lo aqui.

Logo após, o @rimolive (Ricardo Martinelli), o cara de CDI, fez sua apresentação falando sobre Seam 3 e o futuro de JEE 6 com o advento do CDI. Também, na trilha paralela na sala 105, @claudio4j (Claudio Miranda) e @brunorst (Bruno Rossetto) fizeram uma apresentaão sensacional com dicas para tunar seu JBoss AS.

Chegou a hora do almoço e aproveitei para visitar a #Caelum BSB graças ao @lacerdaph (Raphael Lacerda) que me levou até lá! 🙂

Voltando ao evento, apresentei minha palestra sobre Seam 3, contando um pouco da trajetória do Seam, dos adventos do Seam 3, falei do Seam Forge com uma pequena demo e expus algumas recentes decisões que foram tomadas a respeito do futuro do Seam 3. Espero que o pessoal tenha curtido 🙂 (slides aqui)

Infelizmente, conflitando horário com minha apresentação, o @porcelli falou sobre NoSQL! Não pude assistir à apresentação, mas os slides estão aqui! E só ouvi comentários extremamentes positivos a respeito 🙂

Logo após, @rafabene (Rafael Benevides) e @osmanlira (Osman Lira – sim, ele fez uma conta no Twitter após o evento!) falaram sobre Guvnor (os fontes estão aqui) e, na trilha paralela, @vtcorrea (Vitor Correa) e @g_luszczynski (Gustavo Luszczynski) arrebentaram em sua apresentação repleta de demos sobre jGroups e mod_cluster.

Depois, Pedro Igor falou sobre Infinispan e paralelamente, Rafael Soares falou sobre RHQ (infelizmente não pude assistir a essa palestra).

Na hora do coffee break, todos estavam repletos de idéias, dúvidas e rolou um networking muito bacana entre o pessoal que assistiu as palestras e os palestrantes! Além do mais, o coffee estava de primeira! Abundância e variedade de coisas deliciosas!

Em seguida, @jpviragine (João Paulo Viragine) falou sobre data federation com Teiid, e sua demo e precisão na hora das demos deixaram o público fascinado! Na outra sala, @rafaelliu falou sobre JBoss Portlet Bridge.

Fechando com chave de ouro, Flávia Rainone, core developer da JBoss, falou sobre o JBoss AS 7, grande sucesso entre os servidores de aplicação, especialmente devido a sua velocidade de strat de aproximadamente 2s.


Algo que curti muito no evento foi o espaço para palestras da comunidade! Isso foi bem bacana, houve palestras de pessoas da Red hat e de pessoas que contribuem para o mundo Open Source, mostrando a força e participação da comunidade! Show!

Para finalizar, parabenizo toda a organização do Jboss in Bossa e gostaria de agradecer todo o esforço que vocês tiveram para fazer um evento tão bacana quanto este! Parabéns! Espero estar com vocês na próxima edição! 🙂

October 10, 2011 at 8:28 pm 2 comments

Seam 3 – What’s going on

Hi all!

I’ve been blogging about Seam and specially Seam 3 since a few months ago. Recently, new [and big] changes were proposed and commented at IRC channels and at this post (by Shane).

Well, I really didn’t have time to absorb everything, but I’m writing this post to report some thoughts from Seam user’s community who have showed me their opinions.


Seam 3 – The Good points

Seam 3 is pretty different from Seam 2. First, the idea of MODULE is pretty awesome, it allows flexibility, freedom for developing new ideas, Maven integration (yes, was pretty hard with Seam 2); also allows new contributors have more space for implementing their ideas and so on.

Seam 3 – the main problems

I’ve been saying this since I started using Seam 3 – it has several problems. There are few examples (and the existing ones are too simple – and part of that is my fault, I really should have published more posts and tutorials), there are no books about it. Another big problem – Seam is not that simple to use – you need a big skill set to start (JEE – CDI, JSF; Maven; controlling an app server and so on); it’s not like Rails (even if you don’t know Ruby or Active record pattern, or MVC, it IS possible to get something working with Rails, even if your code gets really bad). This not happens to Seam.

Another problem reported by community – what’s Seam goal? I mean, look at Hibernate – it has a main propose – ORM. And Seam 3? Is it CDI? People ask me “Ok, I like Seam 3 modules, but what’s the main goal? For example, I use Seam Social module, but is it really related to CDI?”

These problems have created an awkward situation for developers. Lots of ppl don’t feel comfortable to adopt Seam 3 for production; this scenery  prints an image of unstable or immature framework, which I can say that is completely FALSE. Seam 3 has lots of nice features and solves several problems in an easy way. Unfortunately, I think it’s pretty hard to use; so it scares new JEE users.

Seam 3 – the new proposals

In Shane’s words, due to Seam 3 focus problem – “instead of Seam trying to capture all of the CDI extensions in one place, like Pokemon, we should be trying to propagate them throughout the greater developer community instead.” – and them were presented some changes, like moving Seam persistence, REST and faces modules to other Jboss projects.

Well, community showed their concerns about it (sending me some emails and tweets). Next, a little summary about what ppl said: (ATTENTION – THIS IS NOT MY PERSONAL OPINION)
1. Why did the guys decided it? It was a big change from Seam 2 to 3, and community is not ready for a change like that yet.
2. Ppl don’t believe in compatibility. Some developers already have Seam 3 in production systems and they are really worried about it.
4. “HIBERNATE??” – same guy above
5. “bad shot. The impression that I get is that you are tired of Seam, module leaders are disperse and you are giving up of the project, fitting it into other JBos products”
6. “Seam is gonna die. ok, I’ll start my new project with PlayFMK”
7. “Come on, Red hat should hire more ppl to work with Seam and to write more docs for it, instead killing the project” .
8. “F2F == RIP Seam”
9. Modules created in a not centralized environment, so this generates communication problems and it gets difficult for creating documentation and examples.
10. “WTF??” – Seam new users and ppl that are not directly involved with community contributors or IRC channels.

In my opinion, Seam 3 has some problems (that deserve their own post), but I see good and bad things with the new changes. First, I just think that this approach caused wrong impressions, leading ppl to think the project will die or everyone lost the interest for keeping the project.
I really don’t think Shane, Dan, Pmuir (Pete), Lightguard (Jason), Gastaldi or Lincoln would abort Seam, I mean, I see these guys at IRC channels and I see their passion for the project.
But be careful – how many Open Source projects have you seen that died suddenly? There are lots of dead projects, specially at Ruby Community. Death reasons – LOST their focus, got too complex, few documentation, absence of new features. Unfortunately, Seam 3 has some common problems.
Maybe these new proposed changes help to change this situation, focusing on CDI implementations and joining some correlated modules. But IMHO, it would also weaken Seam identity by merging some parts of it with other projects. I really don’t have a clear idea about the final effects – as I said, there are good and bad parts.


– Seam is not gonna die.
– Everyone who talked to me got a bad impression about these changes. It clearly wasn’t a good approach.
– These changes have good and bad points.
– Seam 3 need more focus and solid examples.

Seam 3 has an absurd potential and more, wonderful contributors building the framework. The only thing I’d like to ask – no panic. Community, keep using Seam 3! It IS nice and powerful. Contributors – that was not the best approach, but move on and keep showing your passion and tech skills by taking care of the framework.

I feel responsible too, I’ll try to do my best to help with examples and tutorials.

I’ll keep blogging about Seam 🙂

Feel free to contact me if you have doubts 🙂



Due to the all this misunderstood, feeling hurts, opposite opinions, doubts and so on, there’s a new post from Shane trying to explain the situation in a better way. As you can see, there’s a thread at Jboss Foum where you can show your opinion about it. Would be nice if you take a few minutes to read, understand the situation and write what you think.

Also, @antoine_sd blogged about it here – very nice post.


September 28, 2011 at 9:07 pm 5 comments

Seam Hack Night – September 8

Hi all!

On the next August 11 at 22:00 UTC * there will be another round of Seam Hack Night! This time for Seam Faces module!
Fork the code and join #seam-dev channel at irc.freenode.net !
This is a great opportunity to help a community project to improve its code! There’s a lot of work to do, so instead of just using the framework, why you don’t help to fix some bugs? Let’s go OSS spirit 🙂
If you don’t know much about Seam 3 project, a good way to start is to take a look here, and do some forks of the modules following these instructions.
If you are not familiar with git or have some questions about how to obtain the source code, or about Maven, you can leave a comment here or send me an email 🙂
So, don’t forget!

September 8, 22:00 UTC

#seam-dev  irc.freenode.net

Faces module – github page

*You can check your timezone here

September 7, 2011 at 6:34 pm 2 comments

The reason I do help Open Source Projects


This is a non-technical post, but I felt inspired to write about it today.

Some days ago a friend of mine asked: “Hey, why do you help Open Source projects? Really, I admire you, but I am not able to waste my time with that”. I almost answered “ORLY YOU FUCKING SELFISH BASTARD”, but instead of that I just said “Oh”, and started to think about a reason for that. Why I do help Open source projects? How did everything start?


A story about my technical career

I went to college to study computer engineering in 2007. Before that, i didn’t know what was a programming language, or what Assembly was, or what was a diode or a capacitor. I was just a stupid, selfish 16-year-old girl. After I got into College, I started to work with software development some time later. Studying (classes were in the morning + afternoon and sometimes in the evening) and working at dawn was really hard. So the only thing I wanted that time was reading my tech books, learning how to use frameworks (OH, FRAMEWORKS LIKE Rails, Spring, Hibernate) and work. Great. There were some events at College about open source, but they were all about Linux Kernel, blah blah, blah, and they never had REAL open source active speakers. So, almost none at College was (and unfortunately almost none is nowadays) an Open source enthusiastic.

Everything was going that way until 2009, when I went to an event called Campus Party. I heard lots of things about ‘open source’ there. And I met lots of Open source enthusiastic people. In other words, for the first time in my life i felt the meaning of… COMMUNITY.

Yet in 2009 I did some extra courses at Caelum, where I could experience another new concept in my life – THE COMMITERS. Yes, people who commit code (and also write tutorials, blog posts and so on) for open source projects. By that time I used to think “Oh, cool, I really would like to help… but hmm, looks too complex. Think I will not be able to write a tutorial for a framework too soon, I am so n00b…. Let me go back to my tech books”.

The truth is… I started to think things like “I really would like to help them…. hmm… looks like a nice idea… But atm I don’t have power to collaborate’.

Some time later I got a big challenge in my professional career – Work with Jboss Seam. I had never seen a piece of code using JBoss Seam. In fact, I had only an unstable idea of what was JBoss Seam. So I got a copy of “Seam in Action” and started reading. I was there, with a framework to learn and put an application up and running with Jboss Seam… Not only with Seam, but also a nice, freaking combo – Seam + Glassfish + Maven + EJBs. Cool. (You guys know that this was a little hard into Seam 2 and Glassfish 2 times). So I started Googling about it, but there were few consistent information about that. “What should I do now? Google can’t help me!! 😦 ” I started getting depressed about that, so I decided to MAKE IT WORK. With the help of a coworker, we did it. Seam 2 + EJB + Maven running on Glassfish 2. Two interns and a crazy project like that running. (Thank you, Andre, I really learned a lot working with you, man). So I thought “I need to write a fixed tutorial about it. Seriously” – and then I created this blog. Every time I had some time off I tried to write some tech stuff on it. That’s why it is called “TI Stuff”. I just wanted that people had consistent information about Seam and Maven [by that time]. I also started to use Twitter and follow cool people (Like the Seam In Action author, a guy called ‘Dan Allen – @mojavelinux – I found his Twitter at Manning’s website)…. I started following some authors from books that I had read read, and I realized how cool they were. So I created a Twitter List, TIHeroes, and added these people into this list. “I really want to be 1/20 of what these guys are”.

With the blog I got some emails with tech questions, post suggestions, new followers at Twitter…. I started to attend to tech conferences in Brazil, join mail-lists… And then I realized that I was HAPPY. But I felt I could do more. People were asking for new tutorials, and they had questions i didn’t know the answer…

Some months later I got into a project where we got a new technology – early-adopters. It was a Ruby project, and some of the gems were pre-alpha… So I started the project and sure, started to find lots of bugs… “And now? Who is going to fix that? I need this framework to do my job!”… Who… And then I think my life changed after thinking about it. “Wait”, I said to myself. “I’ve been using frameworks for years. OPEN SOURCE FRAMEWORKS. Who’s been keeping them? Who fixes the bugs? Who…. – THE COMMUNITY” Sure, usually there are some companies behind the frameworks, but it is COMMUNITY WORK. COMMUNITY. People like me were RESPONSIBLE for the framework. “You become responsible, forever, for what you have tamed”. I am responsible for these frameworks too. I use them. So, instead of just complain, I can do something to help them get better.

Simple actions – report a bug, write tutorials, write blog posts…. I found out that all those little actions can help the community. Even if you don’t write the framework’s core code…. there’s still a lot of things to be done for the community. I will never be the same person after understanding this 🙂

I had a friend who used to say something like “There are no good companies, they do open source for marketing… There’s no open source chocolate”. I won’t discuss that here, but I have to say a little comment – “Open Source work is bidirectional – You improve the project, and the project gives you lots of experience”. I don’t do open source work to be famous. I do open source work because I like to help people. I do open source work because I’m proud of those people who built that framework. Does’t matter if they become inactive, I may consider that people as heroes because they donated their times to make community happy. They have donated their times to give us a new tool or make our lives easiest. Have you ever thought about how boring it would be if we had to write our own ORM framework for every project? Think about that. Imagine If we had to pay to hack Rails or to fix a but on it. “Oh, but there are lots f companies making money with that”, some people will think. The only thing I have to say is “FUCK IT. There are lots of companies making money with good employees. Companies want to make money, and it has nothing to do with my open source passion”. I just want to help people to do their jobs. And yes, these people who collaborate with these projects, they DO HELP MY LIFE. THANK YOU ALL.

I started publishing new posts in my blog, and it started to get lots of views/day. It motivated me to keep helping people. In a busy day of visits, I got a 100+ views at the same day. “Weird – I thought. What’s going on? Let me check the analytics” And then I found out a link referring to my blog – it was a IRC chat log. From a IRC channel – #seam-dev.  Saved a copy of the chat transcription.


[23:52:47] <mojavelinux> check out this blog on seam 3
[23:52:53] <mojavelinux> https://hannelita.wordpress.com/2011/02/22/seam3/
[23:52:57] <mojavelinux> chrome should translate it for you


“Wait, they are talking about my blog! ZOMG! These guys are the Seam guys! Awesome!” Some time later I joined them at IRC and said that I really would be glad to help.


This long story shows a bit of my feelings about open source works. It helped me to be less selfish than I used to be. My family and friends used to say “Workahoolic! Go get a boyfriend!” or “Go take cool stuff to do!”. But the truth is… I AM HAPPY doing that. Seriously happy! I mean, I can help the guys who created the frameworks I use! I can help people who just started with technology X with some information! I can help people who are learning about framework Y by answering their questions! Guys, it’s so cool! Try it once!

I really think people should care a little more about community. I wish I could do much more things that I don’t do because I’m still newbie. But little actions help a lot. You know how good it is to find a nice tutorial on Google that actually works fine and it’s nice to read. But who wrote that? You could write something to improve it, or just post a comment or email the guy who wrote the tutorial saying “Thank you”. A simple feedback is a simple action that can improve community work! 😉

So, I’d like to say thank you to everyone on this list. Heroes.

Thank you, guys. Open source community is very glad to have you in, be sure 🙂


p.s. – I am very proud of you, Seam guys. You cannot image how much I admire you and how much I do like JBoss community. Hope I can help you always 🙂

And sure, I will always admire Ruby community. You guys have some disagreements, but it doesn’t matter to me, I do still admire you the way Ruby community is. Really hope to help you more the next times 😉

August 13, 2011 at 1:31 am 2 comments

Older Posts


  • Blogroll

  • Feeds