Use struts to transmit values and hibernate exceptions between front-end pages: A different object with the same identifier value is already associated with the session summary

Source: Internet
Author: User

2017-3-16

I'm using the SSH framework to do a single-table CRUD update operation encountered a problem, that is, how to pass the value between pages? The need to solve the problem caused a series of bugs, while still remember a good summary.

Transfer values between front-end pages

Scenario : After I've identified the record, clicking Edit will link to the new edit page.

problem : This new page does not have previous entity information, how do I pass the entity information that I want to modify to this page, such as ID?

Idea 1: Use Struts's action to pass the value.

1 <formAction= "Deletesercate.action"Method= "POST">2     <inputtype= "hidden"name= "Servicecategory.id"value= "<s:property value="#list. ID "/>">3     <inputtype= "Submit"value= "Delete">4     <ahref= "Servicecid.action?servicecategory.id=<s:property value="#list. ID "/>"> Modify</a>5 </form>

Take a look at my <a> URL, I created an action and passed the ID value in the URL. Then just return "success" in the new action, as follows:

1 // Pass ID to update page 2  Public String servicecid () {3     return "Success"; 4 }

Then return to the update page in the corresponding action in Struts.xml:

1 <!--Pass ID to update page -2 <Actionname= "Servicecid"class= "Sercateaction"Method= "Servicecid">3     <resultname= "Success">/updatesercate.jsp</result>4 </Action>

Click "Modify" after the completion of the jump to the update page, the page is now available to update the entity's ID number. As follows:

Idea 2: the same value in the URL, in the new page with JS to get the value. The idea has not been implemented yet, but it feels feasible. Pending inspection.

Summary : The front-end page transfer value, the front and rear end of the value is often encountered scene, here I use the action to pass value is a method, there should be a better way, if there is new experience to be summarized.

Hibernate exception: A different object with the same identifier value is already associated with the session

Session.update (object) in the update operation; The Times has made the above error.

cause : in Hibernate, there are two identical identities in the same session but different entities, that is, 2 different objects are associated to the same flag bit. For example, in my case, there are two objects in the session that are associated to the same ID and do not know which object to update when the session is updated.

Workaround: Perform a session.clear () operation before the update. As follows:

1 /* 2  3    4 * associated with the session 5 */   6 session.clear (); 7  Session.update (servicecategory);

Sometimes after the session.clear () operation will be reported "Found the representations of same collection" Exception , the specific reason I do not understand, to be understood and resolved.

This article to solve the problem when the most help me, the message also got a lot of harvest: http://www.blogjava.net/hrcdg/articles/157724.html

Use struts to transmit values and hibernate exceptions between front-end pages: A different object with the same identifier value is already associated with the session summary

Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.