java - "failed to lazily initialize a collection of role" in Hibernate -




i've seen question asked lot , know why happens, i'm having issues trying solve in specific case.

i'm converting project i'm working on using xml files map classes database tables hibernate, using hibernate annotations. going fine long i'm using basic java types (primitives or class versions of primitives, e.g. int or integer). when comes class having member class of mine, things go south.

one type of issue when have onetomany relationship.

in xml file foo says this:

<set inverse="true" name="barlist">     <key>         <column name="foo_id"/>     </key>     <one-to-many class="com.me.model.dao.bar" /> </set> 

in converting annotation, end this:

@onetomany @jointable(name = "bar", inversejoincolumns = @joincolumn(name = "foo_id")) public set<bar> getbarlist() {     return barlist; } 

i've tried other variations of (including have joincolumn), , know stands may incomplete, said, i'm having trouble finding proper solution rid of lazy initial exception when i'm working objects in view of mvc. fetchtype.eager said workaround , not solution, curiously, solutions not offered. maybe more information needed.

  • my mvc wicket 1.4.17.
  • my app server widlfly (i.e. no web.xml)
  • java version 8.
  • hibernate, through maven pom
    • artifact : hibernate
    • version : 3.5.0.ga
    • artifact : ejb3-persistence
    • version : 1.0.1.ga

edit: might helpful add while barlist appears in foo class, there no reference of kind bar in foo in database. foo table have bar_id.

actually, annotation make mapping more simple , easily. both xml or annotation same ideas(to make hibernate understand our objects' relationship). in case, mapping simple like:

    @onetomany(mappedby="foo")       private set<bar> barlist; 

for whole detail, sample looks same yours: https://www.mkyong.com/hibernate/hibernate-one-to-many-relationship-example-annotation/

hope help.





wiki

Comments

Popular posts from this blog

Asterisk AGI Python Script to Dialplan does not work -

kotlin - Out-projected type in generic interface prohibits the use of metod with generic parameter -

python - Read npy file directly from S3 StreamingBody -