-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: bug in BasicPropertyAccessor
PostPosted: Fri Nov 23, 2007 8:22 am 
Newbie

Joined: Tue Apr 04, 2006 6:58 am
Posts: 4
Location: Tampere,Finland
BasicPropertyAccessor attempts to invoke method in wrong class. I have classes DomainName and MboxName, and for some reason during EntityManger.flush(), it tries to acces DomainName.getDescription on MboxName. Why, I have no idea.

I found this out when running the code in debug mode. BasicProperyAccessor has method 'getDescription' for 'DomainName', and gets given 'target = MboxName'. Invokation fails, of course.

Hibernate version: 3.2-GA

Mapping documents:
Set<DomainName> names in Domain
Set<MboxName> names in Mbox


Code between sessionFactory.openSession() and session.close():
Code:
   try {
       utx.begin();
       getEm().joinTransaction();
      
       Domain d = getEm().find(Domain.class, domainId);
      
       if (d == null) {
      throw new DomainNotFound("id " + domainId);
       }
      
       javax.persistence.Query q = getEm().createQuery("SELECT m FROM Mbox m, MboxName mn WHERE m.domain = ? AND mn.mbox_name = ? AND mn.mbox = m");
      
       for(String mboxName: names) {
      if (q.setParameter(1, d).setParameter(2, mboxName).getResultList().size() != 0) {
          throw new Exception("mbox alias " + mboxName + " already in use in domain");
      }
       }
      
       // create a username
       Integer counter = d.getLogin_counter();
       if (counter == null) counter = 0;
      
       String prefix = d.getLogin_prefix();
       String suffix = d.getLogin_suffix();
      
       StringBuffer uname = new StringBuffer();
       if (prefix != null)
      uname.append(prefix);
       counter++;
       uname.append(counter);
       if (suffix != null)
      uname.append(suffix);
      
       mbox = new Mbox();
       mbox.setDomain(d);
       mbox.setUsername(uname.toString());
       mbox.setEnabled(false);
       mbox.setFirstname(firstName);
       mbox.setLastname(lastName);
       mbox.setNames(null);
       mbox.setPasswd_salt(generateSalt(Mbox.SALT_SIZE));
       mbox.setPasswd_sha1(generateHash(mbox.getPasswd_salt(), password));
      
       getEm().persist(mbox);
      
       // it should be stored now.
       d.setLogin_counter(counter);
      
       Set<MboxName> mboxNames = new java.util.HashSet<MboxName>();
       for(String name: names) {
      MboxName mboxName = new MboxName();
      mboxName.setMbox(mbox);
      mboxName.setEnabled(false);
      mboxName.setMbox_name(name);
      getEm().persist(mboxName);
      
      if (mboxNames.add(mboxName) == false)
          throw new Exception("Duplicate name " + mboxName + " in name list");
       }
      
       mbox.setNames(mboxNames);
      
       getEm().flush();
       utx.commit();
   } catch (Exception ex) {
       utx.rollback();
       throw ex;
   }
   return mbox;
    }



