#919 - io.ebean package initial

This commit is contained in:
Rob Bygrave
2016-12-11 23:23:22 +13:00
parent 5821dc96b9
commit 971e2dc91b
2134 changed files with 10721 additions and 8652 deletions
@@ -0,0 +1,47 @@
package org.tests.inheritance;
import javax.persistence.DiscriminatorValue;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.OneToOne;
/**
*/
@Entity
public class InnerReport {
@Id
Long id;
String name;
@OneToOne
Forecast forecast;
public Forecast getForecast() {
return forecast;
}
public void setForecast(Forecast forecast) {
this.forecast = forecast;
}
@Entity
@DiscriminatorValue("F")
public static class Forecast extends Stockforecast {
@ManyToOne
InnerReport innerReport;
public InnerReport getInnerReport() {
return innerReport;
}
public void setInnerReport(InnerReport innerReport) {
this.innerReport = innerReport;
}
}
}
@@ -0,0 +1,26 @@
package org.tests.inheritance;
import javax.persistence.DiscriminatorColumn;
import javax.persistence.DiscriminatorType;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
@Entity
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name = "type", discriminatorType = DiscriminatorType.STRING)
public abstract class Stockforecast {
@Id
private Long id;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
}
@@ -0,0 +1,50 @@
package org.tests.inheritance;
import io.ebean.BaseTestCase;
import io.ebean.Ebean;
import org.tests.model.basic.AttributeHolder;
import org.tests.model.basic.ListAttribute;
import org.tests.model.basic.ListAttributeValue;
import org.junit.Assert;
import org.junit.Test;
public class TestDuplcateKeyException extends BaseTestCase {
/**
* Test query.
* <p>This test covers the BUG 276. Cascade was not propagating to the ListAttribute because
* it was considered safe to skip as it didn't take into account any derived classes
* into account with e.g. collections and Cascade options </p>
*/
@Test
public void testQuery() {
// Setup the data first
final ListAttributeValue value1 = new ListAttributeValue();
Ebean.save(value1);
final ListAttribute listAttribute = new ListAttribute();
listAttribute.add(value1);
Ebean.save(listAttribute);
final AttributeHolder holder = new AttributeHolder();
holder.add(listAttribute);
try {
Ebean.execute(() -> {
//Ebean.currentTransaction().log("-- saving holder first time");
// Alternatively turn off cascade Persist for this transaction
//Ebean.currentTransaction().setPersistCascade(false);
Ebean.save(holder);
//Ebean.currentTransaction().log("-- saving holder second time");
// we don't get this far before failing
//Ebean.save(holder);
});
} catch (Exception e) {
Assert.assertEquals(e.getMessage(), "test rollback");
}
}
}
@@ -0,0 +1,122 @@
package org.tests.inheritance;
import io.ebean.BaseTestCase;
import io.ebean.Ebean;
import io.ebean.Query;
import org.tests.model.basic.Car;
import org.tests.model.basic.CarAccessory;
import org.tests.model.basic.CarFuse;
import org.tests.model.basic.Truck;
import org.tests.model.basic.Vehicle;
import org.tests.model.basic.VehicleDriver;
import org.junit.Test;
import java.util.List;
import static org.assertj.core.api.StrictAssertions.assertThat;
import static org.junit.Assert.*;
public class TestInheritInsert extends BaseTestCase {
@Test
public void testCasting() {
Truck t = new Truck();
t.setCapacity(10d);
Ebean.save(t);
Vehicle v = Ebean.find(Vehicle.class, t.getId());
if (v instanceof Truck) {
Truck t0 = (Truck) v;
assertEquals(Double.valueOf(10d), t0.getCapacity());
assertEquals(Double.valueOf(10d), ((Truck) v).getCapacity());
assertNotNull(t0.getId());
} else {
assertTrue("v not a Truck?", false);
}
VehicleDriver driver = new VehicleDriver();
driver.setName("Jim");
driver.setVehicle(v);
Ebean.save(driver);
VehicleDriver d1 = Ebean.find(VehicleDriver.class, driver.getId());
v = d1.getVehicle();
if (v instanceof Truck) {
Double capacity = ((Truck) v).getCapacity();
assertEquals(Double.valueOf(10d), capacity);
assertNotNull(v.getId());
} else {
assertTrue("v not a Truck?", false);
}
List<VehicleDriver> list = Ebean.find(VehicleDriver.class).findList();
for (VehicleDriver vehicleDriver : list) {
if (vehicleDriver.getVehicle() instanceof Truck) {
Double capacity = ((Truck) vehicleDriver.getVehicle()).getCapacity();
assertEquals(Double.valueOf(10d), capacity);
}
}
}
@Test
public void testQuery() {
Car car = new Car();
car.setLicenseNumber("MARIOS_CAR_LICENSE");
Ebean.save(car);
VehicleDriver driver = new VehicleDriver();
driver.setName("Mario");
driver.setVehicle(car);
Ebean.save(driver);
Query<VehicleDriver> query = Ebean.find(VehicleDriver.class);
query.where().eq("vehicle.licenseNumber", "MARIOS_CAR_LICENSE");
List<VehicleDriver> drivers = query.findList();
assertNotNull(drivers);
assertEquals(1, drivers.size());
assertNotNull(drivers.get(0));
assertEquals("Mario", drivers.get(0).getName());
assertEquals("MARIOS_CAR_LICENSE", drivers.get(0).getVehicle().getLicenseNumber());
Vehicle car2 = Ebean.find(Vehicle.class, car.getId());
car2.setLicenseNumber("test");
Ebean.save(car);
}
@Test
public void test_AtOrderBy_on_ChildOfChild() {
Car car = new Car();
car.setLicenseNumber("ABC");
Ebean.save(car);
CarFuse fuse = new CarFuse();
fuse.setLocationCode("xdfg");
Ebean.save(fuse);
CarAccessory accessory = new CarAccessory(car, fuse);
Ebean.save(accessory);
Query<Car> query = Ebean.find(Car.class)
.fetch("accessories")
.where()
.eq("id", car.getId())
.query();
Car result = query.findUnique();
assertThat(query.getGeneratedSql()).contains("order by t0.id, t2.location_code");
assertThat(query.getGeneratedSql()).contains("left join car_fuse t2 on t2.id = t1.fuse_id");
assertNotNull(result);
}
}
@@ -0,0 +1,41 @@
package org.tests.inheritance;
import io.ebean.Ebean;
import org.tests.model.basic.Car;
import org.tests.model.basic.Truck;
import org.tests.model.basic.Vehicle;
import org.junit.Test;
import java.util.List;
import static org.assertj.core.api.Assertions.assertThat;
public class TestInheritanceBatchLazyLoad {
@Test
public void lazyLoadProperty_when_propertyNotOnAllInheritanceTypes() {
Car c = new Car();
c.setLicenseNumber("VZVZ1");
c.setDriver("CarDriver");
Ebean.save(c);
Truck t = new Truck();
t.setLicenseNumber("VZVZ2");
t.setCapacity(20D);
Ebean.save(t);
List<Vehicle> list = Ebean.find(Vehicle.class)
.select("licenseNumber")
.where().startsWith("licenseNumber", "VZVZ")
.order().asc("licenseNumber")
.findList();
assertThat(list).hasSize(2);
Car car = (Car) list.get(0);
car.getNotes();
}
}
@@ -0,0 +1,115 @@
package org.tests.inheritance;
import io.ebean.BaseTestCase;
import io.ebean.Ebean;
import io.ebean.EbeanServer;
import org.tests.inheritance.model.CalculationResult;
import org.tests.inheritance.model.Configurations;
import org.tests.inheritance.model.GroupConfiguration;
import org.tests.inheritance.model.ProductConfiguration;
import org.junit.Assert;
import org.junit.Test;
import java.util.List;
public class TestInheritanceJoins extends BaseTestCase {
@Test
public void testAssocOne() {
EbeanServer server = Ebean.getDefaultServer();
ProductConfiguration pc = new ProductConfiguration();
pc.setName("PC1");
server.save(pc);
GroupConfiguration gc = new GroupConfiguration();
gc.setName("GC1");
server.save(gc);
CalculationResult r = new CalculationResult();
r.setCharge(100.0);
r.setProductConfiguration(pc);
r.setGroupConfiguration(gc);
server.save(r);
}
@Test
public void assocOne_when_null() {
EbeanServer server = Ebean.getDefaultServer();
GroupConfiguration gc = new GroupConfiguration();
gc.setName("GC1");
server.save(gc);
CalculationResult r = new CalculationResult();
r.setCharge(100.0);
// @ManyToOne with inheritance and null
r.setProductConfiguration(null);
r.setGroupConfiguration(gc);
server.save(r);
CalculationResult result = server.find(CalculationResult.class, r.getId());
GroupConfiguration group = result.getGroupConfiguration();
Assert.assertEquals(group.getId(), gc.getId());
}
@Test
public void testAssocOneWithNullAssoc() {
/* Ensures the fetch join to a property with inheritance work as a left join */
EbeanServer server = Ebean.getServer(null);
final ProductConfiguration pc = new ProductConfiguration();
pc.setName("PC1");
server.save(pc);
CalculationResult r = new CalculationResult();
final Double charge = 100.0;
r.setCharge(charge);
r.setProductConfiguration(pc);
r.setGroupConfiguration(null);
server.save(r);
}
@Test
public void testAssocMany() {
Configurations configurations = new Configurations();
EbeanServer server = Ebean.getServer(null);
server.save(configurations);
final GroupConfiguration gc = new GroupConfiguration("GC1");
configurations.add(gc);
server.save(gc);
Configurations configurationsQueried = server.find(Configurations.class, configurations.getId());
List<GroupConfiguration> groups = configurationsQueried.getGroupConfigurations();
Assert.assertTrue(!groups.isEmpty());
}
@Test
public void testAssocManyWithNoneRelated() {
Configurations configurations = new Configurations();
EbeanServer server = Ebean.getServer(null);
server.save(configurations);
Configurations configurationsQueried = server.find(Configurations.class).fetch("groupConfigurations").where().idEq(configurations.getId()).findUnique();
Assert.assertNotNull(configurationsQueried);
}
}
@@ -0,0 +1,54 @@
package org.tests.inheritance;
import io.ebean.BaseTestCase;
import io.ebean.Ebean;
import io.ebean.bean.BeanCollection.ModifyListenMode;
import io.ebean.common.BeanList;
import org.tests.model.basic.Animal;
import org.tests.model.basic.AnimalShelter;
import org.tests.model.basic.BigDog;
import org.tests.model.basic.Cat;
import org.tests.model.basic.Dog;
import org.junit.Test;
import java.util.List;
import static org.junit.Assert.assertNotNull;
public class TestInheritanceOnMany extends BaseTestCase {
@Test
public void test() {
Cat cat = new Cat();
cat.setName("Puss");
Ebean.save(cat);
Dog dog = new Dog();
dog.setRegistrationNumber("DOGGIE");
Ebean.save(dog);
BigDog bd = new BigDog();
bd.setDogSize("large");
bd.setRegistrationNumber("BG1");
Ebean.save(bd);
AnimalShelter shelter = new AnimalShelter();
shelter.setName("My Animal Shelter");
shelter.getAnimals().add(cat);
shelter.getAnimals().add(dog);
Ebean.save(shelter);
AnimalShelter shelter2 = Ebean.find(AnimalShelter.class, shelter.getId());
List<Animal> animals = shelter2.getAnimals();
BeanList<?> beanList = (BeanList<?>) animals;
ModifyListenMode modifyListenMode = beanList.getModifyListenMode();
assertNotNull(modifyListenMode);
assertNotNull(Ebean.find(Animal.class).findList());
}
}
@@ -0,0 +1,51 @@
package org.tests.inheritance;
import io.ebean.BaseTestCase;
import io.ebean.Ebean;
import io.ebean.RawSql;
import io.ebean.RawSqlBuilder;
import org.tests.model.basic.Truck;
import org.tests.model.basic.Vehicle;
import org.junit.Assert;
import org.junit.Test;
import java.util.List;
public class TestInheritanceRawSql extends BaseTestCase {
@Test
public void test() {
Truck truck = new Truck();
truck.setCapacity(50D);
truck.setLicenseNumber("ASB23");
Ebean.save(truck);
String sql = "select dtype, id, license_number from vehicle where id = :id";
RawSqlBuilder rawSqlBuilder = RawSqlBuilder.parse(sql);
RawSql rawSql = rawSqlBuilder.create();
List<Vehicle> list = Ebean.find(Vehicle.class)
.setRawSql(rawSql)
.setParameter("id", truck.getId())
.findList();
Assert.assertEquals(1, list.size());
Vehicle vehicle2 = list.get(0);
Assert.assertTrue(vehicle2 instanceof Truck);
Truck truck2 = (Truck) vehicle2;
Assert.assertEquals("ASB23", truck2.getLicenseNumber());
// invoke lazy loading and set the capacity
truck2.setCapacity(30D);
// and now save
Ebean.save(truck2);
}
}
@@ -0,0 +1,47 @@
package org.tests.inheritance;
import io.ebean.BaseTestCase;
import io.ebean.Ebean;
import org.tests.model.basic.TIntChild;
import org.tests.model.basic.TIntRoot;
import org.junit.Assert;
import org.junit.Test;
public class TestIntInherit extends BaseTestCase {
@Test
public void testMe() {
TIntRoot r = new TIntRoot();
r.setName("root1");
TIntRoot r2 = new TIntRoot();
r.setName("root2");
TIntChild c1 = new TIntChild();
c1.setName("child1");
c1.setChildProperty("cp1");
TIntChild c2 = new TIntChild();
c2.setName("child2");
c2.setChildProperty("cp2");
Ebean.save(r);
Ebean.save(r2);
Ebean.save(c1);
Ebean.save(c2);
TIntRoot result1 = Ebean.find(TIntRoot.class, r.getId());
Assert.assertTrue(result1 instanceof TIntRoot);
TIntRoot ref3 = Ebean.getReference(TIntRoot.class, c1.getId());
Assert.assertTrue(ref3 instanceof TIntChild);
TIntRoot result3 = Ebean.find(TIntRoot.class, c1.getId());
Assert.assertTrue(result3 instanceof TIntChild);
}
}
@@ -0,0 +1,23 @@
package org.tests.inheritance;
import io.ebean.BaseTestCase;
import io.ebean.Ebean;
import org.junit.Test;
public class TestNpeOnDiscriminator extends BaseTestCase {
@Test
public void test() {
InnerReport report = Ebean.json().toBean(InnerReport.class, "{}");
Ebean.save(report);
// other service ...
InnerReport.Forecast f = new InnerReport.Forecast();
report.setForecast(f);
f.innerReport = report;
Ebean.save(f);
}
}
@@ -0,0 +1,72 @@
package org.tests.inheritance;
import io.ebean.BaseTestCase;
import io.ebean.Ebean;
import org.tests.model.basic.AttributeHolder;
import org.tests.model.basic.ListAttribute;
import org.tests.model.basic.ListAttributeValue;
import org.junit.Assert;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class TestSkippable extends BaseTestCase {
private static final Logger logger = LoggerFactory.getLogger(TestSkippable.class);
/**
* Test query.
* <p>This test covers the BUG 276. Cascade was not propagating to the ListAttribute because
* it was considered safe to skip as it didn't take into account any derived classes
* into account with e.g. collections and Cascade options </p>
*/
@Test
public void testQuery() {
// Setup the data first
final ListAttributeValue value1 = new ListAttributeValue();
final ListAttributeValue value2 = new ListAttributeValue();
Ebean.save(value1);
Ebean.save(value2);
final ListAttribute listAttribute = new ListAttribute();
listAttribute.add(value1);
Ebean.save(listAttribute);
logger.info(" -- seeded data");
final ListAttribute listAttributeDB = Ebean.find(ListAttribute.class, listAttribute.getId());
Assert.assertNotNull(listAttributeDB);
final ListAttributeValue value1_DB = listAttributeDB.getValues().iterator().next();
Assert.assertTrue(value1.getId().equals(value1_DB.getId()));
logger.info(" -- asserted data in db");
final AttributeHolder holder = new AttributeHolder();
holder.add(listAttributeDB);
Ebean.save(holder);
logger.info(" -- saved holder");
// Now change the M2M listAttribute.values and save the holder
// The save should cascade as follows
// holder.attributes..ListAttribute.values
listAttributeDB.getValues().clear();
listAttributeDB.add(value2);
// Save the holder - should cascade down to the listAtribute and save the values
Ebean.save(holder);
logger.info(" -- M2M detected delete of value1 and add of value2 ?");
final ListAttribute listAttributeDB_2 = Ebean.find(ListAttribute.class, listAttributeDB.getId());
Assert.assertNotNull(listAttributeDB_2);
final ListAttributeValue value2_DB_2 = listAttributeDB_2.getValues().iterator().next();
Assert.assertEquals(value2.getId(), value2_DB_2.getId());
Assert.assertTrue("Cascade failed", value2.getId().equals(value2_DB_2.getId()));
}
}
@@ -0,0 +1,42 @@
package org.tests.inheritance.cache;
import io.ebean.BaseTestCase;
import io.ebean.Ebean;
import org.tests.model.basic.cache.CInhOne;
import org.tests.model.basic.cache.CInhRoot;
import org.junit.Test;
import static org.assertj.core.api.StrictAssertions.assertThat;
public class TestInheritanceCache extends BaseTestCase {
@Test
public void test() {
CInhOne one = new CInhOne();
one.setLicenseNumber("O12");
one.setDriver("Jimmy");
one.setNotes("Hello");
Ebean.save(one);
CInhRoot gotOne = Ebean.find(CInhRoot.class)
.setId(one.getId())
.findUnique();
assertThat(gotOne).isInstanceOf(CInhOne.class);
CInhRoot gotOneFromCache = Ebean.find(CInhRoot.class)
.setId(one.getId())
.findUnique();
assertThat(gotOneFromCache).isInstanceOf(CInhOne.class);
CInhRoot refOne = Ebean.getReference(CInhRoot.class, one.getId());
assertThat(refOne).isInstanceOf(CInhOne.class);
CInhRoot refOneSub = Ebean.getReference(CInhOne.class, one.getId());
assertThat(refOneSub).isNotNull();
}
}
@@ -0,0 +1,61 @@
package org.tests.inheritance.company.domain;
import javax.persistence.DiscriminatorColumn;
import javax.persistence.DiscriminatorType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Version;
/**
* @author Per-Ingemar Andersson, It-huset i Norden AB
*/
@Entity
@Table(name = "bar")
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name = "bar_type", discriminatorType = DiscriminatorType.STRING)
//@MappedSuperclass
public abstract class AbstractBar {
@Id
@GeneratedValue
private int barId;
@ManyToOne(optional = false, fetch = FetchType.LAZY)
@JoinColumn(name = "foo_id", nullable = false)
private Foo foo;
@Version
private int version;
public void setBarId(int barId) {
this.barId = barId;
}
public int getBarId() {
return barId;
}
public Foo getFoo() {
return foo;
}
public void setFoo(Foo foo) {
this.foo = foo;
}
public int getVersion() {
return version;
}
public void setVersion(int version) {
this.version = version;
}
}
@@ -0,0 +1,12 @@
package org.tests.inheritance.company.domain;
import javax.persistence.DiscriminatorValue;
import javax.persistence.Entity;
/**
* @author Per-Ingemar Andersson, It-huset i Norden AB
*/
@Entity
@DiscriminatorValue("ConcreteBar")
public class ConcreteBar extends AbstractBar {
}
@@ -0,0 +1,47 @@
package org.tests.inheritance.company.domain;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Version;
/**
* @author Per-Ingemar Andersson, It-huset i Norden AB
*/
@Entity
@Table(name = "foo")
public class Foo {
@Id
@GeneratedValue
private int fooId;
private String importantText;
@Version
private int version;
public void setFooId(int fooId) {
this.fooId = fooId;
}
public int getFooId() {
return fooId;
}
public String getImportantText() {
return importantText;
}
public void setImportantText(String importantText) {
this.importantText = importantText;
}
public int getVersion() {
return version;
}
public void setVersion(int version) {
this.version = version;
}
}
@@ -0,0 +1,52 @@
package org.tests.inheritance.company.domain;
import io.ebean.Ebean;
import io.ebean.EbeanServer;
import junit.framework.TestCase;
import org.junit.Assert;
import java.util.List;
public class TestInheritAbstract extends TestCase {
public void testMe() {
EbeanServer server = Ebean.getServer(null);
List<AbstractBar> list0 = server.find(AbstractBar.class)
.findList();
Assert.assertNotNull(list0);
List<AbstractBar> list1 = server.find(AbstractBar.class)
.fetch("foo", "importantText")
.findList();
Assert.assertNotNull(list1);
Foo f = new Foo();
f.setImportantText("blah");
server.save(f);
ConcreteBar cb = new ConcreteBar();
cb.setFoo(f);
server.save(cb);
List<AbstractBar> list2 = server.find(AbstractBar.class)
.fetch("foo", "importantText")
.findList();
Assert.assertNotNull(list2);
Assert.assertTrue(!list2.isEmpty());
for (AbstractBar abstractBar : list2) {
Foo foo = abstractBar.getFoo();
String importantText = foo.getImportantText();
Assert.assertNotNull(importantText);
}
}
}
@@ -0,0 +1,16 @@
package org.tests.inheritance.model;
import javax.persistence.MappedSuperclass;
@MappedSuperclass
public class AbstractBaseClass {
private String name;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
@@ -0,0 +1,55 @@
package org.tests.inheritance.model;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
@Entity
public class CalculationResult {
@Id
@Column(name = "id")
private Integer id;
private double charge;
@ManyToOne(cascade = CascadeType.PERSIST)
private ProductConfiguration productConfiguration;
@ManyToOne(cascade = CascadeType.PERSIST)
private GroupConfiguration groupConfiguration;
public double getCharge() {
return charge;
}
public void setCharge(double charge) {
this.charge = charge;
}
public ProductConfiguration getProductConfiguration() {
return productConfiguration;
}
public void setProductConfiguration(ProductConfiguration productConfiguration) {
this.productConfiguration = productConfiguration;
}
public GroupConfiguration getGroupConfiguration() {
return groupConfiguration;
}
public void setGroupConfiguration(GroupConfiguration groupConfiguration) {
this.groupConfiguration = groupConfiguration;
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
}
@@ -0,0 +1,47 @@
package org.tests.inheritance.model;
import io.ebean.annotation.ChangeLog;
import javax.persistence.Column;
import javax.persistence.DiscriminatorColumn;
import javax.persistence.DiscriminatorType;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.ManyToOne;
@ChangeLog
@Entity
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name = "type", discriminatorType = DiscriminatorType.STRING)
public class Configuration extends AbstractBaseClass {
@Id
@Column(name = "id")
private Integer id;
@ManyToOne
private Configurations configurations;
public Configuration() {
super();
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public Configurations getConfigurations() {
return configurations;
}
public void setConfigurations(Configurations configurations) {
this.configurations = configurations;
}
}
@@ -0,0 +1,51 @@
package org.tests.inheritance.model;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import java.util.List;
@Entity
public class Configurations {
@Id
@Column(name = "id")
private Integer id;
private String name;
@OneToMany
private List<GroupConfiguration> groupConfigurations;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public List<GroupConfiguration> getGroupConfigurations() {
return groupConfigurations;
}
public void setGroupConfigurations(List<GroupConfiguration> groupConfigurations) {
this.groupConfigurations = groupConfigurations;
}
public void add(GroupConfiguration groupConfiguration) {
groupConfiguration.setConfigurations(this);
groupConfigurations.add(groupConfiguration);
}
}
@@ -0,0 +1,40 @@
package org.tests.inheritance.model;
import javax.persistence.DiscriminatorValue;
import javax.persistence.Entity;
import javax.persistence.OneToMany;
import java.util.List;
@Entity
@DiscriminatorValue("2")
public class GroupConfiguration extends Configuration {
private String groupName;
@OneToMany(mappedBy = "groupConfiguration")
private List<CalculationResult> results;
public GroupConfiguration() {
super();
}
public GroupConfiguration(String name) {
super();
this.groupName = name;
}
public String getGroupName() {
return groupName;
}
public void setGroupName(String groupName) {
this.groupName = groupName;
}
public List<CalculationResult> getResults() {
return results;
}
public void setResults(List<CalculationResult> results) {
this.results = results;
}
}
@@ -0,0 +1,35 @@
package org.tests.inheritance.model;
import javax.persistence.DiscriminatorValue;
import javax.persistence.Entity;
import javax.persistence.OneToMany;
import java.util.List;
@Entity
@DiscriminatorValue("1")
public class ProductConfiguration extends Configuration {
private String productName;
@OneToMany(mappedBy = "productConfiguration")
private List<CalculationResult> results;
public ProductConfiguration() {
super();
}
public String getProductName() {
return productName;
}
public void setProductName(String productName) {
this.productName = productName;
}
public List<CalculationResult> getResults() {
return results;
}
public void setResults(List<CalculationResult> results) {
this.results = results;
}
}