Working with hibernate in Eclipse

zhaozj2021-02-16  71

Working with hibernate in Eclipseby

James Elliott, Author of

Hibernate: a developer's notebook

06/23/2004

Introduction

I recently started using Eclipse as my development environment, in part because of its support for the many platforms on which I develop, and in part because Eclipse is a great example of the power of an open, extensible environment in which people all around the world can contribute. I'm beginning to investigate the extensions people have come up with. For example, I use a little plugin called XMLBuddy to work with XML files, and it's very helpful. So I became curious about whether anyone had written plugins to work with Hibernate, since I've done so much of that recently in putting together the Developer's Notebook It turns out there are several such efforts underway;. in this article we will explore one of them - the Hibernate Synchronizer.

Hibernate Synchronizer

Of the plugins I've found so far, the Hibernate Synchronizer interested me most because it seems to best support the kind of mapping-centric workflow I adopted throughout my Developer's Notebook. (Hibernate can be used in many different ways, so check out the other plugins available;. these may be more helpful if your environment calls for another approach) In fact, the Hibernate Synchronizer plugin removes the need for you to think about updating your Java code when you change your mapping document In a very Eclipse-like. way, it automatically updates the Java code as you edit the mapping. But it goes even farther than Hibernate's built-in code generation tools by creating a pair of classes for each mapped object. It "owns" a base class, which it rewrites at will as you change the mapping, and gives you a subclass that extends this base class, where you can put business logic and other code, without fear that it will ever get changed out from under you.ContentsIntroductionHibernate Sy Nchronizer Installation Configuration Generating Code Editing Mappings Generating The Database Schema Trade-Offsother Plugins HiberClipse HibernatorLearning More

As befits an approach centered around the Hibernate mapping document, Hibernate Synchronizer includes a new editor component for Eclipse that provides intelligent assistance and code completion for such documents. A nice DTD-driven XML editor, such as the aforementioned XMLBuddy, can do some of this for you, but Hibernate Synchronizer uses its semantic understanding of the documents to go much further. It also offers a graphical view of the properties and relations in the mapping, "wizard" interfaces for creating new elements, and other such niceties. and, as mentioned, in its default configuration the editor automatically regenerates the data-access classes as you edit their mapping documents.There are other pieces to Hibernate Synchronizer, too. It adds a section to Eclipse's New menu that provides wizards for creating Hibernate configuration and mapping files , And Adds Contextual Menu Entries In The Package Explorer and in Other Appropriate Places, Providing Easy Access To Relevant Hibernate Operations.

OK, enough abstract description, time to get down to the practical stuff! After all, you were already probably interested in this, or you would not have started to read the article. So how do you get and play with Hibernate Synchronizer?

Installation

Hibernate Synchronizer is installed using Eclipse's built-in Update Manager. The plugin offers separate update sites for users of Eclipse 2.1 and the forthcoming Eclipse 3. Because I'm using Eclipse for mission-critical work, I'm still using the production release, 2.1. As I write this, Eclipse 3 has entered its "release candidate" phase, and I am very much looking forward to being able to upgrade to a production release of version 3 when I return from JavaOne later this summer. (The main reason I mention this is to emphasize that the following instructions are written from an Eclipse 2 perspective; some commands and screens are undoubtedly different in Eclipse 3, so if you're using it, be sure to apply your own judgment in following these steps If! it helps, my impression is that Hibernate Synchronizer's own install instructions are written for Eclipse 3.) Fire up Eclipse and open the Update Manager by choosing Help -> Software Updates -.> Update Manager Once the install / Update perspec Tive OpenS Up, Right-Click (or Control-Click, if you're Unsing a One-Button Mouse) in The Feature Updates View and Choose New -> Site Bookmark, AS Shown In Figure 1.

Figure 1. adding the hibernate synchronizer plugin site to the update manager

In The Resulting Dialog, Enter The Url for the Version of The Plugin That You NEED. The Url To Be Entered Depends On Your Eclipse Version:

Eclipse 2.1: http://www.binamics.com/hibernateSync/eclipse2.1 Eclipse 3: http://www.binamics.com/hibernatesync

