Ignore property?

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Ignore property?

Björn Raupach
Hi group,

is it possible to ignore a column and not map it? Currently I end up with a Cause: org.apache.ibatis.reflection.ReflectionException: There is no setter for property named 'id' in 'class com.acme.Example'.

The class com.acme.Example uses a ResultMap for mapping:

<resultMap id="Example" type="Example">
        <id property="id" column="Id" />
        <result property="name" column="Name" />
       ...
</resultMap>

And the corressponding Example.java looks like this:

public class Example {

   private String name;
   ...
   // getter and setter below
}

So MyBatis complains that there is no id property. Which is correct because I left it out in the pojo but not in the SELECT statement. If I leave it in the SELECT, then MyBatis does not map every row correctly. So it is definitely needed while mapping but not needed in the POJO.

Rationale: The Example.java gets passed to some other layers and they should not see the Id. It is just some business logic requirement. I could help myself creating a second Example.java class and copy value by value to that one and ignoring the id property, or map to java.util.Map instead of the actual type. Just trying to avoid copying property by property by hand. I looking for something like autoMappingUnknownColumnBehavior but just the other way around.

Any ideas?

kind regards
Björn

--
You received this message because you are subscribed to the Google Groups "mybatis-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Ignore property?

Iwao AVE!
Hi Björn,

Have you tried omitting 'property' from <id /> ?

<id column="Id" />

Regards,
Iwao


2018-02-26 23:19 GMT+09:00 'Björn Raupach' via mybatis-user <[hidden email]>:
Hi group,

is it possible to ignore a column and not map it? Currently I end up with a Cause: org.apache.ibatis.reflection.ReflectionException: There is no setter for property named 'id' in 'class com.acme.Example'.

The class com.acme.Example uses a ResultMap for mapping:

<resultMap id="Example" type="Example">
        <id property="id" column="Id" />
        <result property="name" column="Name" />
       ...
</resultMap>

And the corressponding Example.java looks like this:

public class Example {

   private String name;
   ...
   // getter and setter below
}

So MyBatis complains that there is no id property. Which is correct because I left it out in the pojo but not in the SELECT statement. If I leave it in the SELECT, then MyBatis does not map every row correctly. So it is definitely needed while mapping but not needed in the POJO.

Rationale: The Example.java gets passed to some other layers and they should not see the Id. It is just some business logic requirement. I could help myself creating a second Example.java class and copy value by value to that one and ignoring the id property, or map to java.util.Map instead of the actual type. Just trying to avoid copying property by property by hand. I looking for something like autoMappingUnknownColumnBehavior but just the other way around.

Any ideas?

kind regards
Björn

--
You received this message because you are subscribed to the Google Groups "mybatis-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "mybatis-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Ignore property?

Björn Raupach
Hi Iwao,

that does the trick! Perfect! Thanks for the quick response. :)

have a good one!
Björn

On 26. Feb 2018, at 15:59, Iwao AVE! <[hidden email]> wrote:

Hi Björn,

Have you tried omitting 'property' from <id /> ?

<id column="Id" />

Regards,
Iwao


2018-02-26 23:19 GMT+09:00 'Björn Raupach' via mybatis-user <[hidden email]>:
Hi group,

is it possible to ignore a column and not map it? Currently I end up with a Cause: org.apache.ibatis.reflection.ReflectionException: There is no setter for property named 'id' in 'class com.acme.Example'.

The class com.acme.Example uses a ResultMap for mapping:

<resultMap id="Example" type="Example">
        <id property="id" column="Id" />
        <result property="name" column="Name" />
       ...
</resultMap>

And the corressponding Example.java looks like this:

public class Example {

   private String name;
   ...
   // getter and setter below
}

So MyBatis complains that there is no id property. Which is correct because I left it out in the pojo but not in the SELECT statement. If I leave it in the SELECT, then MyBatis does not map every row correctly. So it is definitely needed while mapping but not needed in the POJO.

Rationale: The Example.java gets passed to some other layers and they should not see the Id. It is just some business logic requirement. I could help myself creating a second Example.java class and copy value by value to that one and ignoring the id property, or map to java.util.Map instead of the actual type. Just trying to avoid copying property by property by hand. I looking for something like autoMappingUnknownColumnBehavior but just the other way around.

Any ideas?

kind regards
Björn

--
You received this message because you are subscribed to the Google Groups "mybatis-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.


--
You received this message because you are subscribed to the Google Groups "mybatis-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "mybatis-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.