java - Exception evaluating SpringEL expression: "profesor.post" when trying to display posts that belong to currently logged user in Spring -


i using spring , have application profesors can post posts. trying display posts belong 1 profesor posting them or logged in. between profesor , posts classes have bidirectional relationship one-to-many trying achieve this:

profesor.java

@entity public class profesor extends user {  @onetomany(mappedby = "profesor",  fetch = fetchtype.lazy) private list<post> post; //getters , setters  } 

post.java

@entity public class post {     @manytoone(fetch = fetchtype.lazy)     @joincolumn (name="profesor_id", referencedcolumnname="id", unique=true)      private profesor profesor;     //getters , setters } 

and trying display this

index.html

<tr th:each="post : ${profesor.post}">  <td class="message" data-th-text="${post.message}"></td> 

i got error in console

el1008e: property or field 'post' cannot found on object of type 'java.util.arraylist' - maybe not public? 

or 1 in browser

exception evaluating springel expression: "profesor.post" 

what doing wrong?

you might want try fetch = fetchtype.eager.

only data fetched every time, if have done, fetchtype.lazy not fetch until access them, here you're not accessing them.

but careful when using eager, since query become slower.

http://www.baeldung.com/hibernate-lazy-eager-loading

this has information.

these entity classes:

public class professor implements serializable {  @id private string id;  @onetomany(mappedby = "professor", fetch = eager) private list<post> posts; }  @entity public class post implements serializable {  @manytoone private professor professor; } 

check out, should work. if not, may need bit more of code.


Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -