神刀安全网

NetBeans Java EE Tip #8: Persistence Units

The foundational goals of any good IDE are to simply and organize one’s code and development workflow.  NetBeans does a superb job of achieving these goals, and sometimes we take the basics for granted.  For instance, if your eyes have ever glossed over from trying to read XML in a plain text editor, you may have had issues configuring and working with Persistence Units in the past.  In case you aren’t familiar with Persistence Units, they are XML configuration files that are used by a Java EE project to configure database connections and options.  NetBeans has a very easy-to-use persistence unit wizard, which will be showcased in this post.

For starters, NetBeans provides a wizard for generating a Persistence Unit for a project.  Simply right-click on a project, choose "New" from the context menu, and then choose the "Persistence"->"Persistence Unit" option.

NetBeans Java EE Tip #8: Persistence Units

Next, supply a name for your Persistence Unit, along with a Persistence Provider using the drop-down menu of selections.  You can then choose from an available Data Source, and choose a table generation strategy.

NetBeans Java EE Tip #8: Persistence Units

Once created, the Persistence Unit can be found within the "Configuration Files" folder of a NetBeans project.

NetBeans Java EE Tip #8: Persistence Units

Selecting and double-clicking the file will open the Persistence Unit editor.  NetBeans provides an easy to modify configuration screen for the Persistence Unit that allows changes to be made without working directly with XML.

NetBeans Java EE Tip #8: Persistence Units

For instance, one may wish to add an entity class for use with the Persistence Unit.  To do so, simply click the "Add Class" button and choose the desired class(es).

NetBeans Java EE Tip #8: Persistence Units

If you’d rather work directly with the XML of a Persistence Unit, choose the "Source" button at the top of the editor.  Rather than seeing drab XML, you will be presented with color-coded and an auto-completing XML document.

NetBeans Java EE Tip #8: Persistence Units

Working with history is a breeze with the Persistence Unit configuration within NetBeans.  Choose the "History" button at the top of the editor to see a listing of all changes made to the unit, and it also provides diffs so you can easily see the changes that have been made, and/or apply or revert code, as needed.

NetBeans Java EE Tip #8: Persistence Units

NetBeans provides and easy way to work with Persistence Units.  Forget about dealing with XML within a text editor…you’ll never want to do that again.

转载本站任何文章请注明:转载至神刀安全网,谢谢神刀安全网 » NetBeans Java EE Tip #8: Persistence Units

分享到:更多 ()

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址