Full stack trace of any exception that occurs:
[#|2007-11-23T14:14:53.565+0200|SEVERE|sun-appserver9.1|com.sun.xml.ws.server.se
i.EndpointMethodHandler|_ThreadID=16;_ThreadName=httpSSLWorkerThread-8080-0;_Req
uestID=4b704abf-b299-4676-816d-50ae6ad5c0ba;|org.hibernate.PropertyAccessExcepti
on: IllegalArgumentException occurred calling getter of fi.tdc.cpi.mail.pojo.DomainName.description
javax.persistence.PersistenceException: org.hibernate.PropertyAccessException: IllegalArgumentException occurred calling getter of fi.tdc.cpi.mail.pojo.DomainName.description
at org.hibernate.ejb.AbstractEntityManagerImpl.throwPersistenceException(AbstractEntityManagerImpl.java:630)
at org.hibernate.ejb.AbstractEntityManagerImpl.flush(AbstractEntityManagerImpl.java:300)
at fi.tdc.cpi.mail.services.impl.MailboxImpl.createMailBox(MailboxImpl.java:124)
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:597)
at com.sun.enterprise.webservice.InstanceResolverImpl$1.invoke(InstanceResolverImpl.java:112)
at com.sun.xml.ws.server.InvokerTube$2.invoke(InvokerTube.java:146)
at com.sun.xml.ws.server.sei.EndpointMethodHandler.invoke(EndpointMethodHandler.java:257)
at com.sun.xml.ws.server.sei.SEIInvokerTube.processRequest(SEIInvokerTube.java:93)
at com.sun.xml.ws.api.pipe.Fiber.__doRun(Fiber.java:595)
at com.sun.xml.ws.api.pipe.Fiber._doRun(Fiber.java:554)
at com.sun.xml.ws.api.pipe.Fiber.doRun(Fiber.java:539)
at com.sun.xml.ws.api.pipe.Fiber.runSync(Fiber.java:436)
at com.sun.xml.ws.api.pipe.helper.AbstractTubeImpl.process(AbstractTubeImpl.java:106)
at com.sun.enterprise.webservice.MonitoringPipe.process(MonitoringPipe.java:147)
at com.sun.xml.ws.api.pipe.helper.PipeAdapter.processRequest(PipeAdapter.java:115)
at com.sun.xml.ws.api.pipe.Fiber.__doRun(Fiber.java:595)
at com.sun.xml.ws.api.pipe.Fiber._doRun(Fiber.java:554)
at com.sun.xml.ws.api.pipe.Fiber.doRun(Fiber.java:539)
at com.sun.xml.ws.api.pipe.Fiber.runSync(Fiber.java:436)
at com.sun.xml.ws.api.pipe.helper.AbstractTubeImpl.process(AbstractTubeImpl.java:106)
at com.sun.enterprise.webservice.CommonServerSecurityPipe.processRequest(CommonServerSecurityPipe.java:218)
at com.sun.enterprise.webservice.CommonServerSecurityPipe.process(CommonServerSecurityPipe.java:129)
at com.sun.xml.ws.api.pipe.helper.PipeAdapter.processRequest(PipeAdapter.java:115)
at com.sun.xml.ws.api.pipe.Fiber.__doRun(Fiber.java:595)
at com.sun.xml.ws.api.pipe.Fiber._doRun(Fiber.java:554)
at com.sun.xml.ws.api.pipe.Fiber.doRun(Fiber.java:539)
at com.sun.xml.ws.api.pipe.Fiber.runSync(Fiber.java:436)
at com.sun.xml.ws.server.WSEndpointImpl$2.process(WSEndpointImpl.java:243)
at com.sun.xml.ws.transport.http.HttpAdapter$HttpToolkit.handle(HttpAdapter.java:444)
at com.sun.xml.ws.transport.http.HttpAdapter.handle(HttpAdapter.java:244)
at com.sun.xml.ws.transport.http.servlet.ServletAdapter.handle(ServletAdapter.java:135)
at com.sun.enterprise.webservice.JAXWSServlet.doPost(JAXWSServlet.java:159)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:738)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:831)
at org.apache.catalina.core.ApplicationFilterChain.servletService(ApplicationFilterChain.java:411)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:290)
at org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:271)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:202)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:632)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:577)
at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:94)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:206)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:632)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:577)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:571)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:1080)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:150)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:632)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:577)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:571)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:1080)
at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:270)
at com.sun.enterprise.web.connector.grizzly.DefaultProcessorTask.invokeAdapter(DefaultProcessorTask.java:637)
at com.sun.enterprise.web.connector.grizzly.DefaultProcessorTask.doProcess(DefaultProcessorTask.java:568)
at com.sun.enterprise.web.connector.grizzly.DefaultProcessorTask.process(DefaultProcessorTask.java:813)
at com.sun.enterprise.web.connector.grizzly.DefaultReadTask.executeProcessorTask(DefaultReadTask.java:339)
at com.sun.enterprise.web.connector.grizzly.DefaultReadTask.doTask(DefaultReadTask.java:261)
at com.sun.enterprise.web.connector.grizzly.DefaultReadTask.doTask(DefaultReadTask.java:212)
at com.sun.enterprise.web.portunif.PortUnificationPipeline$PUTask.doTask(PortUnificationPipeline.java:361)
at com.sun.enterprise.web.connector.grizzly.TaskBase.run(TaskBase.java:265) at com.sun.enterprise.web.connector.grizzly.ssl.SSLWorkerThread.run(SSLWorkerThread.java:106)
Caused by: org.hibernate.PropertyAccessException: IllegalArgumentException occurred calling getter of fi.tdc.cpi.mail.pojo.DomainName.description
at org.hibernate.property.BasicPropertyAccessor$BasicGetter.get(BasicPropertyAccessor.java:171)
at org.hibernate.tuple.entity.AbstractEntityTuplizer.getPropertyValue(AbstractEntityTuplizer.java:277)
at org.hibernate.persister.entity.AbstractEntityPersister.getPropertyValue(AbstractEntityPersister.java:3581)
at org.hibernate.engine.Cascade.cascade(Cascade.java:139)
at org.hibernate.event.def.AbstractSaveEventListener.cascadeBeforeSave(AbstractSaveEventListener.java:431)
at org.hibernate.event.def.DefaultPersistEventListener.entityIsPersistent(DefaultPersistEventListener.java:110)
at org.hibernate.event.def.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:84)
at org.hibernate.impl.SessionImpl.firePersistOnFlush(SessionImpl.java:644)
at org.hibernate.impl.SessionImpl.persistOnFlush(SessionImpl.java:636)
at org.hibernate.engine.CascadingAction$9.cascade(CascadingAction.java:323)
at org.hibernate.engine.Cascade.cascadeToOne(Cascade.java:268)
at org.hibernate.engine.Cascade.cascadeAssociation(Cascade.java:216)
at org.hibernate.engine.Cascade.cascadeProperty(Cascade.java:169)
at org.hibernate.engine.Cascade.cascadeCollectionElements(Cascade.java:296)
at org.hibernate.engine.Cascade.cascadeCollection(Cascade.java:242)
at org.hibernate.engine.Cascade.cascadeAssociation(Cascade.java:219)
at org.hibernate.engine.Cascade.cascadeProperty(Cascade.java:169)
at org.hibernate.engine.Cascade.cascade(Cascade.java:130)
at org.hibernate.event.def.AbstractFlushingEventListener.cascadeOnFlush(AbstractFlushingEventListener.java:131)
at org.hibernate.event.def.AbstractFlushingEventListener.prepareEntityFlushes(AbstractFlushingEventListener.java:122)
at org.hibernate.event.def.AbstractFlushingEventListener.flushEverythingToExecutions(AbstractFlushingEventListener.java:65)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:26)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1000)
at org.hibernate.ejb.AbstractEntityManagerImpl.flush(AbstractEntityManagerImpl.java:297)
... 62 more
Caused by: java.lang.IllegalArgumentException: object is not an instance of declaring class
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:597)
at org.hibernate.property.BasicPropertyAccessor$BasicGetter.get(BasicPropertyAccessor.java:145)
... 85 more
|#]
Code:




Name and version of the database you are using:MySQL 5.0

The generated SQL (show_sql=true): No SQL shown

Debug level Hibernate log excerpt:
Code:
[#|2007-11-23T14:14:53.485+0200|INFO|sun-appserver9.1|javax.enterprise.system.st
ream.out|_ThreadID=16;_ThreadName=httpSSLWorkerThread-8080-0;|
- IllegalArgumentException in class: fi.tdc.cpi.mail.pojo.DomainName, getter met
hod of property: description
|#]



Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 26, 2007 3:37 am 
Newbie

Joined: Tue Apr 04, 2006 6:58 am
Posts: 4
Location: Tampere,Finland
...and this is the bit where I say "oops, my bad". Here is what was wrong: In the Mbox class I had annotated that

@OneToMany(cascade={CascadeType.ALL}, targetEntity=DomainName.class, mappedBy="domain")

It should have been

@OneToMany(cascade={CascadeType.ALL}, targetEntity=MboxName.class, mappedBy="mbox")

So, if ANYONE has this problem, *PLEASE* be sure to triple check your annotations/mappings, as the problem is most likely there. Of course, one could ask quite kindly if the developers would be interested into adding a small sanity check here, or improve the error handling to indicate the problem better.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.