-->
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: @ManyToOne in abstract superclass of TABLE_PER_CLASS inhert.
PostPosted: Fri Mar 23, 2012 2:25 pm 
Newbie

Joined: Fri Mar 23, 2012 1:32 pm
Posts: 6
Hibernate 3.2.4.sp1
Hibernate Annotations 3.4.0.GA
MySQL 5.5

I have two tables ACTIVATION and BOOKING, each mapped to a class in the code: Activation and Booking.
There is also a third table called Voucher.

I want the first two classes to inherit from another, abstract, to be called "Operation", without having to create a table for it.

My code is this:

Code:
@Entity
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
@MappedSuperclass
abstract public class Operation implements Serializable {
   private static final long serialVersionUID = -3535901607565756342L;
   protected Long id;
   protected Voucher voucher;
   @Id
   @GeneratedValue(strategy = GenerationType.TABLE)
   @Column(name = "ID", unique = true, nullable = false)
   public Long getId() {
      return this.id;
   }
   public void setId(Long id) {
      this.id = id;
   }
   @ManyToOne(fetch = FetchType.LAZY)
   public Bono getVoucher() {
      return this.voucher;
   }
   public void setVoucher(Voucher voucher) {
      this.voucher = voucher;
   }
}


Code:
@Entity
@AssociationOverride(name="voucher", joinColumns = @JoinColumn(name = "VOUCHER", nullable = true))
@Table(name = "ACTIVATION")
public class Activation extends Operation {
   private static final long serialVersionUID = -2007855148478912920L;
   public Activation() {
   }
   ...
}


Code:
@Entity
@AssociationOverride(name="voucher", joinColumns = @JoinColumn(name = "VOUCHER", nullable = true))
@Table(name = "BOOKING")
public class Booking extends Operation {
   private static final long serialVersionUID = -2007855148478912920L;
   public Booking() {
   }
   ...
}


Code:
@Entity
@Table(name = "VOUCHER", uniqueConstraints = @UniqueConstraint(columnNames = "SERIAL"))
public class Voucher implements java.io.Serializable {
   private static final long serialVersionUID = 7396585840750582396L;
   private Long id;
   ...
   @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "voucher")
   public List<Booking> getBookings() {
      return this.bookings;
   }
   public void setBookings(List<Booking> bookings) {
      this.bookings = bookings;
   }
   @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "voucher")
   public List<Activation> getActivations() {
      return this.activations;
   }
   public void setActivations(List<Activation> activations) {
      this.activations = activations;
   }
   @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "voucher")
   public List<Operation> getOperations() {
      return this.operations;
   }
   public void setOperations(List<Operation> operations) {
      this.operations = operations;
   }
   ...
}


The classes Activation and Booking have no members called "id" nor "voucher", nor the corresponding getters and setters.

So, voucher.getActivations() and voucher.getBookings() work as expected. Now, voucher.getOperations() throws this error in the log:

Code:
19:18:36,187 ERROR [JDBCExceptionReporter] Table 'planbt.Operation' doesn't exist


If I comment out the annotation @MappedSuperclass, then it throws this error:

Code:
19:23:12,062 ERROR [AbstractKernelController] Error installing to Start: name=persistence.unit:unitName=manager.ear/manager.jar#experience state=Create
org.hibernate.AnnotationException: mappedBy reference an unknown target entity property: com.barcelo.experience.model.Activation.voucher in com.barcelo.experience.model.Voucher.activations
   at org.hibernate.cfg.annotations.CollectionBinder.bindStarToManySecondPass(CollectionBinder.java:578)


So it doesn't inherit the properties.


What should I do here?

Any help will be appreciated.


Top
 Profile  
 
 Post subject: Re: @ManyToOne in abstract superclass of TABLE_PER_CLASS inhert.
PostPosted: Mon Mar 26, 2012 9:35 am 
Newbie

Joined: Fri Mar 23, 2012 1:32 pm
Posts: 6
Fixed it.

Added "targetEntity = Operation.class" to the two associations in the class Voucher.

Code:
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "voucher", targetEntity = Operation.class)


@MappedSuperclass must NOT be present. It will not use "union-subclass" inheritance if it is.


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.