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.