-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 
Author Message
 Post subject: ManyToOne lazy inizialization
PostPosted: Sat Mar 03, 2012 10:03 am 
Newbie

Joined: Sat Mar 03, 2012 9:54 am
Posts: 3
Greetings,
i've some trouble with ManyToOne assocation who is eagerly initialized rather than lazily initialized.


my mapping is

Code:
<class name="com.xxx.Model.impl.RisultatiQuestionarioImpl" entity-name="RisultatiQuestionario" abstract="false" lazy="true" discriminator-value="RisultatiQuestionario" table="`risultatiquestionario`" proxy="com.ViewShape.Model.Base.RisultatiQuestionario">
      <id name="Id" type="long" unsaved-value="0">
         <column not-null="true" unique="false" name="`id`"/>
         <generator class="native"/>
      </id>
      <discriminator type="string">
         <column name="dtype" index="risultatiquestionariodtype" length="255" not-null="true"/>
      </discriminator>
      <version name="e_version" type="int">
         <column not-null="true" unique="false" name="`e_version`"/>
      </version>
      <many-to-one name="Risposte" entity-name="OutputRisposte" lazy="proxy" cascade="all" foreign-key="risultatiquestionario_risposte" insert="true" update="true" not-null="true" unique="true">
         <column not-null="true" unique="false" name="`outputrisposte_risposte_e_id`"/>
      </many-to-one>
.
.
.



   <class name="com.xxx.Model.impl.OutputRisposteImpl" entity-name="OutputRisposte" abstract="false" lazy="true" discriminator-value="OutputRisposte" table="`outputrisposte`" proxy="com.ViewShape.Model.Base.OutputRisposte">



as far i know with such setup when i load a RisultatoQuestionario object, Risposte assocation should be loaded only when i try to access it. unfortunately such assocation is eagerly loaded.

An extract of hibernate log generated from a simple query like "from RisultatiQuestionario rs"

