i have a question,one order have many crafts, one of the crafts need two or many people to finish,so in the planning entity i usee a list object for planning variables,but when i start the application,it have a error,please give me some idea,thanks!
#PlanningSolution
public class ScheduleSolution extends AbstractPersistable {
#ProblemFactCollectionProperty
private List<Order> orderList;
#ProblemFactCollectionProperty
private List<ProductBom> productBomList;
#PlanningEntityCollectionProperty
private List<JobAssignment> jobAssignmentList;
#ProblemFactCollectionProperty
#ValueRangeProvider(id = "resourceRange")
List<Resource> resourceList;
#PlanningScore
private HardSoftScore score;
}
#PlanningEntity
public class JobAssignment extends AbstractPersistable {
private ProductBom productBom;
#PlanningVariable(valueRangeProviderRefs = { "resourceRange" })
private List<Resource> resourceList;
}
Caused by: java.lang.IllegalArgumentException: The entityClass (class com.demo.domain.reassign.JobAssignment) has a PlanningVariable annotated property (resourceList) that refers to a ValueRangeProvider annotated member (field java.util.List com.demo.domain.reassign.ScheduleSolution.resourceList) that returns a Collection with elements of type (class com.demo.domain.reassign.Resource) which cannot be assigned to the PlanningVariable's type (interface java.util.List). at org.optaplanner.core.impl.domain.valuerange.descriptor.AbstractFromPropertyValueRangeDescriptor.processValueRangeProviderAnnotation(AbstractFromPropertyValueRangeDescriptor.java:136)
A #PlanningVariable cannot be a List, not until we support #PlanningVariableCollection some day. Possible fix:
#PlanningEntity
public class JobAssignment extends AbstractPersistable {
private ProductBom productBom;
#PlanningVariable(valueRangeProviderRefs = { "resourceRange" })
private Resource resource;
}
Related
I am using spring boot (2.0.0) with eclipse link to persist data (over 500 entity classes) to a postgres db (6.5). Thats works very well. For receiving the data over REST I build an other spring boot application. Here I have some inheriance problem with JPA (sorry for my drawing):
Class C and class D (abstract) inherit from class B. Class A have a reference (attribute1) to class B. This attribute is an instance of entity class E, which inherit from abstract class D. I am using inheritance strategy table per class. Every class using the annotation Entity with the table name. In the database, table from class A have a correct foreign key to table from class E, but if I want to read the data the attribute1 is null. I see from the log level that eclipse link only look inside table from class C. How can I resolve this problem?
Greets Benjamin
here are the classes, class E:
#Entity(name="ep_core_voltagelevel")
public class VoltageLevel extends EquipmentContainer {
#Embedded
#AttributeOverrides(#AttributeOverride(name="value", column=#Column(name="highVoltageLimit_value")
)
)
private myPackage.DomainProfile.Voltage highVoltageLimit;
public myPackage.DomainProfile.Voltage getHighVoltageLimit() {
return highVoltageLimit;
}
public void setHighVoltageLimit(myPackage.DomainProfile.Voltage parameter) {
this.highVoltageLimit = parameter;
}
#Embedded
#AttributeOverrides(#AttributeOverride(name="value", column=#Column(name="lowVoltageLimit_value")
)
)
private myPackage.DomainProfile.Voltage lowVoltageLimit;
public myPackage.DomainProfile.Voltage getLowVoltageLimit() {
return lowVoltageLimit;
}
public void setLowVoltageLimit(myPackage.DomainProfile.Voltage parameter) {
this.lowVoltageLimit = parameter;
}
#ManyToOne(cascade={CascadeType.MERGE, CascadeType.PERSIST, CascadeType.REFRESH})
#JoinColumn(nullable=false, name="basevoltage_id")
private BaseVoltage baseVoltage;
public BaseVoltage getBaseVoltage() {
return baseVoltage;
}
public void setBaseVoltage(BaseVoltage parameter) {
this.baseVoltage = parameter;
}
#ManyToOne(cascade={CascadeType.MERGE, CascadeType.PERSIST, CascadeType.REFRESH})
#JoinColumn(nullable=false, name="substation_id")
private Substation substation;
public Substation getSubstation() {
return substation;
}
public void setSubstation(Substation parameter) {
this.substation = parameter;
}
}
Class D:
#Entity(name = "ep_core_equipmentcontainer")
public abstract class EquipmentContainer extends ConnectivityNodeContainer {
}
Class B:
#Entity(name="ep_core_connectivitynodecontainer")
public abstract class ConnectivityNodeContainer extends PowerSystemResource {
}
Class A:
public class ConnectivityNode extends IdentifiedObject {
#ManyToOne(cascade={CascadeType.MERGE, CascadeType.PERSIST, CascadeType.REFRESH})
#JoinColumn(nullable=false, name="connectivitynodecontainer_id")
private ConnectivityNodeContainer connectivityNodeContainer;
public ConnectivityNodeContainer getConnectivityNodeContainer() {
return connectivityNodeContainer;
}
public void setConnectivityNodeContainer(ConnectivityNodeContainer parameter) {
this.connectivityNodeContainer = parameter;
}
}
Given some simple classes and interfaces...
public interface IClass1 { }; public class Class1 : IClass1 { }
public interface IClass2 { }; public class Class2 : IClass2 { }
... this injectable code ...
public class Class3
{
public Class3(IClass1 class1, IClass2 class2)
{
}
public Class3(IClass1 class1)
{
}
}
... and this setup ...
static void Main(string[] args)
{
var kernel = new StandardKernel();
kernel.Bind<IClass1>().To<Class1>();
var instance = kernel.Get<IClass1>();
}
Ninject will crash declaring that it can't find a binding for IClass2.
On the one had this is understandable, because it doesn't have a binding for IClass2.
However it does have access to a constructor which does not require such a binding.
After some investigation, we have discovered that both of these constructors have the same 'score' because they both have the same number of resolvable parameters.
Ninject appears to treat them as equally valid. It picks the constructor which requires an IClass2 parameter because it is listed first within the code.
So if I reverse the order of these constructors thus...
public class Class3
{
public Class3(IClass1 class1)
{
}
public Class3(IClass1 class1, IClass2 class2)
{
}
}
... everything works.
My question is therefore....
Why is the constructor (the one requiring an IClass2 parameter) ever considered a valid contender when it has unresolvable parameters?
I tried to find an answer to this question in the Orika documentation but no luck.
I have the following classes:
public class A {
private String partNumber1;
private String partNumber2;
...
}
public class B {
private Integer shelfNumber;
private A a;
...
}
public class BDTO {
private Integer selfNumber;
private ADTO someA;
...
}
public class ADTO {
private String partNumber;
...
}
.. and the following CustomMapper's to map Objects of B to objects BDO
#Component
public class BMapper extends CustomMapper<B, BDTO> {
#Override
public void mapAtoB(B b, BDTO bdto, MappingContext context) {
super.mapAtoB(b, bdto, context);
//??? what to do here ???
}
}
#Component
public class AMapper extends CustomMapper<A, ADTO> {
#Override
public void mapAtoB(A a, ADTO adto, MappingContext context) {
super.mapAtoB(a, adto, context);
adto.setPartNumber(a.getPartNumber1() + a.getPartNumber2());
}
}
In my client code I have:
B b = new B(5, new A("100392", "100342"));
BDTO bdto = mapper.map(b, BDTO.class);
My question is, in BMapper, what is the correct way to get the AMapper to map "a" to "someA"? To put it differently, what is the correct way to map a to someA in BMapper? I suspect that it can be done through some interface in the MappingContext object.
I found an answer after some experimentation. To map property objects in the main objects mapper, i.e. the scenario explained above, one can use the protected "mapperFacade" member of CustomMapper.
So you can do something like this:
bdto.setSomeA(super.mapperFacade.map(b.getA(), ADTO.class));
My project is in the form:
Class Persistant :
#Entity
public class Produit implements Serializable {
private static final long serialVersionUID = -3352484919001942398L;
#Id
#GeneratedValue
private Long id;
private String module;
private String produit;
//getter&&setter
Class Dao
public List<Entry<Integer, List<Produit>>> parProduit(String cat) {
.......
HashMap<Integer, List<Produit>> legaux = new HashMap<Integer, List<Produit>>();
........
List<Map.Entry<Integer, List<Produit>>> entries = new ArrayList<Entry<Integer, List<Produit>>>(legaux.entrySet());
return entries;
}
when i execute this code i get this error :
java.io.NotSerializableException: java.util.HashMap$Node
java.util.HashMap.EntrySet<K, V>
is not serializable.
legaux.entrySet()
probably returns set of type java.util.HashMap.EntrySet, you may want to check that.
I have a JPA persistence layer with many #Entity classes which have many OneToMany and ManyToMany relationships.
I want to expose that entities by RestEasy with Jackson2 as serializer to JSON as REST services.
I know about #JsonIdentityInfo for resolving circular references.
The problem is in different REST services I need to expose different subsets of Entity fields. Moreover I need to expose different levels of depts for collections (OneToMany, OneToOne etc).
For example for this simple Entities:
class User {
Long id;
String name;
Company company;
}
class Company {
Long id;
String name;
List<User> users;
List<Product> products;
}
class Product {
Long id;
String name;
List<User> users;
}
and this REST service:
class MyResource {
User getUser() { //... }
List<User> getUsers() { //... }
Company getCompany() { //... }
List<Company> getComanies() { //... }
}
In method getUser() I need to return JSON with full User object including inner Company object. But that company of course only need to include their id and name field and not full list of users. Even more important that inner Company JSON must not include products! It is logical. If we get the user we don't need products of company that related to this user. If we need them we will send another REST request.
But in method getCompany() I need to return JSON with full Company object including inner JSON arrays of User and Product objects. Of course this time that User objects doesn't need to include inner JSON for Company object.
For this reason I can't use #JsonIgnore. In one case we need some field and in another we doesn't.
Now I came up with approach of using Jackson views (#JsonView annotation). I have View class with different views for every MyResource getter.
public class Views {
public static class User {}
public static class Users {}
public static class Company {}
public static class Companies {}
// etc...
}
and MyResoruce class as
class MyResource {
#JsonView(Views.User.class)
User getUser() { //... }
#JsonView(Views.Users.class)
List<User> getUsers() { //... }
#JsonView(Views.Company.class)
Company getCompany() { //... }
#JsonView(Views.Companies.class)
List<Company> getComanies() { //... }
}
and have a MixIn classes for every Entity with every field annotated as
public abstract class UserMixIn {
#JsonView({ Views.User.class, Views.Users.class, Views.Company.class, Views.Companies.class })
public abstract Long getId();
#JsonView({ Views.User.class, Views.Users.class, Views.Company.class, Views.Companies.class })
public abstract String getName();
#JsonView({ Views.User.class, Views.Users.class })
public abstract Company getCompany();
}
public abstract class CompanyMixIn {
#JsonView({ Views.Company.class, Views.Companies.class, Views.User.class, Views.Users.class })
public abstract Long getId();
#JsonView({ Views.Company.class, Views.Companies.class, Views.User.class, Views.Users.class })
public abstract String getName();
#JsonView({ Views.Company.class, Views.Companies.class })
public abstract List<User> getUsers();
#JsonView({ Views.Company.class, Views.Companies.class })
public abstract List<Product> getProducts();
}
public abstract class ProductMixIn {
#JsonView({ Views.Company.class, Views.Companies.class })
public abstract Long getId();
#JsonView({ Views.Company.class, Views.Companies.class })
public abstract String getName();
public abstract List<User> getUsers();
}
Plurals for support cases where getUsers() doesn't need full inner Company object for every user (performance).
Of course there are just example classes. Real classes are much bigger and complex.
I do not like this approach because I am afraid that in the future it can be a nightmare (too many not manageable views). Maybe there are common approach for exposing JPA Entities as REST services? I believe it is a fairly common task. But can not find any intelligible information on how others doing this. Maybe some best practices.
Your service layer (and your REST controller layer) must expose DTOs (Data transfer objects) instead of #Entity objects.
Example :
For a Service 1 (which focus on User managment) :
public class UserDto {
private Long id;
private String name;
private CompanyDtoLight company;
}
public class CompanyDtoLight {
private Long id;
private String name;
}
For a Service 2 (which focus on Company managment) :
public class CompanyDto {
private Long id;
private String name;
List<UserDtoLight > users;
List<ProductDtoLight > products;
}
public class UserDtoLight {
private Long id;
private String name;
}
class ProductDtoLight {
private Long id;
private String name;
}
(The naming of your DTOs is yours)
How to :
You will need Mappers to transfom and reverse your #Entity to DTOs. Some lib exist like Dozer or MapStruct (there are plenty of other).