-->
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.  [ 6 posts ] 
Author Message
 Post subject: Class Cast Problem
PostPosted: Thu Aug 30, 2007 2:55 am 
Newbie

Joined: Wed Mar 07, 2007 12:43 pm
Posts: 10
Hallo,

ich wollte die Query:

Code:
@NamedQuery(name = "Faksimile by seiteid", query = "from Faksimile where seiteid=:seiteid")


die so verwendet wird (und funktioniert):

Code:
Faksimile faksimile = (Faksimile) hiberSession.getNamedQuery("Faksimile by seiteid").setLong("seiteid", seite.getId()).list().get(0);


dahingehend abändern, daß nur bestimmte Felder geholt werden (da ich zu dem Zeitpunkt ein Blob-Feld nicht brauche).

Mein Versuch war:

Code:
@NamedQuery(name = "Faksimile by seiteid", query = "select f.id, f.timestamp from Faksimile f where f.seiteid=:seiteid")


Das führt aber an der gleichen Stelle zu der Exception:

Code:
java.lang.ClassCastException: [Ljava.lang.Object;
   at de.retrobib.utils.Migrator.migrateBilder(Migrator.java:542)
   at de.retrobib.actions.secure.ImportAction.executeAction(ImportAction.java:92)
   at de.retrobib.actions.RetrobibAction.execute(RetrobibAction.java:72)
   at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:431)
   at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:236)
   at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196)
   at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:432)
   at javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
   at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
   at de.retrobib.filter.SecurityFilter.doFilter(SecurityFilter.java:93)
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
   at org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:368)
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
   at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
   at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
   at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
   at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
   at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
   at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
   at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:869)
   at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:664)
   at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
   at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80)
   at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
   at java.lang.Thread.run(Thread.java:613)


Hat jemand einen Tipp, warum?

Grüße, Christian


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 30, 2007 10:44 am 
Newbie

Joined: Thu Aug 30, 2007 10:41 am
Posts: 5
wie schaut denn deine entity klasse aus?


Top
 Profile  
 
 Post subject: Die Entity-Klasse...
PostPosted: Fri Aug 31, 2007 6:00 am 
Newbie

Joined: Wed Mar 07, 2007 12:43 pm
Posts: 10
... sieht so aus:

Im Wesentlichen geht es mir darum, in verschiedenen Querys nicht alle Felder zu holen, ohne diesen "Byte-Code"-Trick zu implementieren.

Code:
/*
* Faksimile.java
*
* Created on 13. August 2007, 09:19
*
*/

package de.retrobib.dbmodel;

import java.io.Serializable;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.Lob;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import org.hibernate.annotations.ForeignKey;
import org.hibernate.annotations.Index;
import org.hibernate.annotations.NamedQueries;
import org.hibernate.annotations.NamedQuery;

/**
* Entity class Faksimile
*
* @author caschoff
* @version 1.0
*
*/
@Entity
@Table(name = "faksimile")
@NamedQueries( {
    @NamedQuery(name = "Faksimile.count", query = "select count(id) from Faksimile where deleted=false"),
    @NamedQuery(name = "Faksimile.count by seiteid", query = "select count(id) from Faksimile where seiteid=:seiteid and deleted=false"),
    @NamedQuery(name = "Faksimile by seiteid", query = "from Faksimile where seiteid=:seiteid")
} )
public class Faksimile implements Serializable {
   
    @Id
    @GeneratedValue
    @Column(name = "id", nullable = false)
    @Index(name = "i_faksimile_id")
    private Long id;
   
   
    @Column(name = "oldid", nullable = true)
    @Index(name = "i_faksimile_oldid")
    private Long oldid;
   
    @Column(name = "timestamp", nullable = false)
    @Index(name = "i_faksimile_timestamp")
    private Long timestamp;
   
    @Column(name = "deleted", nullable = false)
    @Index(name = "i_faksimile_deleted")
    private boolean deleted;
   
    @Column(name = "hash", nullable = true, length = 32)
    @Index(name = "i_faksimile_hash")
    private String hash;
   
    @Lob
    @Column(name = "scan", nullable = true)
    private byte[] scan;
   
    @Column(name = "mimetype", nullable = false, length = 256)
    @Index(name = "i_faksimile_mimetype")
    private String mimetype;
   
    @JoinColumn(name = "accountid", referencedColumnName = "id")
    @ManyToOne
    @ForeignKey(name = "fk_faksimile_accountid")
    @Index(name = "i_faksimile_accountid")
    private Account accountid;
   
    @JoinColumn(name = "seiteid", referencedColumnName = "id")
    @ManyToOne
    @ForeignKey(name = "fk_faksimile_seiteid")
    @Index(name = "i_faksimile_seiteid")
    private Seite seiteid;
   
    /** Creates a new instance of Faksimile */
    public Faksimile() {
    }
   
    /**
     * Creates a new instance of Faksimile with the specified values.
     * @param id the id of the Faksimile
     */
    public Faksimile(Long id) {
        this.id = id;
    }
   
    /**
     * Gets the id of this Faksimile.
     * @return the id
     */
    public Long getId() {
        return this.id;
    }
   
    /**
     * Sets the id of this Faksimile to the specified value.
     * @param id the new id
     */
    public void setId(Long id) {
        this.id = id;
    }
   
