Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Does anybody know how to do this in an elegant way? (OTM with existing classes)

 
Carlos Conti
Ranch Hand
Posts: 131
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

I have three classes : ContractTemplate, Clause and Contract. As you may guess Contract bases on ContractTemplate to be initialized and loaded by default. Clause hangs from ContractTemplate in a one-to-many (OTM) relationship. The point is that Contract holds a List (which normally I implement in the ORM via one-to-many) which holds discarded clasuses by the Contract (which won't be used in the contract final draft). I don't know how to translate that to ORM language without creating an additional class class labelled for instance DiscardedClause which would hold a one-to-one relationship with Clause. This is the only way I figure out to keep the model congruent. However my ideal (specially because I havent orm modelled yet, but programmed the whole thing!) would be to be able to hold a new table somewhere where Contract could store references to those discarded Clause instances, but without the need of creating a whole new Class for this sole purpose.
If I don't get any answers I guess I won't have other solution but to create the DiscardedClause class.

Thanks in advance for your help!
Carlos.
 
James Sutherland
Ranch Hand
Posts: 553
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If a Clause can become discarded, then I would just add an isDiscarded property in the Clause (and column to the table). Contract could still have a normal OneToMany to Clause, then you just need two filter methods on your Contract class, getClauses and getDiscardedClauses (only persist getAllClauses()).

You could define separate mappings to both based on the isDiscarded property, but this is beyond JPA, you would need to use vendor extensions for this.
 
Carlos Conti
Ranch Hand
Posts: 131
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi James,
thanks for your answer. I don't know if I understood exactly what you mean. If I understood well, your solution wouldn't be valid, because Clause is in fact a sort of template which hangs from a ContractModel. Then, Contract runs an automated task to construct a text content, based on successive Clause instances from a given ContractModel. Therefore there may be serveral Contract instances which are based on the same ContractModel, and the same set of Clause references, not being able to discard clauses differently among different contracts. Perhaps I haven't made this point clear enough. From my understanding I must create a new class to hold references to a Contract and to a Clause, a one-to-many relationship which holds only clauses which are not taken into account, when writting the Contract.
If you figure out an alternative, please let me know. I would save some re-coding time.
Thanks anyway for taking the time to answer.

Carlos.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic