Spring Data Mongo MongoDB DBRef lazy initialization
up vote
4
down vote
favorite
I'm using Spring + Spring Data MongoDB.
My model is like this:
@Document(collection = "actors")
public class Actor extends DomainEntity {
private String name;
private String surname;
@DBRef(lazy = true)
private List<Class> classes;
The other class is pretty generic, so I don't post it.
My problem is that the list "classes" isn't loaded when i try to access it, the attribute remains being some kind of proxy object.
Example:
Actor a = actorRepository.findOne(id);
//At this moment classes are a proxy object because of the lazy
//Now I try to load the reference and nothing works
a.getClasses();
a.getClasses().size();
a.getClases().get(0).getAttr();
for(Class g:a.getClasses()){
g.getAttr();
}
I considered a ton of options, but no way to make it working...
spring spring-data spring-data-mongodb lazy-initialization dbref
add a comment |
up vote
4
down vote
favorite
I'm using Spring + Spring Data MongoDB.
My model is like this:
@Document(collection = "actors")
public class Actor extends DomainEntity {
private String name;
private String surname;
@DBRef(lazy = true)
private List<Class> classes;
The other class is pretty generic, so I don't post it.
My problem is that the list "classes" isn't loaded when i try to access it, the attribute remains being some kind of proxy object.
Example:
Actor a = actorRepository.findOne(id);
//At this moment classes are a proxy object because of the lazy
//Now I try to load the reference and nothing works
a.getClasses();
a.getClasses().size();
a.getClases().get(0).getAttr();
for(Class g:a.getClasses()){
g.getAttr();
}
I considered a ton of options, but no way to make it working...
spring spring-data spring-data-mongodb lazy-initialization dbref
So, what exactly is the problem? What doesn't work? Which exceptions do you get? What would you like to see? If you don't want a proxy forClass, don't make it lazy.
– Oliver Drotbohm
Feb 21 '15 at 7:59
I think he wants to use lazy, but that in a particular case he needs the bean read from the DB to be fully exploited. This is possible?
– pagurix
Jun 14 at 13:09
add a comment |
up vote
4
down vote
favorite
up vote
4
down vote
favorite
I'm using Spring + Spring Data MongoDB.
My model is like this:
@Document(collection = "actors")
public class Actor extends DomainEntity {
private String name;
private String surname;
@DBRef(lazy = true)
private List<Class> classes;
The other class is pretty generic, so I don't post it.
My problem is that the list "classes" isn't loaded when i try to access it, the attribute remains being some kind of proxy object.
Example:
Actor a = actorRepository.findOne(id);
//At this moment classes are a proxy object because of the lazy
//Now I try to load the reference and nothing works
a.getClasses();
a.getClasses().size();
a.getClases().get(0).getAttr();
for(Class g:a.getClasses()){
g.getAttr();
}
I considered a ton of options, but no way to make it working...
spring spring-data spring-data-mongodb lazy-initialization dbref
I'm using Spring + Spring Data MongoDB.
My model is like this:
@Document(collection = "actors")
public class Actor extends DomainEntity {
private String name;
private String surname;
@DBRef(lazy = true)
private List<Class> classes;
The other class is pretty generic, so I don't post it.
My problem is that the list "classes" isn't loaded when i try to access it, the attribute remains being some kind of proxy object.
Example:
Actor a = actorRepository.findOne(id);
//At this moment classes are a proxy object because of the lazy
//Now I try to load the reference and nothing works
a.getClasses();
a.getClasses().size();
a.getClases().get(0).getAttr();
for(Class g:a.getClasses()){
g.getAttr();
}
I considered a ton of options, but no way to make it working...
spring spring-data spring-data-mongodb lazy-initialization dbref
spring spring-data spring-data-mongodb lazy-initialization dbref
edited Nov 21 at 5:44
Cœur
17k9102140
17k9102140
asked Feb 20 '15 at 11:58
Lombardo
2112
2112
So, what exactly is the problem? What doesn't work? Which exceptions do you get? What would you like to see? If you don't want a proxy forClass, don't make it lazy.
– Oliver Drotbohm
Feb 21 '15 at 7:59
I think he wants to use lazy, but that in a particular case he needs the bean read from the DB to be fully exploited. This is possible?
– pagurix
Jun 14 at 13:09
add a comment |
So, what exactly is the problem? What doesn't work? Which exceptions do you get? What would you like to see? If you don't want a proxy forClass, don't make it lazy.
– Oliver Drotbohm
Feb 21 '15 at 7:59
I think he wants to use lazy, but that in a particular case he needs the bean read from the DB to be fully exploited. This is possible?
– pagurix
Jun 14 at 13:09
So, what exactly is the problem? What doesn't work? Which exceptions do you get? What would you like to see? If you don't want a proxy for
Class, don't make it lazy.– Oliver Drotbohm
Feb 21 '15 at 7:59
So, what exactly is the problem? What doesn't work? Which exceptions do you get? What would you like to see? If you don't want a proxy for
Class, don't make it lazy.– Oliver Drotbohm
Feb 21 '15 at 7:59
I think he wants to use lazy, but that in a particular case he needs the bean read from the DB to be fully exploited. This is possible?
– pagurix
Jun 14 at 13:09
I think he wants to use lazy, but that in a particular case he needs the bean read from the DB to be fully exploited. This is possible?
– pagurix
Jun 14 at 13:09
add a comment |
1 Answer
1
active
oldest
votes
up vote
3
down vote
I'm using spring-data-mongodb-1.7.0.RELEASE and I was able to solve this issue by initializing the lazy-loaded collection in its declaration, for instance:
@DBRef(lazy = true)
private List<Class> classes = new ArrayList<>();
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
3
down vote
I'm using spring-data-mongodb-1.7.0.RELEASE and I was able to solve this issue by initializing the lazy-loaded collection in its declaration, for instance:
@DBRef(lazy = true)
private List<Class> classes = new ArrayList<>();
add a comment |
up vote
3
down vote
I'm using spring-data-mongodb-1.7.0.RELEASE and I was able to solve this issue by initializing the lazy-loaded collection in its declaration, for instance:
@DBRef(lazy = true)
private List<Class> classes = new ArrayList<>();
add a comment |
up vote
3
down vote
up vote
3
down vote
I'm using spring-data-mongodb-1.7.0.RELEASE and I was able to solve this issue by initializing the lazy-loaded collection in its declaration, for instance:
@DBRef(lazy = true)
private List<Class> classes = new ArrayList<>();
I'm using spring-data-mongodb-1.7.0.RELEASE and I was able to solve this issue by initializing the lazy-loaded collection in its declaration, for instance:
@DBRef(lazy = true)
private List<Class> classes = new ArrayList<>();
answered Aug 1 '15 at 4:12
Douglas
1,1531019
1,1531019
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f28628447%2fspring-data-mongo-mongodb-dbref-lazy-initialization%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
So, what exactly is the problem? What doesn't work? Which exceptions do you get? What would you like to see? If you don't want a proxy for
Class, don't make it lazy.– Oliver Drotbohm
Feb 21 '15 at 7:59
I think he wants to use lazy, but that in a particular case he needs the bean read from the DB to be fully exploited. This is possible?
– pagurix
Jun 14 at 13:09