[Hibernate] Several Patches - sanity check?

2006-03-02 Thread Gudlaugur Egilsson
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=lnk&kid0944&bid$1720&dat1642
___
hibernate-devel mailing list
hibernate-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/hibernate-devel


RE: [Hibernate] Several Patches - sanity check?

2006-03-14 Thread Gudlaugur Egilsson
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 -

[Hibernate] Named primary key constraints

2006-03-17 Thread Gudlaugur Egilsson
Hi

I sent a post recently (too detailed obviously, since noone has
commented on it :-) regarding some features we require that hibernate is
currently not implementing. So here goes again, one more descriptive
post per feature.

One of those is explicitly named primary key constraints. The basic
theory is that instead of primary keys being declared in a DDL in a
manner such as:

create table y
   k number(19,0),
   f varchar(2),
primary key(k)

it should be possible to declare as

create table y
   k number(19,0),
   f varchar(2),
constraint pk_y primary key(k)

This is a syntax supported by many databases, at least Oracle, DB2 and
HSQLDB (those I have tested).

For starters, hbm.xml files need a place to store the primary key name.
Primary keys are associated with
id elements in Hibernate (id, composite-id), so it seems
straightforward to associate a "primary-key" attribute
to those elements. 

We then need code changes to bind those attributes and make them
available for DDL generation. This almost
certainly means an addition to the Dialect class as well.

Please let me know if I'm not approaching this from the right angle...

Thanks

-Gudlaugur Egilsson


---
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&kid=110944&bid=241720&dat=121642
___
hibernate-devel mailing list
hibernate-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/hibernate-devel


[Hibernate] Primary key names and storage meta-attributes

2006-07-27 Thread Gudlaugur Egilsson
Hi

I submitted a patch regarding named primary-keys and storage option 
meta-attributes some months ago (HHH-1766), but no one has commented on it. I'm 
just curious as to 1) if there is a chance that this patch will be applied and 
2) if there is anything I can do (other than spamming this mailing-list :-) to 
make that more likely to happen.

Thanks
-Gulli


-
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
___
hibernate-devel mailing list
hibernate-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/hibernate-devel


[Hibernate] StatefulPersistenceContext

2006-07-28 Thread Gudlaugur Egilsson
Hi

A while back, I tweaked Hibernate in order to get it to replicate XML
elements properly when an element is referring to another element in the
same XML structure. As the code was/is, it only checks for existence in
the database, not in the session cache, making it impossible to
replicate such elements in a single transaction.

Example:


151
PDI
SBR:Delivery Data


151
151