-->
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.  [ 2 posts ] 
Author Message
 Post subject: inheritance and interfaces
PostPosted: Tue Jun 07, 2005 7:57 am 
Newbie

Joined: Thu May 26, 2005 8:13 am
Posts: 2
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):
Code:
@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:
Code:
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):
Code:
@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.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 10, 2005 4:43 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Interface mapping as entity is not something that is supported right now. There is a JIRa issue opened for that, but I must admit I'm not sold to this idea so far (I posted some comments in the forum a while ago).

Currently the way to solve your mapping issue is to do
Code:
@ManyToOne(target="my.package.Price")
PriceOwner getPriceOwner()

But this is not what you really want.

_________________
Emmanuel


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

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.