(1st of all.. sorry for my english..)
so I have been working on a spring roo project.. i'm doing reverse engineer from a mysql db with like 30 tables. the problem is that it throws me the "java.lang.OutOfMemoryError: Java heap space" error because lazy loading is not working, as I can see on the debug logging
I don't even have many rows in the tables.. I mean none of my tables have more than 15 rows..
I've already tried adding
@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;
so I changed it to
@ManyToOne (optional=false)
@JoinColumn(name = "unidad_id", referencedColumnName = "id", nullable = false)
private Unidad unidadId;
I've also tried
@LazyCollection(LazyCollectionOption.EXTRA)
And
@LazyCollection(LazyCollectionOption.TRUE)
I've tried to change my persistence file by setting true the default-lazy - .. but.. nothing :(
It looks like whatever I do, hibernate does not change to lazy load so I'm wondering where do i have to set the lazy loading, or what am I missing..
can anybody help me..?
THIS IS MY ROO SCRIPT
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
these are my classes: public class Area {
@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;
}
}
these are my table definitions:
<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>
Part of debug logging:
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=?
so the thing is.. where and how tell roo/hibernate not to load unnecessary tables