HelloWorld With JPA, Hibernate And MySql

I love Hello Worlds. So when I read the blog HelloWorld with JPA, TopLink and MySql I've quickly copied/pasted the code, downloaded everyhting and made it work. Good. But because I'm more a Hibernate user, I thought, let's give it a try with the same example but using Hibernate EntityManager instead of Toplink.

So here is the same simple example of standalone java application using Java Persistence API (JPA), Hibernate, and MySql 5. Here is what you have to do :

<persistence>
<persistence-unit name="hello-world" transaction-type="RESOURCE_LOCAL">
<class>com.foo.Greeting</class>
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/>
<property name="hibernate.hbm2ddl.auto" value="create"/>
<property name="hibernate.connection.url" value="jdbc:mysql://localhost:3306/test"/>
<property name="hibernate.connection.username" value="root"/>
<property name="hibernate.connection.password" value=""/>
<property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver"/>
</properties>
</persistence-unit>
</persistence>

java cp ..\classes;%LIB%\ejb3-persistence.jar;
%LIB%\hibernate-entitymanager.jar;%LIB%\hibernate3.jar;%LIB%\jboss-common.jar;
%LIB%\dom4j-1.6.1.jar;%LIB%\hibernate-annotations.jar;%LIB%\commons-logging-1.0.4.jar;
%LIB%\cglib-2.1.3.jar;%LIB%\javassist.jar;%LIB%\commons-collections-2.1.1.jar;
%LIB%\mysql-connector-java-5.0.3-bin.jar;%LIB%\ehcache-1.2.jar;%LIB%\asm.jar;
%LIB%\jta.jar com.foo.HelloWorld

Comments 0

No comments for this document
Java Champion

Paris JUG Leader

Cast Codeurs

Antonio Goncalves' personal website