java - Hibernate with JPA annotation problem - lazy object -


i have user table associated many other tables, in general, star topology.

like this:

@entity @table(name = "user") public class user implements serializable {     private static final long serialversionuid = 1l;      @id     @sequencegenerator(name = "user_userid_generator", sequencename = "user_seq")     @generatedvalue(strategy = generationtype.sequence, generator = "userr_userid_generator")     @column(name = "user_id")     private long userid;      @basic     @column(name = "password_hex")     private string password;      @basic     @column(name = "language")     private string language;      @temporal(temporaltype.date)     private date created;      @temporal(temporaltype.date)     private date modyfied;      @basic     @column(name = "first_name")     private string firstname;      @basic     @column(name = "last_name")     private string lastname;      @basic     @column(name = "passport")     private string passport;      @basic     @column(name = "pesel")     private string pesel;      @basic     @column(name = "phone_nr1")     private string phonenr1;      @basic     @column(name = "phone_nr2")     private string phonenr2;      @column(name = "hash")     private string hash;       // uni-directional many-to-one association dictusertype     @manytoone     @joincolumn(name = "status")     private dictuserstatus status;      @onetomany(fetch = fetchtype.lazy, mappedby = "user", cascade = { cascadetype.all })     private set<email> emails = new hashset<email>(0);      @onetomany(fetch = fetchtype.lazy, mappedby = "user", cascade = { cascadetype.all })     private set<address> address = new hashset<address>(0);      @onetomany(fetch = fetchtype.lazy, mappedby = "user", cascade = { cascadetype.all })     private set<archivepasswords> archivepasswords = new hashset<archivepasswords>(             0);      @onetomany(fetch = fetchtype.lazy, mappedby = "user", cascade = { cascadetype.all })     private set<hostswhitelist> hostswhitelist = new hashset<hostswhitelist>(0); 

.... have dao layer, method of search user id.

public user finduser(long userid) throws usernotfoundexception {     user user = userdao.finduser(userid);     if (user == null) {         throw new usernotfoundexception("could not find user id = "                 + userid);     }      return user; } 

why lazy fetching not work?

you should post stack trace receiving. lazyloadingexception occurring? on user object? trying access object?

is notorious lazyinitializationexception? if so, need either traverse object graph manually in service (assuming dao code snippet service method , not dao itself), or research opensessioninviewfilter (assuming using spring).


Comments

Popular posts from this blog

Javascript line number mapping -

c# - Is it possible to remove an existing registration from Autofac container builder? -

php - Mysql PK and FK char(36) vs int(10) -