Nested object mapping

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

Nested object mapping

Максим Касьянов
Hi,

I have annotation base myBatis configuration.
How i can map nested object with annotaion?
Thank you in advance.

For instance:

class Example{


 
public String field1;
 
public NestedObject nestedObect;
 
}


class NestedObject{


 
public String field2;
 
}


class ExampleMapper{


 
@Select("select 'field1' as field1, 'field2' as nestedObjectField")
 
Example map();


}

--
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: Nested object mapping

Guy Rouillier-2
Try nestedObject.field2.

--
Guy Rouillier

------ Original Message ------
From: "Максим Касьянов" <[hidden email]>
To: "mybatis-user" <[hidden email]>
Sent: 1/18/2019 12:40:40 PM
Subject: Nested object mapping

Hi,

I have annotation base myBatis configuration.
How i can map nested object with annotaion?
Thank you in advance.

For instance:

class Example{


 
public String field1;
 
public NestedObject nestedObect;
 
}


class NestedObject{


 
public String field2;
 
}


class ExampleMapper{


 
@Select("select 'field1' as field1, 'field2' as nestedObjectField")
 
Example map();


}

--
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: Nested object mapping

David
In reply to this post by Максим Касьянов
I suppose that in your data model the entities Example and NestedObject have a relation of one to one, the solution that I recommend is:

@Select("select field1 from ExampleEntity")
@Results(id = "selectMap", value = {
@Result(property = "field1", column = "FIELD1", jdbcType = JdbcType.VARCHAR),
        @Result(property = "nestedObject", javaType=NestedObject.class, column = "ID_NESTEDOBJECT", one=@One(select="getNestedObjectById"))
})
Example map();

@Select("select field2 from NestedObjectEntity where ID_NESTEDOBJECT=#{id}")
@Results(id = "nestedObjectMap", value = {
@Result(property = "field2", column = "FIELD2", jdbcType = JdbcType.VARCHAR)
})
NestedObject getNestedObjectById(@Param("id") Long id);


El viernes, 18 de enero de 2019, 14:40:40 (UTC-3), Максим Касьянов escribió:
Hi,

I have annotation base myBatis configuration.
How i can map nested object with annotaion?
Thank you in advance.

For instance:

class Example{


 
public String field1;
 
public NestedObject nestedObect;
 
}


class NestedObject{


 
public String field2;
 
}


class ExampleMapper{


 
@Select("select 'field1' as field1, 'field2' as nestedObjectField")
 
Example map();


}

--
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].
To view this discussion on the web visit https://groups.google.com/d/msgid/mybatis-user/f1ab9f4c-eb31-4989-ad49-0617f19b2da9%40googlegroups.com.