First implementation of Hibernate support for netbeans uses J2SE netbeans project. Before you create your first Hibernate Bean create new J2SE project (File|New Project) .
First Hibernate Bean
After you created J2SE project you can create first Hibernate Bean. Select a java package in project view of your J2SE project and info New File wizard. Select Hibernate Bean from Xdoclet/Hibernate folder.
And click to next button. The Name and location panel will be shown.
Type a name of the new hibernate bean. For example User. Click to Next button. The Key panel will be shown.
In the Key panel you specify the primary key for hibernate bean. The name field is name of variable used in hibernate bean. The type is used java type. You can specify the internal hibernate type and name of the property. But it is not necessary to do it (The name will be used). You can also change the default database field name in the SQL type fild. To go to next panel clock to Next button.
You are now editing the persistent properties. You can skip this steps and add the properties using hibernate templates in code completion dialog of hibernate class in editor. If you want to add a hibernate property to the hibernate bean click to Add button. The Hibernate Property customizer will be shown.
For example you want to add
firstName property of
java type. Set the value of Name field to the
to the Type field value
String. Click to Ok button.
The new property was added into properties table. You can delete or modify the
property using Delete od Modify button.
When all properties are specified you can click to finish button.
Project extensionNow you can customize. the Hibernate Extension setting for the j2se. It is simplier way how to add the ant task usefull for:
- generating hibernate descriptors hbm.xml
- creating db schema for database
The Select Hibernate Folder dialog was shown.
The NetBeans IDE are asking you to select unpacked folder of hibernate distribution. The hibernate distribution (Hibernate Core) can be download from Hibernate download page. So download the distribution and unpack it. Click to Browse button to select unpacked filder of Hibernate distribution. After selecting the Hibernate folder you can click to Ok button.
The dialog for initialization of jdbc driver (dialect) was shown.
- MS SQL Server
The waiting dialog will be shown till the driver is downloaded. After the driver is downloaded it will be be checked if the xdoclet lobraries are available in Library Manager. If the libraries are not available another questioning dialog will be shown.
Click to Ok button and wait till the xdoclet's libraries will be downloaded. Wow, the Hibernate extension was added to Ant's features extensions of your project. The customizer was shown.
In the Hibernate extension you can define:
- used database driver
- building hibernate descriptors from xml beans during building
- generating database dialect during building application
- initalizing database
To close the Properties dialog click to Ok button.
The Hibernate project exception was added to Project Extensions Window.
Now the code is generated. You can look at generated code of Hibernate bean:
And unfolded bean...
You can try to build your first hibernate application. Look into build/classes folder. There are generated hibernate descriptors.