-->
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: Casting Problem beim Iterieren
PostPosted: Fri Jun 29, 2007 2:52 pm 
Newbie

Joined: Wed Apr 25, 2007 4:02 pm
Posts: 7
Hibernate version: 3.2.3 SP1


Hallo miteinander,

ich habe ein Problem mit einem NamedQuery. Und zwar läßt sich das Ergebnis beim Iterieren nicht casten.

Der NamedQuery:

Code:
@NamedQuery(name="allePersonenZuEinemMandanten",
                        query="SELECT p.id, p.name FROM Person p WHERE p.mandant.id = :mid")



Der Aufruf:

Code:
Session hibernateSession = HibernateKonfiguration.getSessionFactory().getCurrentSession();
      Query hsql = hibernateSession.getNamedQuery("allePersonenZuEinemMandanten");
      hsql.setParameter("mid", new Integer(mandantenID));

for(Iterator it = hsql.iterate(); it.hasNext();) {
         Person einePerson = (Person) it.next();
         tmpPerson.add(einePerson);
      }


Ausschnit aus dem Stacktrace:

Code:
  [java] Exception in thread "main" javax.ejb.EJBException: java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to persistence.Person; nested exception is: java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to persistence.Person
     [java] java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to persistence.Person
     [java] at sessionbeans.PersonenVerwaltungBean.allePersonenZuEinemMandanten(PersonenVerwaltungBean.java:80)
     [java] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
     [java] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
     [java] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
     [java] at java.lang.reflect.Method.invoke(Method.java:597)
     [java] at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:112)
     [java] at org.jboss.ejb3.interceptor.InvocationContextImpl.proceed(InvocationContextImpl.java:166)
     [java] at org.jboss.ejb3.interceptor.EJB3InterceptorsInterceptor.invoke(EJB3InterceptorsInterceptor.java:63)
     [java] at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
     [java] at org.jboss.ejb3.entity.TransactionScopedEntityManagerInterceptor.invoke(TransactionScopedEntityManagerInterceptor.java:54)
     [java] at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
     [java] at org.jboss.ejb3.AllowedOperationsInterceptor.invoke(AllowedOperationsInterceptor.java:47)
     [java] at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
     [java] at org.jboss.aspects.tx.TxPolicy.invokeInOurTx(TxPolicy.java:79)
     [java] at org.jboss.aspects.tx.TxInterceptor$Required.invoke(TxInterceptor.java:191)
     [java] at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
     [java] at org.jboss.aspects.tx.TxPropagationInterceptor.invoke(TxPropagationInterceptor.java:76)
     [java] at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
     [java] at org.jboss.ejb3.stateless.StatelessInstanceInterceptor.invoke(StatelessInstanceInterceptor.java:62)
     [java] at org.jboss.aop.joinpoint.MethodInvocation.invokeNext


Ich hoffe mir kann das einer erklären. Vielen Dank

Role


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 02, 2007 3:20 am 
Regular
Regular

Joined: Thu Jan 27, 2005 8:58 am
Posts: 80
Das kann ja auch nicht funktionieren. Du fragst doch nur nach 2 Attributen und Hibernate liefert Dir auch nur 2 Werte in Form eines Arrays. Wenn Du direkt die Person haben willst musst Du die Abfrage in "FROM Person p WHERE p.mandant.id = :mid" ändern.

_________________
Weise ist nicht, wer viele Erfahrungen macht, sondern wer aus wenigen lernt, viele nicht machen zu müssen. (Karlheinz Deschner)


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.