Hallo
I can't get Lazy loading function on my Informix server. Why is it that the Test take AF_LEVRANCE in the SQL, I really don't need the data, just the name of product 84.
The enviorement:
Code:
Weblogic Server 10.3.0
JPA
Hibernate 3.5.6-Final
IBM Informix Dynamic Server Version 11.50
SunOS 5.10 Generic_147440-05 sun4v sparc sun4v (Oracle Solaris 10 9/10 s10s_u9wos_14a SPARC)
Main table:
Code:
DBSCHEMA Schema Utility INFORMIX-SQL Version 7.25.UC7
Copyright (C) Informix Software, Inc., 1984-1997 Software Serial Number AAC#J583710 { TABLE "stl".af_produkt row size = 63 number of columns = 11 index size = 12 } create table "stl".af_produkt
(
af_produkt_id serial not null ,
af_prod_rekkefolge integer not null ,
af_produktnummer char(5) not null ,
af_prod_mmx1 char(2),
af_prod_mmx2 char(2),
af_prod_besk char(25),
af_blanding char(1),
af_foreldet char(1),
af_endret_dato date not null ,
af_endret_af char(10) not null ,
af_synonym char(5),
primary key (af_produkt_id) constraint "stl".dnn4tb0d1u132_24
);
Sub Tabel
Code:
DBSCHEMA Schema Utility INFORMIX-SQL Version 7.25.UC7
Copyright (C) Informix Software, Inc., 1984-1997 Software Serial Number AAC#J583710 { TABLE "stl".af_leverance row size = 74 number of columns = 15 index size = 72 } create table "stl".af_leverance
(
af_leverance_id serial not null constraint "informix".dnn4tb0d1n138_174,
af_ordrenr char(10),
af_stationsnr char(10) not null constraint "informix".dnn4tb0d1n138_175,
af_produktnummer char(5) not null constraint "informix".dnn4tb0d1n138_176,
af_levdato date not null constraint "informix".dnn4tb0d1n138_177,
af_leveret_vol integer not null constraint "informix".dnn4tb0d1n138_178,
af_grundbelob decimal(11,2),
af_momsbelob decimal(11,2),
af_pejletal integer not null constraint "informix".dnn4tb0d1n138_179,
af_pejletid char(4) not null constraint "informix".dnn4tb0d1n138_180,
af_system char(2) not null constraint "informix".dnn4tb0d1n138_181,
af_opret_dato date not null constraint "informix".dnn4tb0d1n138_182,
af_produkt_id integer,
af_afregning_id integer,
af_brugt char(1),
primary key (af_leverance_id) constraint "stl".dnn4tb0d1u125_17
);
.....
JPA for AFREGNING
Code:
.....
@Entity
@Table(name="AF_PRODUKT")
public class AfProdukt implements Serializable{
....
...
@OneToMany(mappedBy="afProdukt", cascade=CascadeType.ALL, fetch=FetchType.LAZY)
public Collection<AfLeverance> getAfLeverancer() {
return afLeverancer;
}
...
...
JPA for AF_LEVERANCE
Code:
....
...
@Entity
@Table(name="AF_LEVERANCE")
public class AfLeverance implements Serializable{
...
...
@ManyToOne(cascade=CascadeType.ALL, fetch=FetchType.LAZY)
@JoinColumn(name="AF_PRODUKT_ID")
public AfProdukt getAfProdukt() {
return afProdukt;
}
...
...
TestCase : AFRENING_TEST
Code:
....
....
public class AfregningTestCase {
//public static final Logger log = Logger.getLogger(AfregningTestCase.class);
EntityManager emAfregning;
@Before public void setUp(){
emAfregning = Persistence.createEntityManagerFactory("afregning_test").createEntityManager();
}
@Test public void testHentProdukt()
{
return;
Query query = emAfregning.createNamedQuery("AfProdukt.hentProdukt");
query.setParameter("produkt", "84");
List rs = query.setMaxResults(2).getResultList();
System.out.println(" "+rs);
System.out.println("test");
}
...
...
TestCase output
Code:
log4j:WARN No appenders could be found for logger (org.hibernate.cfg.annotations.Version).
log4j:WARN Please initialize the log4j system properly.
Hibernate:
select
first 1 afprodukt0_.af_produkt_id as af1_1_,
afprodukt0_.af_blanding as af2_1_,
afprodukt0_.af_endret_af as af3_1_,
afprodukt0_.af_endret_dato as af4_1_,
afprodukt0_.af_foreldet as af5_1_,
afprodukt0_.af_prod_besk as af6_1_,
afprodukt0_.af_prod_mmx1 as af7_1_,
afprodukt0_.af_prod_mmx2 as af8_1_,
afprodukt0_.af_prod_rekkefolge as af9_1_,
afprodukt0_.af_produktnummer as af10_1_,
afprodukt0_.af_synonym as af11_1_
from
AF_PRODUKT afprodukt0_
where
afprodukt0_.af_prod_mmx1=?
Hibernate:
select
afleveranc0_.AF_PRODUKT_ID as AF15_1_,
afleveranc0_.AF_LEVERANCE_ID as AF1_1_,
afleveranc0_.AF_LEVERANCE_ID as AF1_0_0_,
afleveranc0_.AF_AFREGNING_ID as AF2_0_0_,
afleveranc0_.AF_BRUGT as AF3_0_0_,
afleveranc0_.AF_GRUNDBELOB as AF4_0_0_,
afleveranc0_.AF_LEVDATO as AF5_0_0_,
afleveranc0_.AF_LEVERET_VOL as AF6_0_0_,
afleveranc0_.AF_MOMSBELOB as AF7_0_0_,
afleveranc0_.AF_OPRET_DATO as AF8_0_0_,
afleveranc0_.AF_ORDRENR as AF9_0_0_,
afleveranc0_.AF_PEJLETAL as AF10_0_0_,
afleveranc0_.AF_PEJLETID as AF11_0_0_,
afleveranc0_.AF_PRODUKT_ID as AF15_0_0_,
afleveranc0_.AF_PRODUKTNUMMER as AF12_0_0_,
afleveranc0_.AF_STATIONSNR as AF13_0_0_,
afleveranc0_.AF_SYSTEM as AF14_0_0_
from
AF_LEVERANCE afleveranc0_
where
afleveranc0_.AF_PRODUKT_ID=?
Exception trace
Code:
java.lang.StackOverflowError
at dk.q8.core.model.afregning.AfLeverance.toString(AfLeverance.java:199)
at java.lang.String.valueOf(String.java:2827)
at java.lang.StringBuilder.append(StringBuilder.java:115)
at java.util.AbstractCollection.toString(AbstractCollection.java:422)
at org.hibernate.collection.PersistentBag.toString(PersistentBag.java:507)
at java.lang.String.valueOf(String.java:2827)
at java.lang.StringBuilder.append(StringBuilder.java:115)
at dk.q8.core.model.afregning.AfProdukt.toString(AfProdukt.java:179)
at java.lang.String.valueOf(String.java:2827)
at java.lang.StringBuilder.append(StringBuilder.java:115)
at dk.q8.core.model.afregning.AfLeverance.toString(AfLeverance.java:199)
at java.lang.String.valueOf(String.java:2827)
at java.lang.StringBuilder.append(StringBuilder.java:115)
at java.util.AbstractCollection.toString(AbstractCollection.java:422)
at org.hibernate.collection.PersistentBag.toString(PersistentBag.java:507)
at java.lang.String.valueOf(String.java:2827)
...
at dk.q8.core.model.afregning.AfLeverance.toString(AfLeverance.java:199)
at java.lang.String.valueOf(String.java:2827)
at java.lang.StringBuilder.append(StringBuilder.java:115)
at java.util.AbstractCollection.toString(AbstractCollection.java:422)
Regards
/C