reset password
Author Message
cysun
Posts: 2935
Posted 13:53 May 08, 2013 |

For your homework, please add the following to your web.xml:

    <filter>
        <filter-name>jpaFilter</filter-name>  
        <filter-class>org.springframework.orm.jpa.support.OpenEntityManagerInViewFilter</filter-class>  
    </filter>  

    <filter-mapping>  
        <filter-name>jpaFilter</filter-name>  
        <url-pattern>/*</url-pattern>  
    </filter-mapping>

I'll explain in class.

xytian
Posts: 70
Posted 13:06 May 09, 2013 |

Hi Professor,

I encountered problems on the other way. To review a lawyer, I first created a new Review object, set the lawyer and user field, then pass it to jsp as ModelAttribute. After it is returned, the ratings and comment fields seem fine, but the user/lawyer (or reviewer/reviewee) fields are null.

Then I tried another way, I pass a new Review object to jsp, after I collect the input values I manually set the user/lawyer field,  and add this review to the lawyer's reviews list, then tried to save the Lawyer object.  But now I get an "detached entity passed to persist" error! I tried to save either a user, lawyer, or the review, but I kept getting the same message.

cysun
Posts: 2935
Posted 13:21 May 09, 2013 |
megtian wrote:

Hi Professor,

I encountered problems on the other way. To review a lawyer, I first created a new Review object, set the lawyer and user field, then pass it to jsp as ModelAttribute. After it is returned, the ratings and comment fields seem fine, but the user/lawyer (or reviewer/reviewee) fields are null.

...

1. Use @SessionAttribute

2. Use merge() instead of persist()

xytian
Posts: 70
Posted 13:54 May 09, 2013 |

Professor,

Things didn't change. Please refer to the attached pics for codes in my UserController.java.
(1) I added @SessionAttributes("newreview"), the println output is still null for lawyer and user (Line 153, 154).
(2) I did use Merge in UserDaoImpl.java.

(3) I guess I just need to save "lawyer", then the review should be automatically saved, is it right?
    Here is the field attributes in class Lawyer and Review :
 @OneToMany(mappedBy="lawyer",
   cascade=CascadeType.ALL)
 @OrderBy("postedOn desc")
 private List<Review> feedbacks;
    -----------------------------------------
 @ManyToOne
 private User user;
 
 @ManyToOne
 private Lawyer lawyer;

Last edited by cysun at 14:09 May 09, 2013.
cysun
Posts: 2935
Posted 14:13 May 09, 2013 |
megtian wrote:

Professor,

Things didn't change. Please refer to the attached pics for codes in my UserController.java. ...

I've removed the attached screenshot. Please do not post complete code in the forum; doing so will be considered facilitating cheating.

You can post error messages and code snippets, and you can describe your code in English. Just don't post complete methods and so on.
 

cysun
Posts: 2935
Posted 14:18 May 09, 2013 |
megtian wrote:
...

(3) I guess I just need to save "lawyer", then the review should be automatically saved, is it right?
    Here is the field attributes in class Lawyer and Review :
 @OneToMany(mappedBy="lawyer",
   cascade=CascadeType.ALL)
 @OrderBy("postedOn desc")
 private List<Review> feedbacks;
    -----------------------------------------
 @ManyToOne
 private User user;
 
 @ManyToOne
 private Lawyer lawyer;

It would, but it doesn't solve the problem of missing user and lawyer, i.e. the review would have null in those fields.