Hi,
ich erhalte folgende Error-message (s.u.), wenn ich auf meine getChildren() Methode meiner TreeNode-Klasse zugreifen will. Hier der Code:
Und hier die Exception:
Weiss jemand woran das liegen könnte?
ich erhalte folgende Error-message (s.u.), wenn ich auf meine getChildren() Methode meiner TreeNode-Klasse zugreifen will. Hier der Code:
Code:
@Entity
@Transactional
public class TreeNode implements Serializable{
@Id
@GeneratedValue
protected Long id;
protected String name="";
@ManyToOne
protected Device device = null;
@ManyToOne
@JoinColumn(name="parent_id")
protected TreeNode parent = null;
@OneToMany(mappedBy="parent", fetch = FetchType.LAZY)
protected Set<TreeNode> children = new HashSet<TreeNode>();
protected TreeNode(){}
....
@Transactional
public Set<TreeNode> getChildren(){
return this.children;
...
}
Code:
@Configuration
@EnableWebSecurity
@EnableGlobalMethodSecurity(securedEnabled = true)
@EnableTransactionManagement
public static class SecurityConfiguration extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
HttpSessionSecurityContextRepository securityContextRepository = new HttpSessionSecurityContextRepository();
SecurityContextPersistenceFilter filter = new SecurityContextPersistenceFilter(securityContextRepository);
http
.csrf().disable() // Use Vaadin's CSRF protection
.addFilter(filter);
}
}
Und hier die Exception:
Code:
org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: x.z.y.data.TreeNode.children, could not initialize proxy - no Session
at org.hibernate.collection.internal.AbstractPersistentCollection.throwLazyInitializationException(AbstractPersistentCollection.java:587) ~[hibernate-core-5.0.9.Final.jar:5.0.9.Final]
at org.hibernate.collection.internal.AbstractPersistentCollection.withTemporarySessionIfNeeded(AbstractPersistentCollection.java:204) ~[hibernate-core-5.0.9.Final.jar:5.0.9.Final]
at org.hibernate.collection.internal.AbstractPersistentCollection.readSize(AbstractPersistentCollection.java:148) ~[hibernate-core-5.0.9.Final.jar:5.0.9.Final]
at org.hibernate.collection.internal.PersistentSet.size(PersistentSet.java:143) ~[hibernate-core-5.0.9.Final.jar:5.0.9.Final]
at x.y.z.data.TreeNode.getChildren(TreeNode.java:277) ~[classes/:na]
Weiss jemand woran das liegen könnte?