Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Automatic mapping of immutable POJOs using the constructor
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  9 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
IvanL  
View profile  
 More options Sep 27 2012, 8:51 am
From: IvanL <larionov.i...@gmail.com>
Date: Thu, 27 Sep 2012 05:51:45 -0700 (PDT)
Local: Thurs, Sep 27 2012 8:51 am
Subject: Automatic mapping of immutable POJOs using the constructor

Hi guys,

I really like the idea of convention over configuration and MyBatis has
been helpful in this so far. It can automatically map result sets to beans
with little if any mapping info. Anw I would like to know whether it is
possible (can be implemented) to work with immutable POJOs with minimum of
mapping info as well. For instance:

<select id="getMenu" resultType="com.test.ChapterItem">
select id, name, rank from chapter
</select>

public class ChapterItem {
private int id;
private String name;
private int rank;
 public ChapterItem(int id, String name, int rank) {
super();
this.id = id;
this.name = name;
this.rank = rank;

}

// .....

}

It could rely on the result set's columns order and the order of parameters
in the constructor to make an instance.
I would be grateful if somebody shed some light on this. I could try to
make a patch for MyBatis if somebody highlighted the places to look at in
the code.
Thanks

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
IvanL  
View profile  
 More options Sep 27 2012, 9:02 am
From: IvanL <larionov.i...@gmail.com>
Date: Thu, 27 Sep 2012 06:02:00 -0700 (PDT)
Subject: Re: Automatic mapping of immutable POJOs using the constructor

I meant fields to be final. Sorry.

public class ChapterItem {
private *final *int id;
private *final *String name;
private *final *int rank;
 public ChapterItem(int id, String name, int rank) {
super();
this.id = id;
this.name = name;
this.rank = rank;

}

// .....


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Dridi Boukelmoune  
View profile  
 More options Sep 27 2012, 9:39 am
From: Dridi Boukelmoune <dridi.boukelmo...@zenika.com>
Date: Thu, 27 Sep 2012 15:39:28 +0200
Local: Thurs, Sep 27 2012 9:39 am
Subject: Re: Automatic mapping of immutable POJOs using the constructor
Hi Ivan,

I hope JDBC guarantees the columns order because I love your idea :)

Dridi

--
Dridi Boukelmoune
Développeur/Formateur

GSM : +33 (0)6 17 91 14 23


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Paul Krause  
View profile  
 More options Sep 28 2012, 8:03 pm
From: Paul Krause <paulkraus...@alum.mit.edu>
Date: Fri, 28 Sep 2012 17:03:36 -0700 (PDT)
Local: Fri, Sep 28 2012 8:03 pm
Subject: Re: Automatic mapping of immutable POJOs using the constructor

http://www.mybatis.org/core/sqlmap-xml.html#constructor


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Dridi Boukelmoune  
View profile  
 More options Oct 1 2012, 4:40 am
From: Dridi Boukelmoune <dridi.boukelmo...@zenika.com>
Date: Mon, 1 Oct 2012 10:38:48 +0200
Local: Mon, Oct 1 2012 4:38 am
Subject: Re: Automatic mapping of immutable POJOs using the constructor
Hi,

I think Ivan suggested implicit constructor mapping with types, just
like MB would automatically map field names to column names.

Dridi

--
Dridi Boukelmoune
Développeur/Formateur

GSM : +33 (0)6 17 91 14 23


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Tim  
View profile  
 More options Oct 1 2012, 12:01 pm
From: Tim <che...@gmail.com>
Date: Mon, 1 Oct 2012 11:00:32 -0500
Local: Mon, Oct 1 2012 12:00 pm
Subject: Re: Automatic mapping of immutable POJOs using the constructor

I don't like the idea of relying on column ordering. It's a very loose way
to define column mappings.
Constructor mapping is a very clean and easy way to manage this. It's also
powerful enough to be used for immutable complex objects as well.

For example:

FruitBowl {
private final Apple apple;
private final Banana banana;

etc...

On Mon, Oct 1, 2012 at 3:38 AM, Dridi Boukelmoune <


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Jens  
View profile  
 More options Oct 1 2012, 12:34 pm
From: Jens <jens.nehlme...@gmail.com>
Date: Mon, 1 Oct 2012 09:34:56 -0700 (PDT)
Local: Mon, Oct 1 2012 12:34 pm
Subject: Re: Automatic mapping of immutable POJOs using the constructor

> I don't like the idea of relying on column ordering. It's a very loose way
> to define column mappings.
> Constructor mapping is a very clean and easy way to manage this.

With constructor mapping you also depend on ordering:

In order to inject the results into the constructor, MyBatis needs to
identify the constructor by the type of its parameters. Java has no way to
introspect (or reflect) on parameter names. So when creating a constructor
element, ensure that the arguments are in order, and that the data types
are specified.

So it does not make much of a difference if you define the mapping in xml
or let it be defined via convention based on the ResultSet metadata column
information. In both cases you depend on ordering just because Java does
not give you enough information.

+1 for convention, if possible.

-- J.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Dridi Boukelmoune  
View profile  
 More options Oct 1 2012, 1:14 pm
From: Dridi Boukelmoune <dridi.boukelmo...@zenika.com>
Date: Mon, 1 Oct 2012 19:13:18 +0200
Local: Mon, Oct 1 2012 1:13 pm
Subject: Re: Automatic mapping of immutable POJOs using the constructor
It looks rather possible !

http://docs.oracle.com/javase/1.4.2/docs/api/java/sql/ResultSetMetaDa...
(I know this is old documentation, but it's the first result I got =)

getColumnCount()
getColumnType(int column)

Dridi

--
Dridi Boukelmoune
Développeur/Formateur

GSM : +33 (0)6 17 91 14 23


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
IvanL  
View profile   Translate to Translated (View Original)
 More options Oct 3 2012, 1:40 am
From: IvanL <larionov.i...@gmail.com>
Date: Tue, 2 Oct 2012 22:40:53 -0700 (PDT)
Local: Wed, Oct 3 2012 1:40 am
Subject: Re: Automatic mapping of immutable POJOs using the constructor

Hi guys,

With reference to our discussion, would anybody mind if I filed a feature
request regarding this?

четверг, 27 сентября 2012 г., 15:51:45 UTC+3 пользователь IvanL написал:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »