|
Fornax-Platform
Forum |
|
View:
New views
7 Messages
—
Rating Filter:
Alert me
|
|
|
Hibernate - Always generate List?Hello,
the question probably sounds a bit weird, but is it possible to let the hibernate cartridge always generate Lists and never Sets? If the cartridge generates a Set, then I have to implement equals/hashCode. The problem is that I have classes that may be equal concerning their attributes, but actually they are not equal. In order to decide whether they are really different I would have to check lots of other associations to other classes. Therefore a simple equals/hashCode implementation is not possible. Due to this reason I wondered whether it would be able to always generate Lists. My first thought was: Ok I look for the part of the xpt which creates the Set and there I change the code in that way that it always create Lists. Besides the fact that I'm not sure whether this really works its a bit ugly as I would have to change the files every time I'm upgrading to a new version of the cartridge. My next thought was: I do not change the extensions but instead I introduce a transformation, which assigns the ordered-Restriction to every affected association. As a consequence of this I do not have to specify "ordered" for every (affected) association. Are there any other possiblities to solve this problem? Can you give me some hints on how to implement the mentioned transformation (if there is no easier solution). I know that I could use the "ordered" for every assocation, but I'm searching for an alternative. Thank you in advance. Best regards, Tom |
|
|
Re: Hibernate - Always generate List?Hello,
what about to overwrite the extension: org::fornax::cartridges::uml::javabasic::m2t::DataType::isSet(uml::MultiplicityElement element) If the new implementation return false allways a list should be generated. You can do this in a non invasive way by using aop. Or you can use the preProcessor (or a own component) to write a model to model transformation. Set all relevant order or unique properties. Note: Only one of the bouth properties 'unique' or 'ordered' is used. You can configure it with setting this property: #Desides if a collaction is realized as 'set' or a 'list' #Collections with UML-Flag 'isOrdered' is mapped to List and mapped to Set else list.set.property = 'order' #Collections with UML-Flag 'isUnique' is mapped to Set and mapped to List else #list.set.property = 'unique' Did I help you? Regards Darius |
|
|
Re: Hibernate - Always generate List?Hello Darius,
thanks for your quick answer. You probably mean ...::uml2::... or? Thanks for the hint, I didn't know that there is this extension. The advantage of using aop would be that I don't have to change the code (of the extension) every time I'm updating the cartridge version (under the assumption that it uses a new version of the javabasic cartridge as well) right? I've seen uses of aop in cartridges at some places, but I have to get a bit more familiar with it in order to do it on my own ;) Wouldn't that approach include writing my own cartridge, which basically "wraps" the existing (javabasic) cartridge? Thats what I meant with the transformation (my second thought), but I have to change the javabasic cartridge anyway, therefore I think I'll choose your first or second approach mentioned. Yes! Thank you very much. Regards Tom |
|
|
Re: Hibernate - Always generate List?You are right :-) Yes, as long as the signature of the extension not change, the behavior will be overwritten. No you do not have to build your own cartridge. Just place an Advice Component in your Workflow.oaw. You see an example in the Hibernate Cartridge: <component adviceTarget="hibernateCartridge_pojo_generator" id="JPAAnnotationAdvice" class="oaw.xpand2.GeneratorAdvice"> <advices value="org::fornax::cartridges::hibernate::m2t::HibernateAnnotations"/> </component> Overwrite Extensions by using the 'extensionAdvices' instead of the 'advices', for example(Just example, not tested) <component adviceTarget="hibernateCartridge_pojo_generator" id="MyAdvices1" class="oaw.xpand2.GeneratorAdvice"> <extensionAdvices value="m2t::MyAdvice"/> </component> <component adviceTarget="hibernateCartridge_mapping_generator" id="MyAdvice2" class="oaw.xpand2.GeneratorAdvice"> <extensionAdvices value="m2t::MyAdvice"/> </component> You need two advice components because because you have to customize the Mappings and the JavaBeans Regards Darius |
|
|
Re: Hibernate - Always generate List?Please try this:
Inside your project put a 'MyAdvice.ext' into a m2t folder. The file contain this code: around org::fornax::cartridges::uml2::javabasic::m2t::DataType::isSet(*) : false; The example workflow.oaw is extended by the two components like described in the last post. Now is looks like this: <workflow> <property file="./workflow.properties"/> <component class="org.openarchitectureware.util.featureconfig.text.TextConfigurationReader"> <configFile value="${feature.model}" /> </component> <bean class="org.openarchitectureware.uml2.Setup" standardUML2Setup="true" /> <component class="org.openarchitectureware.emf.XmiReader"> <modelFile value="${model.file}"/> <outputSlot value="model"/> </component> <component adviceTarget="hibernateCartridge_pojo_generator" id="MyAdvices1" class="oaw.xpand2.GeneratorAdvice"> <extensionAdvices value="m2t::MyAdvice"/> </component> <component adviceTarget="hibernateCartridge_mapping_generator" id="MyAdvice2" class="oaw.xpand2.GeneratorAdvice"> <extensionAdvices value="m2t::MyAdvice"/> </component> <cartridge file="org/fornax/cartridges/uml2/hibernate/hibernate.oaw" inheritAll="true"> <prExcludes value="*.svn-base"/> </cartridge> </workflow> You see, all the changes have to be done inside your project. If you want I can provide this example. By the way: Thank you very much for your question. I think I will extend the provided example project by such an aop example. This will be part of further releases. Regards Darius |
|
|
Re: Hibernate - Always generate List?Thank you very much! I used some exemplary models and the cartridge always generates lists as desired. The extension of the example is a good idea, as the steps are not that obvious for a beginner like me. Regards Tom |
|
|
Re: Hibernate - Always generate List?See: http://fornax.itemis.de/jira/browse/CHB-106 |
| Free embeddable forum powered by Nabble | Forum Help |