#536 - @ManyToOne with @JoinColumn throw error - Update tests

This commit is contained in:
Robin Bygrave
2016-01-26 16:41:15 +13:00
parent 6be26aaff2
commit 38dd3d82fc
3 changed files with 29 additions and 9 deletions
@@ -1,8 +1,7 @@
package com.avaje.tests.basic.one2one;
import java.util.List;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
@@ -12,6 +11,7 @@ import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.persistence.Version;
import java.util.List;
@Entity
@Table(name = "drel_booking")
@@ -19,9 +19,16 @@ public class Booking {
@Id @GeneratedValue(strategy = GenerationType.SEQUENCE)
private Long id;
@Column(unique = true)
Long bookingUid;
@Version
private int version;
public Booking(Long bookingUid) {
this.bookingUid = bookingUid;
}
@OneToOne(cascade = CascadeType.ALL)
@JoinColumn(name = "agent_invoice")
@@ -31,7 +38,7 @@ public class Booking {
@JoinColumn(name = "client_invoice")
private Invoice clientInvoice;
@OneToMany(mappedBy = "booking")//, cascade = CascadeType.ALL)
@OneToMany(mappedBy = "booking")
private List<Invoice> invoices;
public Long getId() {
@@ -41,8 +48,16 @@ public class Booking {
public void setId(Long id) {
this.id = id;
}
public int getVersion() {
public Long getBookingUid() {
return bookingUid;
}
public void setBookingUid(Long bookingUid) {
this.bookingUid = bookingUid;
}
public int getVersion() {
return version;
}
@@ -69,7 +84,7 @@ public class Booking {
public List<Invoice> getInvoices() {
return invoices;
}
public void setInvoices(List<Invoice> invoices) {
this.invoices= invoices;
}
@@ -21,7 +21,7 @@ public class Invoice {
private int version;
@ManyToOne(cascade = CascadeType.ALL)
@JoinColumn(name = "booking")
@JoinColumn(name = "booking")//_xid", referencedColumnName = "booking_uid")
private Booking booking;
public Long getId() {
@@ -10,7 +10,9 @@ public class TestOne2OneBookingInvoice extends BaseTestCase {
@Test
public void test() {
Booking b = new Booking();
Booking b = new Booking(3000L);
Ebean.save(b);
Invoice ai = new Invoice();
Invoice ci = new Invoice();
@@ -23,6 +25,9 @@ public class TestOne2OneBookingInvoice extends BaseTestCase {
Ebean.save(b);
Invoice invoice = Ebean.find(Invoice.class, ai.getId());
Assert.assertEquals(b.getId(), invoice.getBooking().getId());
Booking b1 = Ebean.find(Booking.class, b.getId());
Invoice ai1 = b1.getAgentInvoice();