These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: JPA and hibernate specification error
PostPosted: Thu Nov 15, 2007 9:35 am 
Beginner
Beginner

Joined: Fri Apr 20, 2007 10:48 am
Posts: 49
Location: France
Hibernate version: 3.2.3

Hi all,

I have a specification bug (not a functional one):

My example is very pedagogic: I have formulas (in groovy, java, ruby etc...) that may need each others in execution time. For tha purpose I made an object that can declare needed formulas. Each formula is in its own row. So a forumla can have be used in many other formulas, and can have many formulas it invokes: this is our many to many relathionship of Formula on itself.

Now formulas are classed in categories: let's say salary formulas and invoice formulas. Both have the same phylosophy.

Let's look at the formula class (uninteresting methods were removed):

Code:
@MappedSuperclass
public class Formula<F extends Formula>
      implements Serializable {
   protected Set<F>               nestedFormulas, parentFormulas;
   protected long                  id;

   @ManyToMany
   @JoinTable(name = "nested_formulas", joinColumns = @JoinColumn(name = "parent_id", referencedColumnName = "id"), inverseJoinColumns = @JoinColumn(name = "child_id", referencedColumnName = "id"))
   public Set<F> getNestedFormulas() {
      return nestedFormulas;
   }

   @ManyToMany(mappedBy = "nestedFormulas")
   public Set<F> getParentFormulas() {
      return parentFormulas;
   }


With this code, it is obvious that we will have our subclasses this way:
Code:
@Entity class SalarayFormula extends Formula<SalarayFormula> {}

Code:
@Entity class InvoiceFormula extends Formula<InvoiceFormula> {}


Generating the schema I realize there is one and only table nested_formulas with foreign keys on both SalarayFormula and InvoiceFormula. S it can't work because there is no "strategy" expression and no discriminator in the table or any other way to know if a many to many row is concerning this or that subclass entity.

There's an easy workaround (writing the dependencies in children classes but the specification should allow us to say: "I'd like to have one class for each dependency, or Id like tohave tem joined with a discrinatorstraegy"...

Any idea about doing things better?

Regards,
Zied Hamdi

_________________
Regards,
Zied Hamdi


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.