gpt4 book ai didi

mysql - Spring : (MVC) java heap space -> lazy loading not working

转载 作者:行者123 更新时间:2023-11-29 14:25:34 25 4
gpt4 key购买 nike

(首先..对不起我的英语..)

所以我一直在致力于一个spring roo项目..我正在从一个大约有 30 个表的 mysql 数据库进行逆向工程。问题是它向我抛出“java.lang.OutOfMemoryError:Java堆空间”错误因为延迟加载不起作用,正如我在调试日志记录中看到的那样

表中的行数并不多。我的意思是我的表中没有一个表的行数超过 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)

我尝试通过将默认惰性设置为 true 来更改我的持久性文件 - ..但是..什么也没有:(

看起来无论我做什么, hibernate 都不会更改为延迟加载所以我想知道我必须在哪里设置延迟加载,或者我错过了什么..

谁能帮我..?

这是我的 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

这些是我的类(class):公开课区{

@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 不要加载不必要的表

最佳答案

我也有问题。我有 1 个表仅使用 MySQL。数据包含 500k 行。

使用 Spring Roo,按照教程运行所有脚本来设置逆向工程和所有内容。当服务器运行时。转到localhost:8080,它运行正常。但是点击List All,java堆空间!

关于mysql - Spring : (MVC) java heap space -> lazy loading not working,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11039101/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com