Code:
84352 [main] DEBUG org.hibernate.loader.Loader  - result row: EntityKey[RisultatiQuestionario#25379]
84355 [main] DEBUG org.hibernate.loader.Loader  - result row: EntityKey[RisultatiQuestionario#27625]
84363 [main] DEBUG org.hibernate.engine.TwoPhaseLoad  - resolving associations for [RisultatiQuestionario#14214]
84371 [main] DEBUG org.hibernate.impl.SessionImpl  - initializing proxy: [OutputRisposte#14215]
84371 [main] DEBUG org.hibernate.loader.Loader  - loading entity: [OutputRisposte#14215]



i really have no clue what's wrong, since the mapping seems okay. ty in advance.


Top
 Profile  
 
 Post subject: Re: ManyToOne lazy inizialization
PostPosted: Mon Mar 05, 2012 3:15 am 
Expert
Expert

Joined: Tue Jun 16, 2009 3:36 am
Posts: 990
Can you please also post the generated schema of tables risultatiquestionario and outputrisposte please?


Top
 Profile  
 
 Post subject: Re: ManyToOne lazy inizialization
PostPosted: Mon Mar 05, 2012 6:15 am 
Newbie

Joined: Sat Mar 03, 2012 9:54 am
Posts: 3
thank you for your answer. i'm attaching the db schema (currently hosted on postgres)

In the table you'll find more foreignkeys like outputrisposte, and have same mapping.

thank you for your help.

Code:
CREATE TABLE risultatiquestionario
(
  id bigint NOT NULL,
  dtype character varying(255) NOT NULL,
  e_version integer NOT NULL,
  outputrisposte_risposte_e_id bigint NOT NULL,
  outputsintesidistribuzione_sintesidistrubuzione_e_id bigint NOT NULL,
  outputhistog_histog_e_id bigint NOT NULL,
  out_percentili_percentili_e_id bigint NOT NULL,
  out_probabilitascen_probabilitascenario_e_id bigint NOT NULL,
  out_scenarioprob_scenarioprob_e_id bigint NOT NULL,
  identity bigint,
  data_questionario timestamp without time zone,
  orainizioquestionario timestamp without time zone,
  orafinequestionario timestamp without time zone,
  note character varying(255),
  out_siar_siar_e_id bigint NOT NULL,
  outputpromemoria_promemoria_e_id bigint NOT NULL,
  attivitasupervisione_attivitasupervisione_e_id bigint NOT NULL,
  flgeseguito_primavolta boolean,
  flgrieseguito_nuoveviews boolean,
  flgrieseguito_nonconvalidato boolean,
  flg_salvatirisultatiparziali boolean,
  flg_convalida_supervisioni boolean,
  risultatiquestionario_variabileutente_id bigint,
  CONSTRAINT risultatiquestionario_pkey PRIMARY KEY (id ),
  CONSTRAINT risultatiquestionario_attivitasupervisione FOREIGN KEY (attivitasupervisione_attivitasupervisione_e_id)
      REFERENCES attivitasupervisione (id) MATCH SIMPLE
      ON UPDATE NO ACTION ON DELETE NO ACTION,
  CONSTRAINT risultatiquestionario_histog FOREIGN KEY (outputhistog_histog_e_id)
      REFERENCES outputhistog (id) MATCH SIMPLE
      ON UPDATE NO ACTION ON DELETE NO ACTION,
  CONSTRAINT risultatiquestionario_percentili FOREIGN KEY (out_percentili_percentili_e_id)
      REFERENCES out_percentili (id) MATCH SIMPLE
      ON UPDATE NO ACTION ON DELETE NO ACTION,
  CONSTRAINT risultatiquestionario_probabilitascenario FOREIGN KEY (out_probabilitascen_probabilitascenario_e_id)
      REFERENCES out_probabilitascen (id) MATCH SIMPLE
      ON UPDATE NO ACTION ON DELETE NO ACTION,
  CONSTRAINT risultatiquestionario_promemoria FOREIGN KEY (outputpromemoria_promemoria_e_id)
      REFERENCES outputpromemoria (id) MATCH SIMPLE
      ON UPDATE NO ACTION ON DELETE NO ACTION,
  CONSTRAINT risultatiquestionario_risposte FOREIGN KEY (outputrisposte_risposte_e_id)
      REFERENCES outputrisposte (id) MATCH SIMPLE
      ON UPDATE NO ACTION ON DELETE NO ACTION,
  CONSTRAINT risultatiquestionario_scenarioprob FOREIGN KEY (out_scenarioprob_scenarioprob_e_id)
      REFERENCES out_scenarioprob (id) MATCH SIMPLE
      ON UPDATE NO ACTION ON DELETE NO ACTION,
  CONSTRAINT risultatiquestionario_siar FOREIGN KEY (out_siar_siar_e_id)
      REFERENCES out_siar (id) MATCH SIMPLE
      ON UPDATE NO ACTION ON DELETE NO ACTION,
  CONSTRAINT risultatiquestionario_sintesidistrubuzione FOREIGN KEY (outputsintesidistribuzione_sintesidistrubuzione_e_id)
      REFERENCES outputsintesidistribuzione (id) MATCH SIMPLE
      ON UPDATE NO ACTION ON DELETE NO ACTION,
  CONSTRAINT risultatiquestionario_variabileutente FOREIGN KEY (risultatiquestionario_variabileutente_id)
      REFERENCES variabileutente (id) MATCH SIMPLE
      ON UPDATE NO ACTION ON DELETE NO ACTION
)
WITH (
  OIDS=FALSE
);


CREATE TABLE outputrisposte
(
  id bigint NOT NULL,
  dtype character varying(255) NOT NULL,
  e_version integer NOT NULL,
  identity bigint,
  risposta_domanda1_a character varying(255),
  risposta_domanda1_b character varying(255),
  risposta_domanda2_a character varying(255),
  risposta_domanda2_b character varying(255),
  risposta_domanda3 character varying(255),
  risposta_domanda4 character varying(255),
  risposta_domanda5_1 character varying(255),
  risposta_domanda5_2 character varying(255),
  risposta_domanda5_3 character varying(255),
  risposta_domanda5_4 character varying(255),
  risposta_domanda5_6 character varying(255),
  risposta_domanda5_7 character varying(255),
  risposta_domanda5_8 character varying(255),
  risposta_domanda5_9 character varying(255),
  risposta_domanda5_10 character varying(255),
  risposta_domanda6_1 character varying(255),
  risposta_domanda6_2 character varying(255),
  risposta_domanda6_3 character varying(255),
  risposta_domanda6_4 character varying(255),
  risposta_domanda6_5 character varying(255),
  risposta_domanda6_6 character varying(255),
  risposta_domanda6_7 character varying(255),
  risposta_domanda6_8 character varying(255),
  risposta_domanda6_9 character varying(255),
  risposta_domanda6_10 character varying(255),
  risp_dom3_equiprob_1 character varying(255),
  risp_dom3_equiprob_2 character varying(255),
  risp_dom3_equiprob_3 character varying(255),
  risp_dom3_equiprob_4 character varying(255),
  risp_dom3_equiprob_5 character varying(255),
  risp_dom3_equiprob_6 character varying(255),
  risp_dom3_equiprob_7 character varying(255),
  risp_dom3_equiprob_8 character varying(255),
  risp_dom3_equiprob_9 character varying(255),
  risp_dom3_equiprob_10 character varying(255),
  risposta_domanda5_5 character varying(255),
  CONSTRAINT outputrisposte_pkey PRIMARY KEY (id )
)
WITH (
  OIDS=FALSE
);



Top
 Profile  
 
 Post subject: Re: ManyToOne lazy inizialization
PostPosted: Mon Mar 05, 2012 6:53 am 
Expert
Expert

Joined: Tue Jun 16, 2009 3:36 am
Posts: 990
Hm,

I suggest you to download the sources of your Hibernate-Core version and then debug your app by putting a breakpoint on SessionImpl#immediateLoad().
On the debugger halts on the breakpoint, go back the stacktrace and try to find out what it leading hibernate to the immediate proxy initialization.


Top
 Profile  
 
 Post subject: Re: ManyToOne lazy inizialization
PostPosted: Tue Mar 06, 2012 3:53 am 
Newbie

Joined: Sat Mar 03, 2012 9:54 am
Posts: 3
thank you for pointing me in the right direction. the culprit seems to be teneo, that somehow triggres the object initialization.

i'm switching to their forum now :)

tvm.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.