In April I wrote a bit about hooking Mayfly to Hibernate. Well, I finally got around to writing a demo showing how to hook it all up in a small self-contained example.
The demo is only a few dozen lines of code, but instead of repeating the whole thing here, I'll point out some interesting bits. Each test creates its own Database object, so there is no shared state to clear out between tests. The test then calls the openConnection on Database to get a JDBC connection, which the FooPersistence class then passes to the openSession method of Hibernate.
Here I configure Hibernate by instantiating an AnnotationConfiguration, tell it the dialect (Hibernate can't figure this out from the connection, because it needs the dialect before the openSession call), and registering Foo as an entity. If you configure Hibernate via XML mapping files, that would work too.
That's pretty much all that is needed. The dialect file is currently part of the demo, so copy it from there.
Tuesday, September 18, 2007
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment