-->
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: OneToOne with Inheritance
PostPosted: Thu May 29, 2008 5:40 pm 
Regular
Regular

Joined: Fri Oct 05, 2007 1:17 pm
Posts: 78
I am developing a JPA app using Hibernate, and I am trying to utilize the strategy pattern in my entities. Basically, I want an order to contain a 1:1 relationship with a payment without knowledge of whether the payment is a credit card payment, check payment, etc. After all, each kind of payment does its own thing, but there is no need for the order to care.

I have an Order entity that owns a 1:1 relation to a Payment as follows:

Code:
   @OneToOne
   @JoinColumn(name = "ORDER_ID", nullable = false)
   public Payment getPayment() {
      return payment;
   }

   public void setPayment(Payment payment) {
      this.payment = payment;
   }


However, Payment is not an entity. It is just a POJI (with no JPA annotations) that is implemented by an abstract class called PaymentImpl as follows:

Code:
@MappedSuperclass
public abstract class PaymentImpl  {
.
.
.
}


Then finally, I have PaymentImpl extended like this:

Code:
@Entity
@Table(name = "CHECK_PAYMENT")
public class CheckPayment extends PaymentImpl {
.
.
.
}


When I do this though, I get this exception:

Code:
org.hibernate.AnnotationException: @OneToOne or @ManyToOne on com.myapp.persistence.Order.payment references an unknown entity: com.myapp.persistence.sales.Payment


This makes sense to me since the Payment interface isn't an entity, but how can I maintain this object model in the JPA paradigm?

Thanks for your insight.


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.