Want to map attribute of an object from a List to an Object - mapstruct

While traversing through ACROD, there is a list and want to map the first object from that list to my domain object.
#Mapping(source="insuranceSvcRqs[0].policyQuoteInqRqsAddRqsAndPolicyQuoteInqRqs[0].producers[0].generalPartyInfo.nameInfos[0].commlName.commercialName",
target = "producer.commercialName")
I tried this one but it did not work. All blogs that I have searched has LIST to LIST mapping. Mine is LIST.first() to Domain Object mapping.

Checkout this example. It explains how to map a collection to an object and what element to take (first, last) based on a qualifier.

Related

JPA Criteria API checking if entity collection contains certain elements or one of them

I am wondering how to create predicate which will filter entities which collection property contains elements from collection given as parameter using JPA specification.
In this example I am building query for UserEntity to return users which belong to groups contained in parameter List.
List<String> groups = query.getGroups();
predicates.add(cb.isTrue(r.get("groups").in(groups)));
But if I understand it correctly it will return true if all or less groups are in this list.
I am looking for solution where a) all elements from list are in entity collection b) at least one (or like way)
Is there some easy way to achieve this? In fact I don't really need anything from GroupEntity so I don't think joining is necessary
Thanks for help

Realm Swift inverse relationships many-to-many

I'm currently trying to work out the best way to architect my realm objects for ease of retrieval.
I have 2 objects tags and object there are multiple tags and each one might contain many object. Similarly each object could have multiple tag associated with it
Ideally selecting a single tag should retrieve all object that have at least that one tag (but could obviously have multiple)
would my models be specified as
class Tag: Object {
let objects = List<Object>()
}
class Object {
let tags = List<Tag>()
}
I don't think I need to use an inverse relationship here or should I? Choosing a Category I should be able to just retrieve a list of all object references regardless, but then maintaining and updating the references to an object might be difficult here? I.e a user selects tag 'A' then updates the first object to also include tag 'B' I would need to update the object in the List for Tag A, then add a new item to the list for Tag 'B' and finally update the actual Object itself to include Tag 'B' in it's list of tags.
Just to be clear an Object will only ever display and allow editing of it's Tag objects. But the Tag object itself will need to know what Object's are applicable to it.
However it feels like I will have to do multiple updates when ideally I'd like to minimise this effort. Can anyone recommend a better way to do this? Or is there no way around this due to the limitations of Realm?
This is exactly what LinkingObjects is for. Changing the objects property in Tag to let objects = LinkingObjects(fromType: Object.self, property: "tags") will make it automatically update whenever a tag is added to an object.

MongoDB storing and querying child objects

I've two different object with same father. I want to store them in the same collection, but I want to be able to retrieve each object separately.
for example if these are my objects:
I want to retrieve all of FirstChild objects without retrieving any SecondChild Object.
Is there any way other than adding a type field to the father object, to retrieve them?
Assuming first child and second child are different types stored in different fields of the father object (father is a composition of first and second child)
datastore.find(FatherObject.class).retrievedFields(false,"secondChildField")
will get everything except secondChildField or
datastore.find(FatherObject.class).retrievedFields(true,"firstChildField")
will bring only firstChildField.
When you create your query, pass in the class reference of the type you want: datastore.createQuery(SecondChild.class). Morphia, by default, tracks the class type of the document so it can filter by that type.

entity framework wrong order of child object after some child objects detached

my problem is after first child object detached and then i add another child object to my parentObj the order of attached child is not correct
, my code look like this:
parentObj= new TparentObj();
firstChildObj=new Tchild1();
secondChildObj= new Tchild1();
thirdChildObj=new Tchild1();
parentObj.Tchild1.add(firstChildObj);
parentObj.Tchild1.add(secondChildObj);
// now parentObj.Tchild1.first()==firstChildObj return true
///then for some reason
parentObj.Tchild1.remove(firstChildObj);
db.Entry(firstChildObj).State = EntityState.Detached;
// now i add third childObj
parentObj.Tchild1.add(thirdChildObj);
//// now parentObj.Tchild1.first()==thirdChildObj return true!!
after saved db the result in database is Correct;
but how can i get list of childObj in order they added?
Entity Framework by default uses HashSets for its collections. HashSet doesn't take ordering into account.
You shouldn't rely on the ordering of elements for it. The current implementation seems (as you are experiencing) to add the element on the first unused position (in your case, the removed one), but this is an implementation detail and you shouldn't rely on it.
About HashSet, the MSDN says about it (bold is mine):
The HashSet class provides high-performance set operations. A set is a collection that contains no duplicate elements, and whose elements are in no particular order.
and
A HashSet collection is not sorted and cannot contain duplicate elements. If order or element duplication is more important than performance for your application, consider using the List class together with the Sort method.

Grouping list of objects based on variable attributes of object in java

I need to do group by on list of objects based multiple attributes in the object.
like lets say there is a student object
with attributes name,number,state,city,marks
now i need to do group by on it based on multiple keys,
like
it cab be state,city or state or name,state,city or marks,count(*)
Please let me know the best option to do it.
the possible options i have are.
1) using of Nested maps
2) using multimap with composite key
3) using ArrayTable.
Seems like just do a list per criteria. Otherwise I might create an Enum that implements Predicate and create a Multimap with the enum as the key.