How to specify one-way mapping in Dozer using annotations - dozer

How to specify one-way mapping in Dozer using annotation?
I can do that using XML Mapping as follows:
<field type="one-way">
<a>oneFoo2</a>
<b>oneFooPrime2</b>
</field>
However I don't see mention of this in annotation documentation.

This is not possible with the current (5.5.1) version. As described in the documentation, there is only one annotation, #Mapping which tells the destination field to map.

Related

mybatis - how to get rid of mapping file and just use annotations

I was looking at this wonderful mybatis example
http://mybatis.co.uk/index.php/2010/09/mybatis-simple-and-complete-example.html
that uses mostly annotations but was hoping for an #MyBatisDao annotation so I don't need to ever go back to some mapping file and add a line for each dao that I add to the system. I obviously will just use mapping for now but was just curious if there was a way???
You can use the package element to let it scan for your mappers (since 3.1)
MyBatis 3.1 Reference Guide

Dozer mapping description to code

I am using Dozer to map my JAXB objects that come off a WebService interface to my domain objects. One of the elements or properties in my JAXB is a String set/setLocation(). This would be the description of the location. What I need in the backend is the to take that String and map it to a code which will be stored in my database. I've looked in the Dozer website and junit tests and I don't see anything that I can use as an example. I was hoping I could create some custom setter mapper to do this but I am looking for an example that I can start with. Any help would be appreciated.
With a little investigation I found a way to resolve my problem with a field level converter.
Here is the Dozer documentation for those interested: http://dozer.sourceforge.net/documentation/customconverter.html

How to set ReturnType of FunctionImport to object that defined in other edmx file?

I have FunctionImport in one edmx1 file and I want to set the ReturnType to object that is located in other edmx2 file.
for example, I have edmx1 file with following FunctionImport and t_Page object defined in edmx1 file
edmx1
<FunctionImport Name="CopySite" EntitySet="t_Page" ReturnType="Collection(Entities.t_Page)">
<Parameter Name="assemblyId" Mode="In" Type="Int32" />
<Parameter Name="projectId" Mode="In" Type="Int32" />
</FunctionImport>
Now, I want to change the ReturnType, so it will return c_Page(declared in edxm2) instead of t_Page. If I just change t_Page to c_Page in edmx1 I get error that c_Page is not defined in edmx
<FunctionImport Name="CopySite" EntitySet="c_Page" ReturnType="Collection(Entities.c_Page)">
<Parameter Name="assemblyId" Mode="In" Type="Int32" />
<Parameter Name="projectId" Mode="In" Type="Int32" />
</FunctionImport>
How I can do this?
UPDATED
The reason why I need this is:
I have several DBs with different tables except 5 of them that has same scheme but different names in each DB(e.g. c_Page,d_Page,e_Page...). It has to be with different names! Now, when I create edmx for each DB I don't want to have hundreds of "same" classes, because they all have the same scheme but different names, so I want map the same class to all those tables
Maybe I need Entity Framework 4 “Code-First”? But in this way I need to create classes manually, right?
Can you suggest me how I can do this?
This is normally not possible. You can use only types defined within same EDMX file.
The only situation when this can be possible is described in this article where you are able to include one CSDL file into another. This would allow you defining entity in one CSDL file and include that CSDL file to second EDMX where you will be able to define FunctionImport and hopefully also used that entity (I didn't tested it). But it has some consequences:
Only CSDL files can be divided this way
You still need single shared MSL and SSDL file for both CSDL files
You cannot use EDMX (container for these files) any more
You cannot use designer and related automated tools and wizards
Edit:
So based on your edit you must have entities defined in every EDMX - there is no way how to avoid that. If you ensure that entities will be exactly same in every EDMX (including: names, keys, property names, relations) you can modify your T4 templates used to generate classes so that only one template generate them. After that you would need to ensure that ObjectContext derived classes generated by templates use correct classes in their exposed sets. It is all about some modifications in T4 templates.

Ignoring some elements/classes in JAXB binding

I use Hyperjaxb to generate some classes with JPA annotations from XML schemas. I'd like to specify which elements from given schema xjc should generate. I can't change xsd file. I can modify only bindings.xjb. I tried to use hj:ignored, but without success.
Well, hj:ignored is the answer. It allows you to make Hyperjaxb ignore certain classes.
Here's an example:
<jaxb:bindings
node="xsd:complexType[#name='issue121Type']//xsd:element[#name='simpleCollection']">
<hj:ignored/>
</jaxb:bindings>
Customizations work in schema as well as via xjb files.
See this project for instance.
How does "without success" reveal itself?

How to define javax.validation.constraints.Size.List in my binding file using jaxb annotate and annox plugins?

I want to use JSR 303 Bean validation on my classes. My problem is that these classes are generated from schema. I am using the jaxb annotate plugin on my bindings file and was able to define simple validation annotations like #NotNull. My problem comes when I have to define multiple annotations of same type for different groups. javax.validation offers a solution for this using annotations like #Size.List{#Size...). How can I use jaxb-annotate and annox plugin to define annotations like those.
You can define nested annotations with Annox, it's no problem. In your case it will be something like:
In *.xjb file:
<annox:annotate>
<annox:annotate annox:class="javax.validation.constraints.Size$List">
<annox:annotate annox:field="value">
<annox:annotate annox:class="javax.validation.constraints.Size" .../>
</annox:annotate>
</annox:annotate>
</annox:annotate>
In schema:
<annox:annotate>
<c:Size$List xmlns:c="http://annox.dev.java.net/javax.validation.constraints">
<c:value>
<c:Size ... />
</c:value>
</c:Size$List>
</annox:annotate>
I haven't tested it, so the syntax may be a bit different.
See the Annox user guide an the Annotate plugin docs.