0 Replies Latest reply on Jun 8, 2005 11:37 AM by herkules

    inheritance and interfaces

    herkules

      Hi,

      I use jboss-EJB-3.0_Preview_5 inside jboss-4.0.1sp1. Each Service will have several Prices valid in different time periods. I cannot deploy the classes, because EJB expects Price to be an Entity, not interface. Is this bug or will this be supported in next version of EJB? How do you solve this kind of relation?

      Thanks for any help, Jan

      The Price class represents price valid for certain time period (price and from/to date properties omitted):

      @Entity
      public class Price implements Serializable {
       private Long id;
      
       private String name;
      
       private PriceOwner priceOwner;
      
       public Price() {
       }
      
       public Price(String name) {
       this.name = name;
       }
      
       @Id(generate = GeneratorType.AUTO)
       public Long getId() {
       return id;
       }
      
       public void setId(Long id) {
       this.id = id;
       }
      
       @Basic
       @Column(nullable = false)
       public String getName() {
       return name;
       }
      
       public void setName(String name) {
       this.name = name;
       }
      
       @ManyToOne(optional = false)
       public PriceOwner getPriceOwner() {
       return priceOwner;
       }
      
       public void setPriceOwner(PriceOwner priceOwner) {
       this.priceOwner = priceOwner;
       }
      }
      


      PriceOwner interface:
      public interface PriceOwner {
       Long getId();
      }
      


      The Service class has one-to-many relation to Price, there will be method to get price at some date (omitted):
      @Entity
      public class Service implements Serializable, PriceOwner {
       private Long id;
      
       private String name;
      
       private Set<Price> prices;
      
       public Service() {
       }
      
       public Service(String name) {
       this.name = name;
       }
      
       @Id(generate = GeneratorType.AUTO)
       public Long getId() {
       return id;
       }
      
       private void setId(Long id) {
       this.id = id;
       }
      
       @Basic
       public String getName() {
       return name;
       }
      
       public void setName(String name) {
       this.name = name;
       }
      
       @Transient
       public Price getMaxInsurance(Date date) {
       return getPrices().iterator().next();
       }
      
       public void addPrice(Price price) {
       price.setPriceOwner(this);
       prices.add(price);
       }
      
       @OneToMany(mappedBy = "priceOwner", cascade = { CascadeType.ALL }, fetch = FetchType.EAGER)
       protected Set<Price> getPrices() {
       return prices;
       }
      
       protected void setPrices(Set<Price> prices) {
       this.prices = prices;
       }
      }
      


      Besides Service class there will be more classes with one-to-many relation to Price class.