私はBasicTransformerAdapterを拡張するカスタム結果トランスフォーマを作成しました。 transformTupleメソッドでは、エンティティの新しいオブジェクトを作成します。Hibernate ResultTransformerとgwt requestfactory
@Override
public Object transformTuple(Object[] tuple, String[] aliases) {
RegistryRow row = new RegistryRow();
DataRow dataRow = new DataRow();
Registry registry = new Registry();
for (int i = 0; i < aliases.length; i++) {
if ("id".equals(aliases[i])) {
row.setId((Long) tuple[i]);
} else if ("entityVersion".equals(aliases[i])) {
row.setEntityVersion((Long) tuple[i]);
} else if ("gridRowId".equals(aliases[i])) {
dataRow.setId((Long) tuple[i]);
} else if ("rowEntityVersion".equals(aliases[i])) {
dataRow.setEntityVersion((Long) tuple[i]);
} else if (tuple[i] != null && aliases[i] != null && aliases[i].startsWith("set")) {
try {
DataType type = DataRow.getDataType(tuple[i].getClass());
Method m = DataRow.class.getMethod(aliases[i], type.getDataClass());
m.invoke(dataRow, DataRow.castValue(tuple[i], type));
} catch (Exception e) {
LOG.error("--Error while setting dataRow data: ", e);
}
} else if ("registryCode".equals(aliases[i])) {
registry.setCode((String) tuple[i]);
} else if ("registryEntityVersion".equals(aliases[i])) {
registry.setEntityVersion((Long) tuple[i]);
}
}
row.setRegistry(registry);
row.setGridRow(dataRow);
return row;
}
すべて動作します。 RegistryRowオブジェクトのリストが作成されます。 は、クライアント側でRegistryRowProxyは、次のようになりますこれがあります:
@ProxyFor(value = RegistryRow.class, locator = LongEntityLocator.class)
public interface RegistryRowProxy extends EntityProxy, BeanModelTag {
Long getId();
DataRowProxy getGridRow();
Date getCreateDate();
RegistryProxy getRegistry();
Long getDataId();
}
これは、リストのサービスを呼び出すGWT RequestFactoryに使用されています。
getRequestFactory().registryRow().list(registry.getCode(), paramsId).with("gridRow").fire(receiver);
これはデータを返しますが、すべて問題ありませんが、show_sqlをオンにするとデータベースに追加の選択が行われます。クエリは次のようになります。
select "all_columns" from RegistryRow where id = ?;
select "all_columns" from DataRow where id = ?;
これらのクエリは、リストに行がある回数だけ実行されます。私はperfomanceに影響を与えるこれらの追加クエリをどのように取り除くかを知らない。なぜデータベースに追加のクエリがあるのか知っていますか? (私はエンティティにこのようになります変数があることを追加します。
@JoinColumn(name = "T_DATA_ROWS_ID")
@NotNull
private DataRow gridRow;
ではなく、それらのすべてが)
アップデート1: 注釈は正確に次のようになります。
@OneToOne(fetch = FetchType.EAGER, cascade = CascadeType.ALL)
@JoinColumn(name = "T_DATA_ROWS_ID")
@NotNull
private DataRow gridRow;
をとそれでも各行に対してクエリを実行しています。
:
私はあなたの問題は、あなたの
DataRow dataGrid
財産上の@OneToOne
注釈が欠落していることであると仮定= '@OneToOne(フェッチFetchType.EAGER、カスケード= CascadeType.ALL ) @JoinColumn(name = "T_DATA_ROWS_ID") @NotNullプライベートDataRow gridRow; ' – Caroline