0

(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

trincot
  • 317,000
  • 35
  • 244
  • 286
aLee
  • 11
  • 3

3 Answers3

1

I have a problem also. I have 1 table only using MySQL. Data contain 500k rows.

Using Spring Roo, run all script follow tutorial to setup reverse engineering and everything. when server running. go to localhost:8080, it run OK. But click List All, java heap space!

Echilon
  • 10,064
  • 33
  • 131
  • 217
0

Can you share the Roo script and the definition of the tables Unidad and Area?

Apologize, but I didn't have enough time to take a look, but watching the code I see that you're using a Hibernate annotation: Fetch with FetchMode.SELECT. What for?

In general it's not a good idea to depend on the engine. Besides, maybe it's creating some undesireable behaviour.

At first sight, the JPA annotation Fetch.LAZY seems enough for your objective.

jbbarquero
  • 2,842
  • 2
  • 19
  • 17
  • thank you for replying! the select thing was because of this(I know its useless but I was trying of everything..): _Fetch type (lazy/eager) refers to when Hibernate will fetch the association, whether in advance when it fetches the entity(eager), or whether it waits for the code to ask for the association(lazy). Fetch mode(select/join) refers to how Hibernate will fetch the association, i.e. does it use an extra SELECT statement, or does it use a join. Some combinations of these make no sense, e.g. lazy+join. If you use lazy fetching, then SELECT fetch mode is the only one that you can do._ – aLee Jun 18 '12 at 13:42
  • I mean its useless because it is supposed that hibernate uses lazy select fetching by default, so I souldn't even use those anottations.. I really don't know why its doing that.. what else could I do..? – aLee Jun 18 '12 at 13:50
0
import javax.persistence.FetchType
@ManyToOne (fetch = FetchType.LAZY)

I'm not sure why this did not work for you, I've just used it and it did make it lazy loading. Where you modifying the generated .aj file, because if so, Roo will regenerate it on its next scan; if so you need to push it into the .java file.

melutovich
  • 372
  • 1
  • 3
  • 15
  • it is on the java file, but it never worked :( always the java heap space error.. – aLee Jan 11 '13 at 17:19
  • I assume only on the java file (you might want to check). When it is being used is the heap space error in the debugging log still because of the lazy loading? – melutovich Jan 12 '13 at 17:14