mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
No effective change -Add test: Truck, Car, Wheel plus test code cleanup
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
package com.avaje.tests.model.carwheeltruck;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.persistence.CascadeType;
|
||||
import javax.persistence.DiscriminatorColumn;
|
||||
import javax.persistence.DiscriminatorValue;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.Inheritance;
|
||||
import javax.persistence.InheritanceType;
|
||||
import javax.persistence.OneToMany;
|
||||
|
||||
@Entity
|
||||
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
|
||||
@DiscriminatorColumn(name = "type")
|
||||
@DiscriminatorValue("car")
|
||||
public class TCar {
|
||||
|
||||
@Id
|
||||
String plateNo;
|
||||
|
||||
@OneToMany(cascade = CascadeType.ALL)
|
||||
List<TWheel> wheels;
|
||||
|
||||
public String getPlateNo() {
|
||||
return plateNo;
|
||||
}
|
||||
|
||||
public void setPlateNo(String plateNo) {
|
||||
this.plateNo = plateNo;
|
||||
}
|
||||
|
||||
public List<TWheel> getWheels() {
|
||||
return wheels;
|
||||
}
|
||||
|
||||
public void setWheels(List<TWheel> wheels) {
|
||||
this.wheels = wheels;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package com.avaje.tests.model.carwheeltruck;
|
||||
|
||||
import javax.persistence.DiscriminatorColumn;
|
||||
import javax.persistence.DiscriminatorValue;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Inheritance;
|
||||
import javax.persistence.InheritanceType;
|
||||
|
||||
@Entity
|
||||
@Inheritance(strategy=InheritanceType.SINGLE_TABLE)
|
||||
@DiscriminatorColumn(name="type")
|
||||
@DiscriminatorValue("truck")
|
||||
public class TTruck extends TCar {
|
||||
|
||||
Long load;
|
||||
|
||||
public Long getLoad() {
|
||||
return load;
|
||||
}
|
||||
|
||||
public void setLoad(Long load) {
|
||||
this.load = load;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package com.avaje.tests.model.carwheeltruck;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.ManyToOne;
|
||||
|
||||
@Entity
|
||||
public class TWheel {
|
||||
|
||||
@Id
|
||||
Long id;
|
||||
|
||||
@ManyToOne(optional=false)
|
||||
TCar owner;
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public TCar getOwner() {
|
||||
return owner;
|
||||
}
|
||||
|
||||
public void setOwner(TCar owner) {
|
||||
this.owner = owner;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package com.avaje.tests.model.carwheeltruck;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import com.avaje.ebean.BaseTestCase;
|
||||
import com.avaje.ebean.Ebean;
|
||||
|
||||
public class TestTruckCarWheelInhertiance extends BaseTestCase {
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
|
||||
TTruck truck = new TTruck();
|
||||
truck.setPlateNo("foo");
|
||||
|
||||
TWheel wheel = new TWheel();
|
||||
wheel.setOwner(truck);
|
||||
|
||||
Ebean.save(truck);
|
||||
|
||||
// This save() works ok...
|
||||
|
||||
// But if then is added one more wheel
|
||||
wheel = new TWheel();
|
||||
wheel.setOwner(truck);
|
||||
|
||||
// And save() is called again
|
||||
Ebean.save(truck);
|
||||
|
||||
// Then an exception is raised:
|
||||
}
|
||||
|
||||
}
|
||||
@@ -2,8 +2,7 @@ package com.avaje.tests.query.other;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import junit.framework.Assert;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.avaje.ebean.BaseTestCase;
|
||||
|
||||
@@ -3,8 +3,6 @@ package com.avaje.tests.query.other;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.validation.constraints.AssertTrue;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import com.avaje.ebean.BaseTestCase;
|
||||
@@ -56,7 +54,7 @@ public class TestManyLazyLoadingQuery extends BaseTestCase {
|
||||
|
||||
beanProperty.addWhereParentIdIn(query0, parentIds);
|
||||
|
||||
List<?> list0 = query0.findList();
|
||||
query0.findList();
|
||||
|
||||
} finally {
|
||||
Ebean.endTransaction();
|
||||
|
||||
@@ -2,8 +2,7 @@ package com.avaje.tests.query.other;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import junit.framework.Assert;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.avaje.ebean.BaseTestCase;
|
||||
|
||||
Reference in New Issue
Block a user