    /**
     * Gets the oldid of this Werk.
     * @return the oldid
     */
    public Long getOldid() {
        return this.oldid;
    }
   
    /**
     * Sets the oldid of this Werk to the specified value.
     * @param oldid the new oldid
     */
    public void setOldid(Long oldid) {
        this.oldid = oldid;
    }
   
    /**
     * Gets the timestamp of this Faksimile.
     * @return the timestamp
     */
    public Long getTimestamp() {
        return this.timestamp;
    }
   
    /**
     * Sets the timestamp of this Faksimile to the specified value.
     * @param timestamp the new timestamp
     */
    public void setTimestamp(Long timestamp) {
        this.timestamp = timestamp;
    }
   
    /**
     * Gets the deleted of this Faksimile.
     * @return the deleted
     */
    public boolean getDeleted() {
        return this.deleted;
    }
   
    /**
     * Sets the deleted of this Faksimile to the specified value.
     * @param deleted the new deleted
     */
    public void setDeleted(boolean deleted) {
        this.deleted = deleted;
    }
   
    /**
     * Gets the hash of this Faksimile.
     * @return the hash
     */
    public String getHash() {
        return this.hash;
    }
   
    /**
     * Sets the hash of this Faksimile to the specified value.
     * @param hash the new hash
     */
    public void setHash(String hash) {
        this.hash = hash;
    }
   
    /**
     * Gets the scan of this Faksimile.
     * @return the scan
     */
    public byte[] getScan() {
        return this.scan;
    }
   
    /**
     * Sets the scan of this Faksimile to the specified value.
     * @param scan the new scan
     */
    public void setScan(byte[] scan) {
        this.scan = scan;
    }
   
    /**
     * Gets the mimetype of this Faksimile.
     * @return the mimetype
     */
    public String getMimetype() {
        return this.mimetype;
    }
   
    /**
     * Sets the mimetype of this Faksimile to the specified value.
     * @param mimetype the new mimetype
     */
    public void setMimetype(String mimetype) {
        this.mimetype = mimetype;
    }
   
    /**
     * Gets the accountid of this Faksimile.
     * @return the accountid
     */
    public Account getAccountid() {
        return this.accountid;
    }
   
    /**
     * Sets the accountid of this Faksimile to the specified value.
     * @param accountid the new accountid
     */
    public void setAccountid(Account accountid) {
        this.accountid = accountid;
    }
   
    /**
     * Gets the seiteid of this Faksimile.
     * @return the seiteid
     */
    public Seite getSeiteid() {
        return this.seiteid;
    }
   
    /**
     * Sets the seiteid of this Faksimile to the specified value.
     * @param seiteid the new seiteid
     */
    public void setSeiteid(Seite seiteid) {
        this.seiteid = seiteid;
    }
   
    /**
     * Returns a hash code value for the object.  This implementation computes
     * a hash code value based on the id fields in this object.
     * @return a hash code value for this object.
     */
    @Override
    public int hashCode() {
        int hash = 0;
        hash += (this.id != null ? this.id.hashCode() : 0);
        return hash;
    }
   
    /**
     * Determines whether another object is equal to this Faksimile.  The result is
     * <code>true</code> if and only if the argument is not null and is a Faksimile object that
     * has the same id field values as this object.
     * @param object the reference object with which to compare
     * @return <code>true</code> if this object is the same as the argument;
     * <code>false</code> otherwise.
     */
    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Faksimile)) {
            return false;
        }
        Faksimile other = (Faksimile)object;
        if (this.id != other.id && (this.id == null || !this.id.equals(other.id))) return false;
        return true;
    }
   
    /**
     * Returns a string representation of the object.  This implementation constructs
     * that representation based on the id fields.
     * @return a string representation of the object.
     */
    @Override
    public String toString() {
        return "de.retrobib.dbmodel.Faksimile[id=" + id +
                "; oldid = " + oldid +
                "; timestamp = " + timestamp +
                "; deleted = " + deleted +
                "; hash = " + hash +
                "; scan(size) = " + scan.length +
                "; mimetype = " + mimetype +
                "]";
    }
   
}


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 31, 2007 7:47 am 
Newbie

Joined: Thu Aug 30, 2007 10:41 am
Posts: 5
Musst schon einen Long hernehmen dann...

Code:
Long longValue = (Faksimile) hiberSession.getNamedQuery("Faksimile by seiteid").setLong("seiteid", seite.getId()).list().get(0);


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 31, 2007 7:48 am 
Newbie

Joined: Thu Aug 30, 2007 10:41 am
Posts: 5
Musst schon einen Long hernehmen dann...

Code:
Long longValue =  (Long) hiberSession.getNamedQuery("Faksimile by seiteid").setLong("seiteid", seite.getId()).list().get(0);


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 31, 2007 8:47 am 
Regular
Regular

Joined: Thu Oct 19, 2006 12:07 pm
Posts: 75
Eigentlich sollte es heissen :
Code:
Object [] resultat =  (Object[]) hiberSession.getNamedQuery("Faksimile by seiteid").setLong("seiteid", seite.getId()).list().get(0);

Long id = (Long)resultat[0];
Long timestamp = (Long)resultat[1];


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 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.