Comments below:
On Wed, Sep 19, 2012 at 12:05 PM, Lukas Eder <[email protected]> wrote:
> Adam,
>
> > I got many to one to sort of work using JPA annotations (@ManyToOne +
> > @JoinColumn) and the ResultSetMetaData to figure out how to transform the
> > child object from the ResultSet.
>
>
I'm not using jOOQ for this but my own Spring RowMapper that uses column
labels (ResultSetMetaData.getColumnLabel) to generate a nested
Map<String,Object>.
I would put the code up but its a mess and it will take me some time to
remove some of the nastiness.
Basically I do a bunch of reflection on the top level object I want to load
and determine which properties are complex (ie ManyToOne).
Then I construct SQL SELECT (automatically although you generate it
manually following a dotted notation naming scheme ):
-- SQL notice "parent.test.stringProp" is bean like notation
SELECT id,
parent0.id AS "parent.id",
parent0_test1.string_prop AS "parent.test.stringProp",
parent0_test1.long_prop AS "parent.test.longProp",
parent0_test1.timets AS "parent.test.timeTS"
FROM grand_parent_bean
INNER JOIN parent_bean parent0 ON parent0.id = parent
INNER JOIN test_bean parent0_test1 ON parent0_test1.string_prop =
parent0.test
WHERE id = ? LIMIT ? OFFSET ?
// JAVA POJOs
public class GrandParentBean {
@Id
private final String id;
@ManyToOne(targetEntity=ParentBean.class)
private final ParentBean parent;
@JsonCreator
public GrandParentBean(
@JsonProperty("id") String id,
@JsonProperty("parent") ParentBean parent) {
super();
this.id = id;
this.parent = parent;
}
public String getId() {
return id;
}
public ParentBean getParent() {
return parent;
}
}
public class ParentBean {
@Id
private final String id;
@ManyToOne(targetEntity=TestBean.class)
private final TestBean test;
@JsonCreator
public ParentBean(
@JsonProperty("id") String id,
@JsonProperty("test") TestBean test) {
super();
this.id = id;
this.test = test;
}
public String getId() {
return id;
}
public TestBean getTest() {
return test;
}
}
public class TestBean {
@Id
private final String stringProp;
private final long longProp;
@Column(name="timets")
@NotNull
private final Calendar timeTS;
@JsonCreator
public TestBean(
@JsonProperty("stringProp") String stringProp,
@JsonProperty("longProp") long longProp,
@JsonProperty("timeTS") Calendar timeTS ) {
super();
this.stringProp = stringProp;
this.longProp = longProp;
this.timeTS = timeTS;
}
public String getStringProp() {
return stringProp;
}
public long getLongProp() {
return longProp;
}
public Calendar getTimeTS() {
return timeTS;
}
}
> Care to share / contribute this?
>
> > One to many and many to many will be a PITA and in my mind defeats the
> goals
> > of jOOQ.
>
> Yes, there are a lot of corner cases with some of those.
>
--
CTO
Evocatus, Inc. (evocatus.com)
(twitter) @agentgt (cell) 781-883-5182