【发布时间】:2014-06-29 19:50:28
【问题描述】:
这是几个问题,Spring Roo 应该通过逆向工程为 .aj 文件中的 Set 字段添加 FetchType.LAZY 还是我应该手动执行?
如果 .aj 文件中不存在 FetchType.LAZY,我可以通过查询“SELECT st1 FROM parentTable t1 JOIN FETCH t1.childTable st1”进入选择,对吧?
这里的重点是我可以手动将 FetchType.LAZY 添加到文件中(重构 .aj 文件 > Push In..),然后添加到 .java 文件中(如果我希望 Roo 保持对我的域类的控制,则风险很高)。
关于通过查询,我不能这样做,因为我得到:
> query specified join fetching, but the owner of the fetched association was not present in the select list [FromElement{explicit,not a collection join,fetch join,fetch non-lazy properties,classAlias=ii,role=...domain.Industry.i18nIndustries,
tableName=..I18nIndustry,
tableAlias=i18nindust3_,
origin=..Industry industry2_,
columns={industry2_.IdIndustry ,className=..domain.I18nIndustry}}]
[select u.idUserName, u.isActiveInd, u.employeeNbr, u.name, c.name as CompanyName, ii.name as IndustryName from Users u JOIN u.idCompany c JOIN c.idIndustry i JOIN FETCH i.i18nIndustries ii WHERE u.idUserName = :username ]
这里是 Roo 生成的 .aj 文件:
privileged aspect Users_Roo_DbManaged {
...
@ManyToOne
@JoinColumn(name = "IdCompany", referencedColumnName = "IdCompany", nullable = false)
private Company Users.idCompany; ...
..
privileged aspect Company_Roo_DbManaged {
...
@ManyToOne
@JoinColumn(name = "IdCity", referencedColumnName = "IdCity", nullable = false)
private City Company.idCity;
@ManyToOne
@JoinColumn(name = "IdIndustry", referencedColumnName = "IdIndustry", nullable = false)
private Industry Company.idIndustry; ..
..
privileged aspect Industry_Roo_DbManaged { ..
@OneToMany(mappedBy = "idIndustry")
private Set<I18nIndustry> Industry.i18nIndustries; ...
你能告诉我这里发生了什么吗?
Spring MVC 3.2, Roo 1.2.4, MSSql 数据库
谢谢各位! --JR
【问题讨论】:
-
确认,这是你的HQL在执行
[select u.idUserName, u.isActiveInd, u.employeeNbr, u.name, c.name as CompanyName, ii.name as IndustryName from Users u JOIN u.idCompany c JOIN c.idIndustry i JOIN FETCH i.i18nIndustries ii WHERE u.idUserName = :username ]吗?
标签: spring hibernate hibernate-mapping spring-roo