You also need to assign a name for the new bookmark. "Hibernate Synchronizer" makes a lot of sense. Figure 2 shows the dialog with all required information in my Eclipse 2.1.2 environment. Once you've got it filled in, click Finish To Add the Bookmark.figure 2. Bookmark for the Hibernate Synchronizer Plugin Update Site

Once You Click Finish, The New Bookmark Will Appear in The Feature Updates View, AS Shown In Figure 3.

Figure 3. The Hibernate Synchronizer Site Is Now Available for USE

To actually install the plugin, click on the disclosure triangle to the left of the bookmark, and again on the next one that appears inside of it, until you can see the icon for the plugin itself. When you click on that, the Preview view Will Update to show you an interface tructions you to install the plugin, AS Shown In Figure 4.

Figure 4. Ready to Install the Plugin

Click Install now, And Let Eclipse Walk You Through The Process (Figures 5-10).

Figure 5. Installing Hibernate Synchronizer

Figure 6. The Plugin license agreement

See Trade-Offs, below, for some discussion about this license agreement. You may wish to read it carefully before deciding to use Hibernate Synchronizer in a project of your own. I think it's probably fine, but it is confusingly based on the GPL without Actually being open source.

Figure 7. Choosing where to install the plugin; the default is fine

Figure 8. The Standard Warning for Unsigned Plugins

Figure 9. THE Install is underway

Figure 10. The Install Has Completed

Now that the plugin is installed, you need to quit and relaunch Eclipse for it to take effect. The dialog seems to imply that Eclipse will restart itself, but in my experience, clicking Yes merely causes the environment to quit, and you have to relaunch IT MANUALLY. THIS MAY BE BE A LIMTATION OF Eclipse 2.1 'Mac OS X Implementation; Eclipse 3 Is Going to Be The First Release That Promises "First-Class" Support for OS X. In Any Case, this is a very minor is a very minor issue. If you need to restart Eclipse, Do So Now, Because It's Time To Start Configuring The Plugin To Put Through ITS Paces! ">

CONFIGURATION

Once Eclipse comes back up, you can close the Install / Update perspective. Open a Java project that uses Hibernate. If you've been going through the examples in the Developer's Notebook, you'll have several directories from which to choose. I ' Ll be looking at the examples as the ip...........................

If you're creating a new Eclipse project to work with one of the example source directories, just choose File -> New -> Project, specify that you want to create a Java project and click Next, give it a name ( "Hibernate Ch3 "in my case, as shown in Figure 11), uncheck the Use default checkbox so that you can tell Eclipse where to find the existing project directory, and hit the Browse button to locate where it exists on your own drive. At this point, you can click Finish to create the project, but I generally like to click Next and double-check the decisions Eclipse is making. (Of course, if it gets anything wrong, you can always go back and fix the project properties, but I tend To find it disconcerting to be deleted by a ton of errors and warnings immediately if the is a library missing or something.) Figure 11. Creating a new project to work with hibernate

