From: Max R. A. <ma...@eo...> - 2002-10-22 16:37:12
|
Hi! While trying to make a build environment that given some ErWin generated SQL generates, some hbm.xml and from this generate java sources for both class and proxy interfaces I have found some shortcomings in the current codegenerator :( 1. Codegenerator does not support composite-id's 2. You cannot generate code from hbm.xml and then generate proxies without manual intervention ;( This is because the proxy generation depends on java reflection and java reflection requires .class files. But if you are using proxies in the hbm.xml file then the generated code cannot compile because it is using the not-yet generated proxy interfaces :) - its a chicken-egg problem :) What I would suggest is to have the codegenerators and proxygenerator use the metadata package instead of parsing the xml manually! What good is that for ? well 2 things: 1. Code for parsing hbm.xml will only be written ONCE! 2. By having the codegenerator and proxygenerator use metadata one is sure they are using the same information to generate the code...(as they do not do know :) Secondly, I would suggest some kind of custom-attribute stuff like the one provided in OJB. Then one could agument the definitions in hbm.xml with custom attributes which could be used for codegeneration and other generic purposes runtime (if it was available via the metadata package) So, e.g. extend ClassMetaData and CollectionMetaData with getCustomAttribute(key) which could be set by a e.g. <customattrib key="relinfo" value="weak reference"/> embedded in <class> tags. Anyone already doing this ? :) /max |
From: Gavin K. <ga...@ap...> - 2002-10-24 11:31:02
|
> This is because the proxy generation depends on java reflection and java > reflection requires .class files. > But if you are using proxies in the hbm.xml file then the generated code > cannot compile because it is using the not-yet generated proxy interfaces > :) - its a chicken-egg problem :) Yes, pretty yucky. > > What I would suggest is to have the codegenerators and proxygenerator use > the metadata package instead of parsing the xml manually! *Much* saner. The reason it is the way it is currently is that the individual bits of the toolset were done by different people at different times, with no real overarching vision. > 1. Code for parsing hbm.xml will only be written ONCE! :) > Secondly, I would suggest some kind of custom-attribute stuff like the one > provided in OJB. Then one could agument the definitions in hbm.xml with > custom attributes which could be used for codegeneration and other generic > purposes runtime (if it was available via the metadata package) Yeah, that would be cool. > Anyone already doing this ? :) Nope, I thought *you* owned the CodeGenerator now...... ;) |
From: Gavin K. <ga...@ap...> - 2002-10-24 12:22:02
|
> But now we do not NEED the proxies so it is better now, but not perfect > (since someone might > like to have proxies :) You still need proxies for polymorphic persistence. Check out the latest doco on the website for an explanation...... > Any suggestions on formats/semantics of it all ? (property and attribute are > dubious names in > this db context, so is custom-attribute a good tag-name/metadata name for > it ?) How about <metadata name="foo" value="bar"/> > I would love to contribute the above mentioned stuff, if I had a clear > vision on the existing parsing and building > of metadata info in Hibernate....and currently it seems that Hibernate > CANNOT parse an hbm.xml without > having the related classes in its classpath ...and that is somewhat of an > limitiation when it is a codegenerator that > is about to generate these classes :) Good point. > Anyone with a clear vision and understanding of hibernates hbm.xml parsing > that can untangle that web of assumptions > in the hibernate core ? Okay, there are two levels of metadata. The "parsed" metadata, represented by the cirrus.hibernate.map package and the "compiled" metadata which is really just the internal state of the EntityPersisters. You have no chance of using the compiled metadata. On the other hand, it would be reasonably easy to remove any references to actual classes from the cirrus.hibernate.map package which is used to represent the internal state of Datastore. If you could clean up that package a little bit, it would probably do what you want. Now, that package is definately not meant to be exposed to users, but you might be able to expose it to the toolset. |
From: Gavin K. <ga...@ap...> - 2002-10-27 15:25:13
|
Unfortunately, the parsing code sucks. It sucks because (a) it was written to "do the job", not be elegant (b) it uses DOM (c) there are a lot of places where things are implied by a combination of the mapping file and the class itself We could fix (b) by chucking the whole .map package and re-doing it using some databinding fwk. I'm not sure whats the best for databinding currently though. I would actually very much like to do this, to get rid of ugly code. However, currently the design of the map package has not been a problem for _me_ in the functionality I've been concentrating upon. (c) is more difficult since it means that plenty of perfectly legitimate mapping files can't be fully compiled without the classes. However, if we chucked + re-did with databinding, we would need a second-pass to fill in reflected values *anyway*, so maybe there is also a way forward there. Now, if it turns out to be worthwhile doing this, there is one thing working in our favor. We have heaps of unit tests, so we shouldn't need to be worried about breaking things. ----- Original Message ----- From: "Max Rydahl Andersen" <ma...@eo...> To: "Gavin King" <ga...@ap...> Sent: Monday, October 28, 2002 1:33 AM Subject: Re: [Hibernate] Metadata, codegenerator et.al... > > > Any suggestions on formats/semantics of it all ? (property and attribute > > are > > > dubious names in > > > this db context, so is custom-attribute a good tag-name/metadata name > for > > > it ?) > > > > How about <metadata name="foo" value="bar"/> > > So, we got a metadata to augment/describe the metadata - well, I suppose > that's the > way it is supposed to be :) > > > > I would love to contribute the above mentioned stuff, if I had a clear > > > vision on the existing parsing and building > > > of metadata info in Hibernate....and currently it seems that Hibernate > > > CANNOT parse an hbm.xml without > > > having the related classes in its classpath ...and that is somewhat of > an > > > limitiation when it is a codegenerator that > > > is about to generate these classes :) > > > > Good point. > > > > > Anyone with a clear vision and understanding of hibernates hbm.xml > parsing > > > that can untangle that web of assumptions > > > in the hibernate core ? > > > > Okay, there are two levels of metadata. The "parsed" metadata, represented > > by the cirrus.hibernate.map package and the "compiled" metadata which is > > really just the internal state of the EntityPersisters. > > > > You have no chance of using the compiled metadata. On the other hand, it > > would be reasonably easy to remove any references to actual classes from > the > > cirrus.hibernate.map package which is used to represent the internal state > > of Datastore. If you could clean up that package a little bit, it would > > probably do what you want. Now, that package is definately not meant to be > > exposed to users, but you might be able to expose it to the toolset. > > I've tried to dig into the map package, but it seems there is waaay to many > places > the code tries to do a classForName to check if it can continue to do its > parsing - > and by waaay to many, I mean waaay to many for me to go changing the parse > semantics :( > > So, I'll try to "just" add the metadata tag stuff...that should be doable > without changing much > of the semantics, but it sure won't be as usable when the parser still > requires the classes to > be available ;( > > /max |