I'm using mapstruct for mapping my entities.
All my entities have a date field.
Is there a way to define a date formatter on the level of the mapper, instead of adding a mapping for each field?
Currently this is not possible. However, one can achieve what you are looking for by implementing a custom mapping methods within your mappers. In there you can use your own pattern.
Related
Is there a way in hibernate-search 6 to project multiple fields and map them directly to a POJO object or I should handle it by myself. I'm not sure that I understand the composite method described in the documentation. For example I can do something like that:
SearchResult<List<?>> result = searchSession.search(indicies)
.select(f -> f.composite(f.field("field1"), f.field("field2"), f.field("field3"),f.field("field4")))
.where(SearchPredicateFactory::matchAll)
.fetch(20)
And then I can manually map the returned List of fields to a POJO. But is there a more fancy way to do that without the need to manually loop through the list of fields and set them to the POJO instance?
At the moment projecting to a POJO is only possible for fairly simple POJOs, with up to three fields, using the syntax shown in the documentation. For more fields than that, you have to go through a List.
If you're using the Elasticsearch backend, you can theoretically retrieve the document as a JsonObject and then use Gson to map it to a POJO.
There are plans to offer more fancy solutions, but we're not there yet.
I am using MapStruct to provide bean mapping between different systems, and I have reached a point where the only way to map a specific property is to add it as a Map entry to the target object with the field name as key.
I can do this using a very long expression where I set the entire map using guava ImmutableMap builder, but is there a more elegant and safe way of providing this mapping? Setter method would expect two parameters in this case.
This is currently not support in MapStruct. There is already an open feature request #1075 for support like this.
Is there a way to create the equivalent behavior provided by EclipseLink’s AdditionalCriteria annotation in JPA? That is, can we create additional filtering that is added to every query for a particular entity type? We can use EclipseLink, but we don’t want to be dependent on it.
I was wondering how can I define my own datatypes within a metamodel created using EMF Ecore ?
The goal is to have a class that may contain many attribute. Each attribute has one Datatype.
The problem I am facing now is when I want to set the attribute datatype [in a model which is conforme to my metamodel ] in the Property View (Eclipse EMF), I get an empty list.
I want something similar to when adding an EAttribute , you get the choice between different Etype (EString, EBoolean,...).
I appreciate any help.
Thank you.
You can add EDataType instances on the same level as EClasses, and they can refer to any kind of Java object. However, be careful that only very simple serialization is available for these objects.
Say I want to populate a JPA entity using values supplied by a user through a web application form (Tapestry for that matter).
What is the best way to obtain the "blank" instance of the JPA entity that is going to be bound to the form fields?
As of now I just use the new operator as follows in my Tapestry class:
childminderAccount = new ChildminderAccount();
Is this not a somewhat a crude way of doing it? Is there a better way?
Nope, that's the best way to do it. One of the advantages of JPA (over old EJB Persistence) is that it is a "lighter" framework. One of it's lightnesses is the fact that it now works woth POJOs (or Java Beans). I would recommend however to take a look at Java's new validation API which is very lightweight as well, and it can insure that a JPA Bean is correctly populated from your form (like no non-nullable fields set to null, empty id field etc):
http://www.hibernate.org/subprojects/validator.html