(首先..对不起我的英语..)
所以我一直在做一个spring roo项目。我正在从一个有30个表的mysql数据库做逆向工程。问题是它抛出了“java.lang.OutOfMemoryError: Java heap space”错误 ,因为延迟加载不起作用,正如我在调试日志中看到的那样
我什至在表格中没有很多行.. 我的意思是我的表格中没有一个超过 15 行..
我已经尝试添加
@OneToMany(mappedBy = "unidadId", fetch = FetchType.LAZY)
private Set<Area> areas;
@Fetch(FetchMode.SELECT)
public Set<com.springroo.gqr.dominio.Area> getAreas() {
return areas;
}
@ManyToOne (fetch = FetchType.LAZY) //which does exactly the oposite: EAGER :S and it makes it even slooooooower..
@JoinColumn(name = "unidad_id", referencedColumnName = "id", nullable = false)
private Unidad unidadId;
所以我把它改成
@ManyToOne (optional=false)
@JoinColumn(name = "unidad_id", referencedColumnName = "id", nullable = false)
private Unidad unidadId;
我也试过
@LazyCollection(LazyCollectionOption.EXTRA)
和
@LazyCollection(LazyCollectionOption.TRUE)
我试图通过将 default-lazy 设置为 true 来更改我的持久性文件 - .. 但是.. 什么都没有 :(
看起来无论我做什么,休眠都不会更改为延迟加载,所以我想知道我必须在哪里设置延迟加载,或者我错过了什么..
有谁能够帮我..?
这是我的 ROO 脚本
project --topLevelPackage com.springroo.GQR
jpa setup --provider HIBERNATE --database MYSQL --databaseName bd_gqr --userName root --password ******
database reverse engineer --schema bd_gqr --package ~.dominio
web mvc setup
web flow
web mvc all --package ~.web
web mvc language --code es
security setup
perform tests
perform eclipse
这些是我的课:公共课区{
@ManyToOne(optional = false)
@JoinColumn(name = "unidad_id", referencedColumnName = "id", nullable = false)
private Unidad unidadId;
@OneToMany(mappedBy = "areaId", fetch = FetchType.LAZY)
@Fetch(FetchMode.SELECT)
private Set<Empleado> empleadoes;
@OneToMany(mappedBy = "areaId", fetch = FetchType.LAZY)
@Fetch(FetchMode.SELECT)
private Set<Queja> quejas;
@Column(name = "nombre", length = 45, unique = true)
@NotNull
private String nombre;
public String getNombre() {
return nombre;
}
public void setNombre(String nombre) {
this.nombre = nombre;
}
public Unidad AgetUnidadId() {
return unidadId;
}
public void setUnidadId(Unidad unidadId) {
this.unidadId = unidadId;
}
public Set<com.springroo.gqr.dominio.Empleado> getEmpleadoes() {
return empleadoes;
}
public void setEmpleadoes(Set<com.springroo.gqr.dominio.Empleado> empleadoes) {
this.empleadoes = empleadoes;
}
public Set<com.springroo.gqr.dominio.Queja> getQuejas() {
return quejas;
}
public void setQuejas(Set<com.springroo.gqr.dominio.Queja> quejas) {
this.quejas = quejas;
}
}
public class Unidad {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "id")
private Integer id;
public Integer getId() {
return this.id;
}
public void setId(Integer id) {
this.id = id;
}
@OneToMany(mappedBy = "unidadId", fetch = FetchType.LAZY)
private Set<Area> areas;
@Fetch(FetchMode.SELECT)
public Set<com.springroo.gqr.dominio.Area> getAreas() {
return areas;
}
public void setAreas(Set<com.springroo.gqr.dominio.Area> areas) {
this.areas = areas;
}
}
这些是我的表定义:
<table name="area">
<column name="id" primaryKey="true" required="true" scale="0" size="10" type="4,INT"/>
<column name="unidad_id" primaryKey="false" required="true" scale="0" size="10" type="4,INT"/>
<column name="nombre" primaryKey="false" required="true" scale="0" size="45" type="12,VARCHAR"/>
<foreign-key foreignTable="unidad" name="fk_area_unidad1" onDelete="cascade" onUpdate="cascade">
<option key="exported" value="false"/>
<reference foreign="id" local="unidad_id"/>
</foreign-key>
<foreign-key foreignTable="empleado" name="fk_empleado_area1" onDelete="cascade" onUpdate="cascade">
<option key="exported" value="true"/>
<reference foreign="area_id" local="id"/>
</foreign-key>
<foreign-key foreignTable="queja" name="fk_quejas_areas1" onDelete="cascade" onUpdate="cascade">
<option key="exported" value="true"/>
<reference foreign="area_id" local="id"/>
</foreign-key>
<unique name="PRIMARY">
<unique-column name="id"/>
</unique>
<unique name="nombre_UNIQUE">
<unique-column name="nombre"/>
</unique>
<index name="fk_area_unidad1">
<index-column name="unidad_id"/>
</index>
</table>
<table name="unidad">
<column name="id" primaryKey="true" required="true" scale="0" size="10" type="4,INT"/>
<column name="clues" primaryKey="false" required="true" scale="0" size="25" type="12,VARCHAR"/>
<column name="nombre" primaryKey="false" required="true" scale="0" size="100" type="12,VARCHAR"/>
<foreign-key foreignTable="area" name="fk_area_unidad1" onDelete="cascade" onUpdate="cascade">
<option key="exported" value="true"/>
<reference foreign="unidad_id" local="id"/>
</foreign-key>
<unique name="PRIMARY">
<unique-column name="id"/>
</unique>
<unique name="nombre_UNIQUE">
<unique-column name="nombre"/>
</unique>
<unique name="clues_UNIQUE">
<unique-column name="clues"/>
</unique>
</table>
调试日志的一部分:
Hibernate: select quejas0_.area_id as area3_4_2_, quejas0_.id as id2_, quejas0_.id as id18_1_, quejas0_.area_id as area3_18_1_, quejas0_.folio as folio18_1_, quejas0_.medio_id as medio4_18_1_, quejas0_.tramite_id as tramite5_18_1_, medioqueja1_.id as id13_0_, medioqueja1_.medio as medio13_0_ from queja quejas0_ inner join medio_queja medioqueja1_ on quejas0_.medio_id=medioqueja1_.id where quejas0_.area_id=?
所以问题是......在哪里以及如何告诉 roo/hibernate 不要加载不必要的表