The tutorial is as follows.
- Install the maven2 plugin for netbeans
create the maven project using the following command.- mvn archetype:create -DarchetypeGroupId=org.apache.maven.archetypes -DgroupId=edu.wpi.hibernate.test -DartifactId=HibernateTestApp
- Import the project into NetBeans
- Add the maven compiler plugin by following the directions on their website here.
- Add the following dependencies in this order (groupId, artifactID, version)
- (org.hibernate, hibernate, 3.2.6.ga)
- (org.hibernate, hibernate-annotations, 3.3.1.GA)
- (mysql, mysql-connector-java, 5.1.6) [This may vary depending on which DB you choose]
- Create the hibernate.cfg.xml file in "src/main/resources" with the follwing...
- Change the following symbols { and } to <>
- {hibernate-configuration}
{session-factory}
{property name="connection.url"}jdbc:mysql://hobonator/hibernate{/property}
{property name="connection.username"}root{/property}
{property name="connection.password"}root{/property}
{property name="connection.driver_class"}com.mysql.jdbc.Driver{/property}
{property name="dialect"}org.hibernate.dialect.MySQLDialect{/property}
{property name="show_sql"}true{/property}
{property name="format_sql"}true{/property}
{property name="hbm2ddl.auto"}create{/property}
{!-- JDBC connection pool (use the built-in) --}
{property name="connection.pool_size"}1{/property}
{property name="current_session_context_class"}thread{/property}
{/session-factory}
- Change the connections settings to your MySQL server settings
- Add HibernateUtil class like the one shown in the Hibernate tutorial here
- Add a class with Hibernate Annotations
- Add a
inside the node in hibernate.cfg.xml - Run the project, you should see the table and rows have been created in your mySQL DB.
- Run "mvn eclipse:eclipse" in your project folder (assuming that you have maven2 installed correctly in your commandline)
- Install the eclipse maven plugin from here
- Import the project with eclipse
- Run the project with eclipse
No comments:
Post a Comment