My requirements are as follows: 1. Convert a schema separately maintained for Oracle and DB2, to Hibernate HBMs with no loss of information. 2. Generate Schema DDLs for Oracle, DB2 and HSQLDB that are at least as expressive as previous schema definition. 3. Export initialization data from existing installation(s) as hibernate XMLs. 4. Import xml initialization data into new installations, where the schema was created with hibernate generated DDLs.
Below is a list of changes I found necessary to fulfill these requirements. -- Specify, reverse engineer and forward engineer (generate DDL) for primary key names. -- There is no place in the HBM to store primary-key names. Although the reverse engineering tool has this information, it can't put it anywhere. Requred changes: - In the hibernate-mapping DTD; on elements "id" and "compsite-id", add attribute "primary-key". Add support to bind this attribute and use in DDL generation. Special considerations: - The current PK_ALIAS_GENERATOR does not guarantee unique names. This needs to be addressed once these names are being used in named constraint creation. - There are two alternatives here in terms of DDL generation. One is to use constraint specification within the create table statement, and the other is to use alter table statement. I prefer the create table approach, and that is the one I implemented. -- Add support for table/index storage clauses -- For our application, where tables have vastly different storage requirements within the same schema, it is essential to be able to specify Oracle storage options. I suggest doing this using meta attributes. -- Transient check in ForeignKeys is suspect -- According to my understanding, using persistence context's "getDatabaseSnapshot" is not sufficient to check whether an entity is transient, since it only checks a cache which is updated on fetch from database. If an entity is being persisted in the same transaction, we need to use "containsEntity(EntityKey)" to establish correct transient state. The effect of this issue is that each entity needs to be committed to the database in order for hibernate to resolve foreign keys correctly during replicate-traversal of an XML document. By adding a call to "containsEntity(EntityKey)" to the "isTransient(String, Object, Boolean, SessionImplementor)" method, the replicate-traversal of the document can be done in a single transaction. Note: I wrote my own XML document repliacte-traversal method, which does not check for hibernate's cascade-replicate settings, since my assumption is that all elements in an XML document are supposed to be replicated irrespective of hibernate setup. -- Support encountering same entity multiple times during replication of XML document -- Subsequent entities should generate updates, with the last one encountered being the "ruling copy". This involves changes to DefaultReplicateEventListener, adding a fetch into the session's persistenceContext cache to see whether there is a copy in the cache before it checks the database for the current version. This is necessary to support importing XML documents that contain complex structures that are not pure trees, i.e. entities can naturally appear multiple times in the document. In most cases they will be identical, so creating an update will do nothing anyway. What we absolutely need to avoid is to create another insert (resulting in a primary key violation). -- Bug in StatefulPersistenceContext, causing classcast exception -- replace: public Object[] getCachedDatabaseSnapshot(EntityKey key) { //TODO: assertion failure if NO_ROW return (Object[]) entitySnapshotsByKey.get(key); } with: public Object[] getCachedDatabaseSnapshot(EntityKey key) { Object result = entitySnapshotsByKey.get(key); if(result==NO_ROW){ return null; } else { return (Object[]) result; } } *------------------------------------------------------------------- In HibernateExt: * Use index information in hbm mapping creation *- Probably add this to Cfg2HbmTool. Needs a new method in Table object, "getIndexesByColumnName" or similar. * Use primary key information in id creation *- In JDBCBinder, set the primary key name for ids. * Use named constraint information in hbm mapping creation -- Requires changes to templates. >>> "Steve Ebersole" <[EMAIL PROTECTED]> 2.3.2006 17:17 >>> The best approach is to first just describe the changes you are proposing at a high level here on this list (i.e. the theory). Then we can discuss the implementation details. -----Original Message----- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Gudlaugur Egilsson Sent: Thursday, March 02, 2006 10:37 AM To: hibernate-devel@lists.sourceforge.net Subject: [Hibernate] Several Patches - sanity check? Hi dear Hibernate developers To begin with, thank you for an excellent ORM product. As a "by-product" of converting the schema definition of our database to hbm-xmls (the first step towards migrating to hibernate), as well as changing the format of our database "bootstrap" data from insert scripts to hibernate-style XML, I've done a number of modifications to Hibernate-core and Hibernate-tools. The impact areas are reverse engineering (e.g. retaining primary-key, foreign-key and index names), HBM parsing and DDL generation (e.g. support specification of foreign-key names) and replication (some issues with replicating nested XML entity elements in a single transaction). Now, obviously, me being a relative noob in hibernate, these changes are probably based on inadequate knowledge in some cases. I'm quite ready to correct the approach used, but I'm thinking it might be more efficient for everyone involved (especially me :-) to send a post to this list describing the changes I've made, and then submit a patch for each change when these changes have been reviewed by some of the developers. What is your preference in this matter? Thanks -Gulli ------------------------------------------------------- This SF.Net email is sponsored by xPML, a groundbreaking scripting language that extends applications into web and mobile media. Attend the live webcast and join the prime developer group breaking into this new coding territory! http://sel.as-us.falkag.net/sel?cmd=k&kid0944&bid$1720&dat1642 _______________________________________________ hibernate-devel mailing list hibernate-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/hibernate-devel ------------------------------------------------------- This SF.Net email is sponsored by xPML, a groundbreaking scripting language that extends applications into web and mobile media. Attend the live webcast and join the prime developer group breaking into this new coding territory! http://sel.as-us.falkag.net/sel?cmd=lnk&kid0944&bid$1720&dat1642 _______________________________________________ hibernate-devel mailing list hibernate-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/hibernate-devel