In this case, my caution was unnecessary. Eclipse figured out exactly how the directory was structured and intended to be used, and found all of the third-party libraries I had downloaded and installed in order to enable Hibernate and the HSQLDB database engine to run . (A detailed walkthrough of this process is the bulk of Chapter 1 of my Developer's Notebook.) This kind of smart adaptability is one of the great features of Eclipse. Figure 12 shows our new project open and ready for experimentation. It also shows that Eclipse Doesn't Like To Fit Into A Window Small ENOUGH for a Reasonable Screen Shot; I'm Going to Have To Work with Partial Window Captures from this Point ON.

Figure 12. The Chapter 3 EXAMPLE PROJECT

The next thing we need to do is create a Hibernate configuration file that Hibernate Synchronizer can use. There is already a hibernate.properties file in the src directory, which is how the examples in the book work, but Hibernate Synchronizer only works with Hibernate's XML -based configuration approach. So we'll need to replicate the contents of hibernate.properties into a new hibernate.cfg.xml file. On the bright side, this gives us our first opportunity to play with a feature of Hibernate Synchronizer, the configuration File Wizard. Choose File -> New -> Other, Click The Newly Available Hibernate Category, Pick Hibernate Configuration File, And Click Next.figure 13. Starting The Hibernate Configuration File Wizard

When the wizard starts up, the directory it offers to put the file into depends on the file you've currently got selected in Eclipse. Let's be sure to put it at the top-level src directory alongside the properties version, for consistency. Fill in the rest of the information requested by the wizard to match the properties version of the configuration, as shown in Figure 14. Notice that, unlike when using Ant to control the execution of Hibernate (which was the approach used in the Developer's Notebook), we have no way to control the current working directory when Hibernate is invoked, so we need to use a fully qualified path to the database file in the URL in my case, this takes the (somewhat ungainly) value jdbc:. hsqldb: / Users / jim / Documents / Work / OReilly / Hibernate / Examples / ch03 / data / music. (If anyone can tell me how to get Eclipse or Hibernate Synchronizer to use a particular working directory for a project, I'd certainly be interested. I 'M Still a Beginner When IT Comes To Eclipse, SO IT Would Not Surprise Me At All to Learn That this Is Possible and That I Simply Don't Know How To Do It.) Figure 14. Filling In The Configuration File Details

Filling in the Driver Class is a little strange: You need to click the Browse button, and start typing the driver name If you type "jdbcD", the window will present only two choices, and you can easily click the right one This.. Is illustrate in Figure 15.

Figure 15. Specifying The HSQLDB Driver Class

Once the wizard is set up to the extent of Figure 14, with values ​​appropriate for your own installation, you can click Finish to create the configuration file. Hibernate Synchronizer is now ready to use. It opens the file it created so you can see the Structure and details of an xml configuration file for hibernate.figure 16. The generated configuration file

A quick way to test that the configuration is working is to play with the other wizard interface Choose File -.> New -.> Other, click the newly available Hibernate category, pick Hibernate Mapping File, and click Next When the wizard comes up, it should be populated with the settings information we just entered, and you can click the Refresh button to make sure it can communicate with the database and show you that it found a TRACK table. The first time you do this, you might have to confirm the location of the .jar file containing the HSQLDB driver, for some reason, but that seems to happen only once. In any case, once you confirm that everything seems to be working, click Cancel rather than actually creating the mapping, because we want To work with our hand-create ketplay file what already exists.

">

GENERATING CODE

..................... ..

If you right-click (or control-click) on one, you get a number of Hibernate-related choices (Figure 17), including one to synchronize. This is a manual way to ask Hibernate Synchronizer to generate the data access objects associated with The mapping document.

Figure 17. Synchronizer Choices for mapping documents

The Add Mapping Reference choice is also useful: it adds an entry to the main Hibernate configuration file telling it about this mapping document, so you do not need to put anything in your source code to request that the corresponding mapping gets set up For. now, let's look at the result of choosing Synchronize Files.This is where things start to get interesting. We end up with two new sub-packages, one for the "base" data access objects that Hibernate Synchronizer "owns" and can rewrite at Any Time, And One for Our Business Objects That Subclass, WHICH WILL NOT GET overwritten, And Give US An Opportunity To Add Business Logic To The Data Class (Shown In Figure 18).

Figure 18. The Synchronized Data Access Objects, Showing Our Editable Subclass

There are many more classes generated this way than by using the normal Hibernate code generation facilities, which has advantages, as well as some potential disadvantages, which I discuss later in the Trade-Offs section. Note also that in the properties configuration for your project , you can choose which of these classes get generated for you, as well as the package structure into which they are generated. I'd demonstrate this, but the current release of the plugin has a bug which blocks access to this configuration interface on Mac OS X. A FIX HAS BEEN MADE, But Not Yet Released.

Based on the examples on the Hibernate Synchronizer page, I put together the following class to try inserting some data into the music database using these new data access objects. It's quite similar to the version using the standard Hibernate code generator (on pages 39-40 of Hibernate: A Developer's Notebook) and even simpler because the classes generated by Hibernate Synchronizer create and commit a new transaction for each of your database operations, so you do not need any code to set one up in simple situations like this (There. are ways of doing so if you need to have a group of operations operate as a single transaction, of course) Here's the code for the new version: package com.oreilly.hh; import java.sql.Time; import java.util. .Date; import net.sf.hibernate.HibernateException; import com.oreilly.hh.dao.TrackDAO; import com.oreilly.hh.dao._RootDAO; / ** * Try creating some data using the Hibernate Synchronizer approach * /. Public class cretetest2 {public static void main (Strin g [] args) throws HibernateException {// Load the configuration file _RootDAO.initialize (); // Create some sample data TrackDAO dao = new TrackDAO (); Track track = new Track ( "Russian Trance", "vol2 / album610 / TRACK02.MP3 ", Time.Valueof (" 00:03:30 "), new date (), (short); DAO.SAVE (TRACK); Track = New TRACK (" Video Killed The Radio Star "," Vol2 / album611 / track12.mp3 ", time.valueof (" 00:03:49 "), new date (), (short) 0); DAO.SAVE (TRACK); // WE Don't even need a track Variable, of Course: DAO.SAVE (New Track ("Gravity's Angel", "/Vol2/Album175/track03.mp3", Time.Valueof ("00:06:06"), New Date (), (Short) 0 );

Having Eclipse around while I was writing this was very nice. I'd forgotten how much I missed intelligent code completion while I was writing the examples for the book, and there are several other things the JDT helps with too.To run this simple program within Eclipse, we need to set up a new Run configuration Choose Run -.> Run ... with CreateTest2.java as the currently active editor file Click on New and Eclipse figures out that we want to run this class in our current project. Because We create it with a main () Method. The default name it assigns, cretetest2, is fine. The screen will lookesthing like Figure 19. Click Run To try. Some Data.

Figure 19. Ready to Run Our Creation Test in Eclipse

If you've been exactly following along on your own, you'll find that this first attempt at execution fails:. Hibernate complains that the configuration file contains no mapping references, and at least one is required Ah ha So that's what XMLBuddy was! warning about with the yellow underline near the bottom of Figure 16. We can easily fix this by right-clicking on the Track.hbm.xml mapping document in the Package Explorer view and choosing Add Mapping Reference in the new Hibernate Synchronizer submenu. That makes XMLBuddy happy, and allows the run to get further. Unfortunately, not as far as we might like, though. The next error was a complaint about not being able to find the JTA UserTransaction initial context in JNDI. It turned out I was not The only perscussed in a.

Since I knew I did not need to use JTA, I wondered why Hibernate was even trying. I opened up the Hibernate configuration file (Figure 16) and looked for anything suspicious that Hibernate Synchronizer had put there. Sure enough, there were some lines that looked like prime suspects: net.sf.hibernate.transaction.JTATransactionFactory java: comp / UserTransaction

Once I tried commenting these out and running again, the third time was indeed the charm. My run completed with no errors, and my data appeared in the database. Hurrah! Running the trusty ant db target (explained in Chapter 1 of the Developer's Notebook ) reveals the data in all its (admittedly simple) glory, as shown in Figure 20. If you're doing this yourself, be sure to start with an ant schema to create the database schema or empty out any test data that may be there From previous experimentation.

Figure 20. The data create by ur test

Note that you can run Ant targets from within Eclipse by right-clicking (or control-clicking) on ​​the build.xml file within the Package Explorer, choosing Run Ant and picking the target using an Eclipse dialog. Pretty cool.

Figure 21. Running Ant from Withnin Eclipse

Getting data back out using queries is pretty straightforward, although this time it's a lot closer to the same code you'd use with the ordinary Hibernate-generated data access classes. Even though Hibernate Synchronizer generates a number of helper methods for working with named queries , I do not think any of them is particularly useful, because they all insist on running the query and returning the list of results, rather than giving you the Query object to work with yourself. That prevents you from using any of Query's convenient type -safe parameter setting methods. Because of that, I decided to stick to having the _RootDAO object give me a Hibernate Session to work with the "old fashioned" way. In fairness, I think I could edit the templates used by Hibernate Synchronizer to generate Any Methods I'D Like, And Would Almost Certainly Look Into Doing That If I WAS Going to Undertake a Project with it. ">

Actually, on further reflection, because you can only work with a Query while you've got an active Session, the methods offered by the DAOs already work the best way they possibly can. You're always going to have to do your own session management if you want to work with the query the way I do in this example. you could embed the session management into the business logic provided in "your" half of the DAO, though, which would give you the best of both worlds. That's Another REASON The Split-Class Model Offered by Hibernate Synchronizer Is So Useful. I Explore this Insight A bit Below.

Anyway, Here's The Code I First Came Up with, MORALLY QUITE Equivalent To That on Pages 48-49 of the book:

package com.oreilly.hh; import java.sql.Time; import java.util.ListIterator; import net.sf.hibernate.HibernateException; import net.sf.hibernate.Query; import net.sf.hibernate.Session; import com .oreilly.hh.dao.TrackDAO; import com.oreilly.hh.dao._RootDAO; / ** * Use Hibernate Synchronizer's DAOs to run a query * / public class QueryTest3 {public static void main (String [] args) throws HibernateException {// Load the configuration file and get a session _RootDAO.initialize (); Session session = _RootDAO.createSession (); try {// Print the tracks that will fit in five minutes Query query = session.getNamedQuery (TrackDAO.QUERY_COM_OREILLY_HH_TRACKS_NO_LONGER_THAN) Query.Settime ("Length", Time.Valueof ("00:05:00")); for (Listiterator iter = query.list (). Listiterator (); it.hasnext ();) {track atrack = TRACK) iter.next (); system.out.println ("track: /" atrack.gettitle () "/", " atrack.getplaytime ());}} finaryly {// no matter what, Close the session session.close ();}}} one nice feature that TrackDAO does give us is a static constant by which we can request the named query, eliminating any chances of run-time errors due to typos in string literals. I appreciate that! Setting up and executing a Run configuration for this test class produces The Output I'd Expect, As Shown In Figure 22.

Figure 22. The Query Results in Eclipse's Console View

As I noted above, after getting this class working, I realized there was a better way to approach it, given the model offered by Hibernate Synchronizer. Here's what our TrackDAO object would look like if we moved the query inside of it, which is where it really belongs, given that the named query is a feature of the mapping file associated with that data access object: package com.oreilly.hh.dao; import java.sql.Time; import java.util.List; import net.sf .hibernate.HibernateException; import net.sf.hibernate.Query; import net.sf.hibernate.Session; import com.oreilly.hh.base.BaseTrackDAO; / ** * This class has been automatically generated by Hibernate Synchronizer * For. more information or documentation, visit The Hibernate Synchronizer page * at http://www.binamics.com/hibernatesync or contact Joe Hudson at joe@binamics.com. * * This is the object class that relates to the TRACK table. * Any Customizations Belong Here. * / Public Class TRACKDAO EXTENDS BaseTrackdao {// Return The TRACKS that fit within a particular length of time public static List getTracksNoLongerThan (Time time) throws HibernateException {Session session = _RootDAO.createSession (); try {// Print the tracks that will fit in five minutes Query query = session.getNamedQuery (QUERY_COM_OREILLY_HH_TRACKS_NO_LONGER_THAN) Query.Settime ("Length", Time); return query.list ();} finally {// no matter what, close the session session.close ();}}}

This is nice and clean, and it simplifies the main () method in querytest3 Even More:

public static void main (String [] args) throws HibernateException {// Load the configuration file and get a session _RootDAO.initialize (); // Print the tracks that fit in five minutes List tracks = TrackDAO.getTracksNoLongerThan (Time.valueOf ( "00:05:00")); for (Listiterator it = tracks.listiterator (); it.hasnext ();) {track atrack = (track) iter.next (); system.out.println ("TRACK: / "" aTrack.getTitle () "/", " aTrack.getPlayTime ());}} Clearly this is the approach to take when working with named queries and Hibernate Synchronizer A quick test confirms that it produces the same. Output, And It's Much Better Code.

Whather or not You Want to Use Hibernate Synchronizer To Generate Its Own Style of Data Access Objects, There is one last major feature to expedition.

Editing mappings

One of the main attractions of Hibernate Synchronizer is its specialized editor for mapping documents This editor can be configured to automatically regenerate the associated data objects whenever you save files, but that's just a final touch;. You might want to use the editor even if you 're not use the Plugin's Code Generator. It Gives You Smart Completion of Mapping Document Elements, And A Graphical Outline View in Which You Can Manipulate Them, AS Well.

There is a trick to getting the editor to work for you, though, at least if you're starting from the downloaded source code from my Developer's Notebook. In the download, the mapping documents are named with the extension ".hbm.xml, "and the editor is only invoked for files ending with" .hbm ". In theory, you can configure the extension mappings within Eclipse so that both extensions use the plugin's mapping document editor, but I was not able to get that to work, And i SAW That Someone else on the support forum had the Same Problem. So, At Least For Now, Your Best Bet May Be To Rename The Files (if You're Going to Stick with Ant-Based Standard Code Generation, Be Sure to update the codegen target in build.xml to use the new extension, too.) As soon as I renamed Track.hbm.xml to Track.hbm, its icon in the Package Explorer was updated to look like the Hibernate logo, and the Default Editor Became The Plugin's, As Shown In Figure 23. For Whate Reason, The Other Hibernate Synchronizer OP TIONS (As Shown In Figure 17) Are Available with Either Extension, But The Editor is Available Only with The Shorter Version.

Figure 23. The contextual menu for a hibernate mapping document (with the extension ".hbm")

. The editor has context-sensitive completion support for all of the elements you're adding within the mapping document Figure 24 shows a couple of examples, but no screen shots can really capture the depth and usefulness of a feature like this; I'd .

Figures 24 and 25. Completion assistance in the mapping document editorThe outline view, shown in Figure 26, gives you a graphical view of the hierarchy of classes, their mapped elements, named queries, and the like that are present in your mapping document, as Well as giving you a menu offering a few wizards to help you create new one.

Figures 26 and 27. The mapping editor's outline view, and the "address" wizard

The contextual menu within the editor itself also offers a Format Source Code option you can use to clean up and re-flow the document. There are already many neat and useful features in this editor, and it'll be interesting to see how it grows in the future. My only complaint (and a minor one at that) is that this editor uses a very different approach to helping you manage quotation marks when you complete XML attributes than the JDT does in Java code. Switching back and forth between them can Be Somewhat Disorienting. (The Way The Jdt Works Takes A Little Getting Used To Itself, But Once You Start Trusting It, It's Almost Magical.)

">

Generating the Database Schema

Despite my first impression that everything flowed from the mapping document, Hibernate Synchronizer does not currently offer any support for creating or updating a database schema from your mapping documents. There has already been a request posted to the support forum about this, and it wouldn 't surprise me if we saw these features in the future; support should not be too difficult For now, you'll have to stick with an approach like the Ant-driven one in Hibernate: A Developer's Notebook if you're developing. your database from your mappings. Alternately, the Hibernator plugin described below does support schema updates from within Eclipse. I may have to investigate whether it's possible to have both of these plugins installed at the same time.Well, I certainly hope this whirlwind tour has Given you an sensor of the capabilities offered by the plugin. i Haven't Covered All of Them, by Any Means, So Do Download It and Explore ON Your Own if anything has intrigued you.

Trade-offs

Clearly you can do some neat things with Hibernate Synchronizer. Will I be using it for my own Hibernate projects? There are some pluses and minuses to that idea, and I probably will not decide until I get to the point of actually adopting Hibernate in place of our homebrew (and very simplistic) lightweight O / R tool at work. that is going to be a significant enough change that we are putting it off until we tackle a major architecture shift that's on the horizon for other reasons. Here are some Of the factory trata will weigh in my decision.

As mentioned in the Installation section, there is a little bit of concern about the license out there. The plugin's forum has a discussion about this. The current license is based on a custom modification of the GNU GPL that removes all the source-sharing provisions , but tries to retain the other aspects of "copyleft" protection. There is some question about the legitimacy of this, and the author is looking for an alternative. It is clear that the intention is to protect the plugin, not to encumber any other Project what happens to use the plugin to generate code, but it it. gence, but it, or if there.

The same discussion reveals that the author had originally released the plugin as open source, but withdrew it temporarily because he felt it was not yet polished enough to serve as a good example to others. He then had some very annoying email interactions with hotheads who , sadly, soured him on the whole idea of ​​sharing the source. It is certainly his prerogative to decide what, if anything, to share with us. The plugin is a gift to the world, and the author does not owe us anything. But I hope that enough positive interactions with other users might help convince him to go back to his original plan of sharing the source. I really value having access to the source code of tools that I use, not only because it is a very valuable learning opportunity, but because it means I (or others) can fix little problems immediately if we need to. The author has been very responsive so far in addressing user concerns, but no one person can keep up as well as a community, and we all Sometimes get bus y, burned out, or otherwise distracted.The fact that Hibernate Synchronizer uses its own templates and mechanism to generate your data access class is both positive and negative. It's positive in that it gives you more capabilities than Hibernate's "standard" code generation tools. The ability to work with an auto-generated subclass of your data object in which you can embed business logic without fear of it getting overwritten when you regenerate the access code is a big plus. And there are other niceties offered by the plugin's generated classes that Make MAKE MANY OF THE SIMPLE CASES EVEN SIMPLER.

On the other hand, this also means that Hibernate Synchronizer's generated code can lag behind Hibernate when there are new features added or changes made to the platform The plugin's code is also more likely to have bugs in its support for Hibernate's less-used modes.: it has a much smaller user base, and a single person keeping it updated. you can see evidence of this phenomenon on the discussion forum.As with so many things, it's up to you to decide whether the potential benefits outweigh the risks. Even if You don't use the code generator, you might find the mapping editor extremely useful. You can you want to just use the editor's completion and assistance features.

If you do adopt the plugin and find it usful, I would definitely Encourage you to contact the author and thank our Money to Help Support ITS Further Development.

Other Plugins

In my hunting so far, I've encountered two more plugins that offer support for Hibernate within Eclipse. (If you know of others, or come across them in the future, I'd be interested in learning about them.) Perhaps I ' LL Write Articles About these in the fulure.

HiberClipse

The HiberClipse plugin looks like another very useful tool. It seems geared towards a database-driven workflow, where you've already got a database schema and want to build a Hibernate mapping file and Java classes to work with it. This is a common scenario , and if you find yourself facing such a challenge, I'd definitely recommend checking out this plugin. One really cool feature it offers is a graphical "relationships view" of the database you're working with, right within Eclipse. (I should point out that Hibernate Synchronizer does not leave you high and dry if you want to start with an existing database schema, either. Its New Mapping File Wizard can connect to your database and build the mapping file based on what it finds.) Figure 28 Hibernate Synchronizer's mapping wizard

Hibernator

Finally, Hibernator seems to lean in the opposite direction, starting from your Java code to generate a simple Hibernate mapping document, and then from there letting you build (or update) the database schema. It also offers the ability to run database queries within Eclipse . of the three plugins, it appears to be at the earliest stages of development, but already looks worth keeping an eye on, especially since it cites members of the Hibernate development team as contributors.

Learning more

If I've managed to pique your interest in this article, there are plenty of resources to help you dig deeper into these topics. In addition to the sites I've linked to throughout the text, there are some books that might interest you. of course, I have to mention my own, Hibernate:. A Developer's Notebook For in-depth reference material about Hibernate, the online documentation is very useful, especially the reference manual, and there is a forthcoming book by the developers of Hibernate itself, Hibernate in Action. I look forward to reading that myself.As for Eclipse, I'm currently working through Steve Holzner's Eclipse and looking forward to the Eclipse Cookbook that will be released later this month. My blog discusses my Eclipse "conversion" in more detail in case you're curious about that (or teetering on the edge yourself). If you're just getting started, be sure to explore the "Getting Started" sections of Eclipse's built-in Workbench and Java Development user guides. These show you how the environment is intended to be used, give you some good suggestions, and walk you through processes and features you might not otherwise discover quickly on your own Choose Help -.> Help Contents within Eclipse to find them.

转载请注明原文地址:https://www.9cbs.com/read-17947.html

New Post(0)