[EJB 3.0] - Implementing business-logic: ConcurrentModificationException
by dgdwinte
Hi all,
I use a stateless session-bean to implement the business-logic to save entity-beans. The stateless session-bean uses injection of the entitymanager as follows:
| @Stateless(mappedName = "PersonDAO")
| public class PersonDAO extends DAOBasicOperationsAbstractClass<Person> implements PersonDAOInterfaceLocal, PersonDAOInterfaceRemote{
| @PersistenceContext(unitName = "texaco", type = PersistenceContextType.TRANSACTION)
| EntityManager em;
|
Before saving the "Person"-entitybean, I'd like to do some checks by executing a native read-query in a separate method on the same table (join with other ones) where I'd like to save the Person:
| Query query=em.createNativeQuery(
| querystring
| );
|
| query.setParameter("TELEPHONENUMBER_1", person.getPhonenumber1()==null?"K":person.getPhonenumber1().getPhoneNumber());
| query.setParameter("TELEPHONENUMBER_2", person.getPhonenumber2()==null?"K":person.getPhonenumber2().getPhoneNumber());
| query.setParameter("GSMNUMBER_1", person.getGsmnumber1()==null?"K":person.getGsmnumber1().getPhoneNumber());
| query.setParameter("GSMNUMBER_2", person.getGsmnumber2()==null?"K":person.getGsmnumber2().getPhoneNumber());
| if (update) query.setParameter("ID", person.getId());
| Collection<Person> pers_coll=executeMultipleResultQuery(query);
| if (pers_coll.size()>0) return false;
| else return true;
|
If this method returns true, the new person will not be saved, otherwise he will be saved as follows:
| if (!checkPhoneNumberValidity(person, true)) throw new PersonValidationException();
| Person person_orig=findById(person.getId());
| if (!person_orig.equals(person)){
| person_orig.getLatestValidPersonProperty().getValidityinterval().invalidate();
| person.getLatestValidPersonProperty().setValidityinterval(new ValidityInterval(new GregorianCalendar(), new GregorianCalendar(2099, 12, 12)));
| person.getLatestValidPersonProperty().setId(null);
| person_orig.getPersonproperties().add(person.getLatestValidPersonProperty());
| person_orig.setName(person.getName());
| person_orig.setFirstname(person.getFirstname());
| person_orig.setNationalregisternumber(person.getNationalregisternumber());
| person_orig.setIdentitycardnumber(person.getIdentitycardnumber());
| person_orig.setBirthdate(person.getBirthdate());
| person_orig.setSex(person.getSex());
| person_orig.deepValidate();
| executeMerge(em, person_orig);
| }
|
Please note, I also make some comparisons with the original object as I work with properties. In this scenario, I get a ConcurrentModificationException. Seems logic to me, but how to solve this in a proper way, because the checks must happen within the same transaction.
Any help or advice is very appreciated!
Best regards,
Davy.
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4138436#4138436
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4138436
18 years, 1 month
[Installation, Configuration & DEPLOYMENT] - which jar contains class org.jboss.util.id.UID
by gcameo
I am having this exception whiles trying to call a Remote EJB method
java.lang.NoClassDefFoundError: Could not initialize class org.jboss.util.id.UID
| at org.jboss.util.id.VMID.create(VMID.java:259)
| at org.jboss.util.id.VMID.getInstance(VMID.java:223)
| at org.jboss.util.id.GUID.<init>(GUID.java:65)
| at org.jboss.remoting.Client.<init>(Client.java:268)
| at org.jboss.remoting.Client.<init>(Client.java:243)
| at org.jboss.remoting.Client.<init>(Client.java:230)
| at org.jboss.aspects.remoting.InvokeRemoteInterceptor.invoke(InvokeRemoteInterceptor.java:57)
| at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
| at org.jboss.aspects.tx.ClientTxPropagationInterceptor.invoke(ClientTxPropagationInterceptor.java:67)
| at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
| at org.jboss.aspects.security.SecurityClientInterceptor.invoke(SecurityClientInterceptor.java:53)
| at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
| at org.jboss.ejb3.remoting.IsLocalInterceptor.invoke(IsLocalInterceptor.java:74)
| at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
| at org.jboss.ejb3.stateless.StatelessRemoteProxy.invoke(StatelessRemoteProxy.java:107)
| at $Proxy0.execute(Unknown Source)
| at com.console.web.BusinessDelegate.processLogin(BusinessDelegate.java:45)
| at com.console.web.LoginProcessor.processLogin(LoginProcessor.java:75)
| at com.console.web.LoginProcessor.doLogon(LoginProcessor.java:62)
| at com.console.web.FrontFilter.doFilter(FrontFilter.java:41)
| at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
| at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
| at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
| at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
| at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
| at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
| at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
| at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:263)
| at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
| at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:584)
| at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
| at java.lang.Thread.run(Thread.java:619)
| wanted to know which jar contains that jar
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4138434#4138434
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4138434
18 years, 1 month
[JBoss Portal] - Re: Servlet calling java:portal/UserModule
by foongkim
guys, problem solved.
the NULL Pointer is because in my eclipse project, i have included the hibernate3.jar and it's seems its crashed with the hibernate3.jar inside the JBoss app server.
after i have removed the hibernate in my project (as i will use the JBoss), everything is working fine means i can pull the information from the portal user.
Below is the complete code.
SessionFactory identitySessionFactory = null;
Session session = null;
Transaction transaction = null;
try
{
identitySessionFactory = (SessionFactory) new InitialContext().lookup("java:portal/IdentitySessionFactory");
session = identitySessionFactory.openSession();
transaction = session.beginTransaction();
UserModule userModule = (UserModule) new InitialContext().lookup("java:portal/UserModule");
User temp_user = userModule.findUserByUserName(username);
authenticateUser = temp_user.validatePassword(password);
session.clear();
}
catch (Exception e)
{
e.printStackTrace();
}
finally
{
if (transaction != null)
transaction.commit();
if (session != null)
session.close();
}
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4138422#4138422
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4138422
18 years, 1 month