[EJB 3.0] - deleted entity passed to persist:
by m.shinde
Hi ,
I am getting following exception after deletion of entity bean.
| Caused by: javax.persistence.EntityNotFoundException: deleted entity passed to persist: [de.bonprix.orderstarter.model.entity.ArticleSupplier#<null>]
| at org.hibernate.ejb.AbstractEntityManagerImpl.throwPersistenceException(AbstractEntityManagerImpl.java:613)
| at org.hibernate.ejb.AbstractEntityManagerImpl.flush(AbstractEntityManagerImpl.java:299)
| at org.jboss.seam.persistence.EntityManagerProxy.flush(EntityManagerProxy.java:83)
| at de.bonprix.orderstarter.service.ManageOrders.deleteSupplierDetails(ManageOrders.java:476)
| at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
| at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
| at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
| at java.lang.reflect.Method.invoke(Method.java:585)
| at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:112)
| at org.jboss.ejb3.interceptor.InvocationContextImpl.proceed(InvocationContextImpl.java:166)
| at org.jboss.seam.intercept.EJBInvocationContext.proceed(EJBInvocationContext.java:37)
| at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:57)
| at org.jboss.seam.interceptors.BijectionInterceptor.aroundInvoke(BijectionInterceptor.java:47)
| at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:69)
| at org.jboss.seam.interceptors.ManagedEntityIdentityInterceptor.aroundInvoke(ManagedEntityIdentityInterceptor.java:37)
| at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:69)
| at org.jboss.seam.interceptors.ConversationInterceptor.aroundInvoke(ConversationInterceptor.java:63)
| at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:69)
| at org.jboss.seam.interceptors.MethodContextInterceptor.aroundInvoke(MethodContextInterceptor.java:27)
| at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:69)
| at org.jboss.seam.intercept.RootInterceptor.invoke(RootInterceptor.java:103)
| at org.jboss.seam.intercept.SessionBeanInterceptor.aroundInvoke(SessionBeanInterceptor.java:53)
| at sun.reflect.GeneratedMethodAccessor108.invoke(Unknown Source)
| at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
| at java.lang.reflect.Method.invoke(Method.java:585)
| at org.jboss.ejb3.interceptor.InvocationContextImpl.proceed(InvocationContextImpl.java:118)
| at org.jboss.ejb3.interceptor.EJB3InterceptorsInterceptor.invoke(EJB3InterceptorsInterceptor.java:63)
| at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
| at org.jboss.ejb3.entity.ExtendedPersistenceContextPropagationInterceptor.invoke(ExtendedPersistenceContextPropagationInterceptor.java:57)
| at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
| at org.jboss.ejb3.entity.TransactionScopedEntityManagerInterceptor.invoke(TransactionScopedEntityManagerInterceptor.java:54)
| at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
| at org.jboss.ejb3.AllowedOperationsInterceptor.invoke(AllowedOperationsInterceptor.java:47)
| at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
| at org.jboss.aspects.tx.TxPolicy.invokeInOurTx(TxPolicy.java:79)
| ... 77 more
|
And Below is my code
@TransactionAttribute(TransactionAttributeType.REQUIRED)
| public void deleteSupplierDetails() {
| if (this.artSuppPriceList != null) {
| for (int i = 0; i < this.artSuppPriceList.size(); i++) {
| ArticleSupplierPrice artSuppPriceObj = this.artSuppPriceList.get(i);
| if (artSuppPriceObj.getIsChecked() != null
| && artSuppPriceObj.getIsChecked().equals(Boolean.TRUE)) {
| entityManager.remove(artSuppPriceObj);
| }
| }
| entityManager.flush();
| }
| }
I have two entites ArticleSupplier and ArticleSupplierPrice has OneToMany relationship respectively.
Suggest.
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4093079#4093079
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4093079
18Â years, 7Â months
[JBoss Seam] - How to write a validator that compares two fields
by chawax
Hi,
I need to write a JSF validator which compares two fields. It could be used for example to compare "new password" and "confirm password" fields.
To do this, I wrote the following class :
@Name (value="validator.compareFields")
| @org.jboss.seam.annotations.faces.Validator
|
| public class CompareFieldsValidator implements Validator {
|
| private @In FacesMessages facesMessages;
|
| public void validate(FacesContext context, UIComponent cmp, Object value)
| throws ValidatorException
| {
| String compareTo = (String) cmp.getAttributes().get("compareTo");
| UIInput input = (UIInput) cmp.findComponent(compareTo);
| String otherValue = (String) input.getSubmittedValue();
| boolean error = false;
| if (value != null) {
| if (! value.equals(otherValue)) error = true;
| }
| else {
| if (otherValue != null) error = true;
| }
| if (error) {
| facesMessages.addToControlFromResourceBundle(cmp.getId(), "error.fieldsNotEqual", null);
| throw new ValidatorException(new FacesMessage());
| }
| }
| }
Then in my JSF, I use it this way :
<h:outputLabel value="New password :" for="newPassword" />
| <h:inputSecret id="newPassword" value="#{userCrud.newPassword}">
| <f:validator validatorId="validator.compareFields" />
| <f:attribute name="compareTo" value="confirmPassword" />
| </h:inputSecret>
|
| <h:outputLabel value="Confirm password :" for="confirmPassword" />
| <h:inputSecret id="confirmPassword" value="#{userCrud.confirmPassword}" />
It works well except when my inputSecret fields are surrounded by <s:decorate>.
<s:decorate template="/decorateField.xhtml">
| <h:inputSecret id="newPassword" value="#{userCrud.newPassword}">
| <f:validator validatorId="validator.compareFields" />
| <f:attribute name="compareTo" value="confirmPassword" />
| </h:inputSecret>
| </s:decorate>
In this case, the UIComponent.findComponent() can't find the field corresponding to "compareTo" attribute. For what I understood, it works only if the two fields to compare have the same parent in JSF components tree (while I thought findComponent was searching recursively the component). Anyone knows how I could make it work ?
Note also that I'm not sure the way I used facesMessages object, especially the way I throw ValidatorException. I couldn't find an example with message in a resource bundle. So please tell me if there's a better way to write it.
Thanks in advance
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4093072#4093072
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4093072
18Â years, 7Â months