-->
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.  [ 8 posts ] 
Author Message
 Post subject: ClassCastException...
PostPosted: Mon Feb 23, 2004 10:16 am 
Regular
Regular

Joined: Mon Jan 19, 2004 10:39 pm
Posts: 84
Location: Nottingham, England
Hi,
I want to do the following but am getting the above mentioned error. What am I doing wrong?:

calling page:
byte[] photo = new byte[10];
Artist artist = Artist.getArtistImage(artistID,imageNum);
photo = artist.getArtistPhoto1()

class: (snippet)
public byte[] getArtistPhoto1() {
return ArtistPhoto1;
}
public void setArtistPhoto1(byte[] newArtistPhoto1) {
this.ArtistPhoto1 = newArtistPhoto1;
}

......

public static Artist getArtistImage (int artist_id, int imageNum)
{
Artist artist = null;
Transaction transaction = null;
HibernateUtil Util = null;
Session session = null;
String photoNum = null;
String artistID = String.valueOf(artist_id);
StringBuffer queryBuild = new StringBuffer();

try {
Util = new HibernateUtil();
session = Util.currentSession();

transaction = session.beginTransaction();

switch(imageNum){
case 1: photoNum = "artist.ArtistPhoto1"; break;
case 2: photoNum = "artist.ArtistPhoto2"; break;
case 3: photoNum = "artist.ArtistPhoto3"; break;
}

//Get Artist image
queryBuild.append("Select ")
.append(photoNum).append(" ")
.append("from test.Artist as artist where artist.ID=:artist_id");

Query query = session.createQuery(queryBuild.toString())
.setParameter("artist_id",artistID);
artist = (Artist)query.uniqueResult();

transaction.commit();
Util.closeSession();

} catch (HibernateException e) {
throw new RuntimeException("Exception in Hibernate:: " + e.getMessage(), e);
}

return artist;
}


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 23, 2004 10:18 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
This is not a quiz show. First, your code is not the code that you have compiled. Second, you haven't read the BIG RED WARNING before you posted. Third, half of the code you have shown is probably unrelated to the problem. Isolate it, follow the instructsions, post.

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
 Post subject: Requested info....
PostPosted: Mon Feb 23, 2004 12:21 pm 
Regular
Regular

Joined: Mon Jan 19, 2004 10:39 pm
Posts: 84
Location: Nottingham, England
Christian,
the information I provided earlier was a snippet of the overall code I am running, but here is the complete code break requested by big red!.

1. Hibernate Version: 2.1.1
2. Map: Artist.hbm.xml

<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">

<hibernate-mapping package="test">
<class name="Artist" table="artisttbl">
<id name="ID" column="artist_id" type="integer" unsaved-value="0">
<generator class="sequence">
<param name="sequence">artist_seq_id</param>
</generator>
</id>
<property name="ArtistName" column="artist_name" type="string" not-null="true"/>
<property name="ArtistInfo" column="artist_info" type="string"/>
<property name="ArtistPhoto1" column="artist_photo1" type="binary"/>
<property name="ArtistPhoto2" column="artist_photo2" type="binary"/>
<property name="ArtistPhoto3" column="artist_photo3" type="binary"/>
</class>
</hibernate-mapping>

3. Java Code (between openSession() and session.close()):

transaction = session.beginTransaction();

switch(imageNum){
case 1: photoNum = "artist.ArtistPhoto1"; break;
case 2: photoNum = "artist.ArtistPhoto2"; break;
case 3: photoNum = "artist.ArtistPhoto3"; break;
}

//Get Artist image
queryBuild.append("Select ")
.append(photoNum).append(" ")
.append("from test.Artist as artist where artist.ID=:artist_id");

Query query = session.createQuery(queryBuild.toString())
.setParameter("artist_id",artistID);
artist = (Artist)query.uniqueResult();

transaction.commit();

4. Stack trace:

16:06:46,655 INFO Environment:432 - Hibernate 2.1.1
16:06:46,661 INFO Environment:461 - hibernate.properties not found
16:06:46,667 INFO Environment:481 - using CGLIB reflection optimizer
16:06:46,678 INFO Configuration:843 - configuring from resource: /hibernate.cfg.xml
16:06:46,680 INFO Configuration:815 - Configuration resource: /hibernate.cfg.xml
16:06:46,805 DEBUG DTDEntityResolver:20 - trying to locate http://hibernate.sourceforge.net/hibern ... on-2.0.dtd in classpath under net/sf/hibernate/
16:06:46,825 DEBUG DTDEntityResolver:29 - found http://hibernate.sourceforge.net/hibern ... on-2.0.dtd in classpath
16:06:46,912 DEBUG Configuration:801 - connection.driver_class=org.postgresql.Driver
16:06:46,915 DEBUG Configuration:801 - connection.url=jdbc:postgresql://localhost:5432/beyarecords
16:06:46,916 DEBUG Configuration:801 - connection.username=postgres
16:06:46,918 DEBUG Configuration:801 - connection.password=postgres
16:06:46,920 DEBUG Configuration:801 - connection.pool_size=0
16:06:46,921 DEBUG Configuration:801 - jdbc.batch_size=5
16:06:46,923 DEBUG Configuration:801 - jdbc.use_scrollable_resultset=true
16:06:46,925 DEBUG Configuration:801 - hibernate.statement_cache.size=25
16:06:46,931 DEBUG Configuration:801 - hibernate.jdbc.use_streams_for_binary=true
16:06:46,933 DEBUG Configuration:801 - show_sql=true
16:06:46,934 DEBUG Configuration:801 - transaction.factory_class=net.sf.hibernate.transaction.JDBCTransactionFactory
16:06:46,936 DEBUG Configuration:801 - hibernate.cache.provider_class=net.sf.hibernate.cache.HashtableCacheProvider
16:06:46,938 DEBUG Configuration:801 - use_outer_join=true
16:06:46,939 DEBUG Configuration:801 - dialect=net.sf.hibernate.dialect.PostgreSQLDialect
16:06:46,941 DEBUG Configuration:801 - hibernate.c3p0.max_size=2
16:06:46,943 DEBUG Configuration:801 - hibernate.c3p0.min_size=1
16:06:46,944 DEBUG Configuration:801 - hibernate.c3p0.timeout=5000
16:06:46,946 DEBUG Configuration:801 - hibernate.c3p0.max_statements=50
16:06:46,950 DEBUG Configuration:952 - null<-org.dom4j.tree.DefaultAttribute@3e062c [Attribute: name resource value "test/User.hbm.xml"]
16:06:46,952 INFO Configuration:300 - Mapping resource: test/User.hbm.xml
16:06:46,962 DEBUG DTDEntityResolver:20 - trying to locate http://hibernate.sourceforge.net/hibern ... ng-2.0.dtd in classpath under net/sf/hibernate/
16:06:46,971 DEBUG DTDEntityResolver:29 - found http://hibernate.sourceforge.net/hibern ... ng-2.0.dtd in classpath
16:06:47,165 INFO Binder:225 - Mapping class: test.User -> usertbl
16:06:47,337 DEBUG Binder:449 - Mapped property: ID -> user_id, type: integer
16:06:47,380 DEBUG Binder:449 - Mapped property: FirstName -> first_name, type: string
16:06:47,383 DEBUG Binder:449 - Mapped property: LastName -> last_name, type: string
16:06:47,385 DEBUG Binder:449 - Mapped property: Address1 -> address1, type: string
16:06:47,386 DEBUG Binder:449 - Mapped property: Address2 -> address2, type: string
16:06:47,388 DEBUG Binder:449 - Mapped property: Address3 -> address3, type: string
16:06:47,391 DEBUG Binder:449 - Mapped property: PostCode -> postcode, type: string
16:06:47,393 DEBUG Binder:449 - Mapped property: Country -> country, type: string
16:06:47,395 DEBUG Binder:449 - Mapped property: Email -> email, type: string
16:06:47,405 DEBUG Binder:449 - Mapped property: HomeTel -> home_telephone, type: string
16:06:47,407 DEBUG Binder:449 - Mapped property: HomeMob -> mobile_telephone, type: string
16:06:47,410 DEBUG Binder:449 - Mapped property: DateJoined -> date_joined, type: timestamp
16:06:47,415 DEBUG Binder:449 - Mapped property: UserName -> username, type: string
16:06:47,418 DEBUG Binder:449 - Mapped property: UserPassword -> userpassword, type: string
16:06:47,421 INFO Binder:534 - Mapping collection: test.User.ArtistChoice -> choicetbl
16:06:47,442 DEBUG Binder:449 - Mapped property: ArtistChoice, type: java.util.Set
16:06:47,444 DEBUG Configuration:952 - null<-org.dom4j.tree.DefaultAttribute@3214e [Attribute: name resource value "test/Artist.hbm.xml"]
16:06:47,446 INFO Configuration:300 - Mapping resource: test/Artist.hbm.xml
16:06:47,458 DEBUG DTDEntityResolver:20 - trying to locate http://hibernate.sourceforge.net/hibern ... ng-2.0.dtd in classpath under net/sf/hibernate/
16:06:47,460 DEBUG DTDEntityResolver:29 - found http://hibernate.sourceforge.net/hibern ... ng-2.0.dtd in classpath
16:06:47,482 INFO Binder:225 - Mapping class: test.Artist -> artisttbl
16:06:47,484 DEBUG Binder:449 - Mapped property: ID -> artist_id, type: integer
16:06:47,486 DEBUG Binder:449 - Mapped property: ArtistName -> artist_name, type: string
16:06:47,488 DEBUG Binder:449 - Mapped property: ArtistInfo -> artist_info, type: string
16:06:47,490 DEBUG Binder:449 - Mapped property: ArtistPhoto1 -> artist_photo1, type: binary
16:06:47,492 DEBUG Binder:449 - Mapped property: ArtistPhoto2 -> artist_photo2, type: binary
16:06:47,494 DEBUG Binder:449 - Mapped property: ArtistPhoto3 -> artist_photo3, type: binary
16:06:47,496 DEBUG Configuration:952 - null<-org.dom4j.tree.DefaultAttribute@cc603d [Attribute: name resource value "test/Artist_TourDates.hbm.xml"]
16:06:47,498 INFO Configuration:300 - Mapping resource: test/Artist_TourDates.hbm.xml
16:06:47,516 DEBUG DTDEntityResolver:20 - trying to locate http://hibernate.sourceforge.net/hibern ... ng-2.0.dtd in classpath under net/sf/hibernate/
16:06:47,518 DEBUG DTDEntityResolver:29 - found http://hibernate.sourceforge.net/hibern ... ng-2.0.dtd in classpath
16:06:47,556 INFO Binder:225 - Mapping class: test.Artist_TourDates -> artist_tourdatestbl
16:06:47,558 DEBUG Binder:449 - Mapped property: ID -> artist_id, type: integer
16:06:47,560 DEBUG Binder:449 - Mapped property: Venue -> venue, type: string
16:06:47,562 DEBUG Binder:449 - Mapped property: Location -> location, type: string
16:06:47,564 DEBUG Binder:449 - Mapped property: TourDate -> tourdate, type: string
16:06:47,566 DEBUG Configuration:952 - null<-org.dom4j.tree.DefaultAttribute@f3e2f5 [Attribute: name resource value "test/Stock.hbm.xml"]
16:06:47,568 INFO Configuration:300 - Mapping resource: test/Stock.hbm.xml
16:06:47,576 DEBUG DTDEntityResolver:20 - trying to locate http://hibernate.sourceforge.net/hibern ... ng-2.0.dtd in classpath under net/sf/hibernate/
16:06:47,584 DEBUG DTDEntityResolver:29 - found http://hibernate.sourceforge.net/hibern ... ng-2.0.dtd in classpath
16:06:47,605 INFO Binder:225 - Mapping class: test.Stock -> stocktbl
16:06:47,607 DEBUG Binder:449 - Mapped property: ID -> item_code, type: string
16:06:47,609 DEBUG Binder:449 - Mapped property: ArtistID -> artist_id, type: integer
16:06:47,611 DEBUG Binder:449 - Mapped property: ItemType -> item_type, type: character
16:06:47,613 DEBUG Binder:449 - Mapped property: ItemTitle -> item_title, type: string
16:06:47,616 DEBUG Binder:449 - Mapped property: ItemDemo -> item_demo_location, type: string
16:06:47,618 DEBUG Binder:449 - Mapped property: ItemFinal -> item_final_location, type: string
16:06:47,620 DEBUG Binder:449 - Mapped property: ItemPhoto -> item_photo_location, type: string
16:06:47,622 DEBUG Binder:449 - Mapped property: UnitCost -> unit_cost, type: float
16:06:47,624 DEBUG Configuration:952 - null<-org.dom4j.tree.DefaultAttribute@454bd [Attribute: name resource value "test/Downloads.hbm.xml"]
16:06:47,626 INFO Configuration:300 - Mapping resource: test/Downloads.hbm.xml
16:06:47,645 DEBUG DTDEntityResolver:20 - trying to locate http://hibernate.sourceforge.net/hibern ... ng-2.0.dtd in classpath under net/sf/hibernate/
16:06:47,647 DEBUG DTDEntityResolver:29 - found http://hibernate.sourceforge.net/hibern ... ng-2.0.dtd in classpath
16:06:47,662 INFO Binder:225 - Mapping class: test.Downloads -> downloadstbl
16:06:47,664 DEBUG Binder:449 - Mapped property: ID -> user_id, type: integer
16:06:47,666 DEBUG Binder:449 - Mapped property: ArtistID -> artist_id, type: integer
16:06:47,668 DEBUG Binder:449 - Mapped property: SessionID -> session_id, type: string
16:06:47,670 DEBUG Binder:449 - Mapped property: Location -> item_final_location, type: string
16:06:47,672 DEBUG Binder:449 - Mapped property: ItemCode -> item_code, type: string
16:06:47,673 DEBUG Binder:449 - Mapped property: Accepted -> accepted, type: integer
16:06:47,675 DEBUG Configuration:952 - null<-org.dom4j.tree.DefaultAttribute@5b8d33 [Attribute: name resource value "test/Demos.hbm.xml"]
16:06:47,685 INFO Configuration:300 - Mapping resource: test/Demos.hbm.xml
16:06:47,693 DEBUG DTDEntityResolver:20 - trying to locate http://hibernate.sourceforge.net/hibern ... ng-2.0.dtd in classpath under net/sf/hibernate/
16:06:47,695 DEBUG DTDEntityResolver:29 - found http://hibernate.sourceforge.net/hibern ... ng-2.0.dtd in classpath
16:06:47,713 INFO Binder:225 - Mapping class: test.Demos -> new_artist_demostbl
16:06:47,715 DEBUG Binder:449 - Mapped property: ID -> id_key, type: integer
16:06:47,718 DEBUG Binder:449 - Mapped property: ArtistName -> artist_name, type: string
16:06:47,720 DEBUG Binder:449 - Mapped property: Email -> email, type: string
16:06:47,722 DEBUG Binder:449 - Mapped property: TrackName -> track_name, type: string
16:06:47,724 DEBUG Binder:449 - Mapped property: DateSubmitted -> date_submitted, type: timestamp
16:06:47,726 DEBUG Binder:449 - Mapped property: DemoLocation -> demo_location, type: string
16:06:47,728 DEBUG Configuration:952 - null<-org.dom4j.tree.DefaultAttribute@9c7cdb [Attribute: name resource value "test/Accounts.hbm.xml"]
16:06:47,733 INFO Configuration:300 - Mapping resource: test/Accounts.hbm.xml
16:06:47,741 DEBUG DTDEntityResolver:20 - trying to locate http://hibernate.sourceforge.net/hibern ... ng-2.0.dtd in classpath under net/sf/hibernate/
16:06:47,743 DEBUG DTDEntityResolver:29 - found http://hibernate.sourceforge.net/hibern ... ng-2.0.dtd in classpath
16:06:47,761 INFO Binder:225 - Mapping class: test.Accounts -> user_accountstbl
16:06:47,763 DEBUG Binder:449 - Mapped property: ID -> receipt_no, type: string
16:06:47,765 DEBUG Binder:449 - Mapped property: UserID -> user_id, type: integer
16:06:47,767 DEBUG Binder:449 - Mapped property: ArtistID -> artist_id, type: integer
16:06:47,769 DEBUG Binder:449 - Mapped property: ItemType -> item_type, type: character
16:06:47,771 DEBUG Binder:449 - Mapped property: ItemQuantity -> item_quantity, type: integer
16:06:47,773 DEBUG Binder:449 - Mapped property: PurchaseDate -> purchase_date, type: timestamp
16:06:47,779 DEBUG Binder:449 - Mapped property: ItemCode -> item_code, type: string
16:06:47,781 DEBUG Binder:449 - Mapped property: Email -> email, type: string
16:06:47,783 DEBUG Binder:449 - Mapped property: UnitCost -> unit_cost, type: float
16:06:47,785 DEBUG Binder:449 - Mapped property: TotalCost -> total_cost, type: float
16:06:47,787 DEBUG Configuration:952 - null<-org.dom4j.tree.DefaultAttribute@d33f05 [Attribute: name resource value "test/ShoppingCart.hbm.xml"]
16:06:47,789 INFO Configuration:300 - Mapping resource: test/ShoppingCart.hbm.xml
16:06:47,796 DEBUG DTDEntityResolver:20 - trying to locate http://hibernate.sourceforge.net/hibern ... ng-2.0.dtd in classpath under net/sf/hibernate/
16:06:47,798 DEBUG DTDEntityResolver:29 - found http://hibernate.sourceforge.net/hibern ... ng-2.0.dtd in classpath
16:06:47,814 INFO Binder:225 - Mapping class: test.ShoppingCart -> shopping_carttbl
16:06:47,817 DEBUG Binder:449 - Mapped property: ID -> receipt_no, type: string
16:06:47,819 DEBUG Binder:449 - Mapped property: UserID -> user_id, type: integer
16:06:47,827 DEBUG Binder:449 - Mapped property: ArtistID -> artist_id, type: integer
16:06:47,829 DEBUG Binder:449 - Mapped property: ItemType -> item_type, type: character
16:06:47,831 DEBUG Binder:449 - Mapped property: ItemQuantity -> item_quantity, type: integer
16:06:47,832 DEBUG Binder:449 - Mapped property: PurchaseDate -> purchase_date, type: timestamp
16:06:47,834 DEBUG Binder:449 - Mapped property: UnitCost -> unit_cost, type: float
16:06:47,836 DEBUG Binder:449 - Mapped property: ItemCode -> item_code, type: string
16:06:47,838 DEBUG Binder:449 - Mapped property: TotalCost -> total_cost, type: float
16:06:47,840 DEBUG Binder:449 - Mapped property: Accepted -> card_accepted, type: character
16:06:47,842 INFO Configuration:998 - Configured SessionFactory: null
16:06:47,844 DEBUG Configuration:999 - properties: {show_sql=true, java.vendor=Apple Computer, Inc., catalina.base=/library/tomcat, hibernate.connection.url=jdbc:postgresql://localhost:5432/beyarecords, catalina.useNaming=true, os.name=Mac OS X, sun.boot.class.path=/library/tomcat/common/endorsed/xalan-2.5.2.jar:/library/tomcat/common/endorsed/xercesImpl.jar:/library/tomcat/common/endorsed/xmlParserAPIs.jar:/System/Library/Frameworks/JavaVM.framework/Versions/1.4.2/Classes/classes.jar:/System/Library/Frameworks/JavaVM.framework/Versions/1.4.2/Classes/ui.jar:/System/Library/Frameworks/JavaVM.framework/Versions/1.4.2/Classes/laf.jar:/System/Library/Frameworks/JavaVM.framework/Versions/1.4.2/Classes/sunrsasign.jar:/System/Library/Frameworks/JavaVM.framework/Versions/1.4.2/Classes/jsse.jar:/System/Library/Frameworks/JavaVM.framework/Versions/1.4.2/Classes/jce.jar:/System/Library/Frameworks/JavaVM.framework/Versions/1.4.2/Classes/charsets.jar, hibernate.c3p0.max_size=2, sun.java2d.fontpath=, java.vm.specification.vendor=Sun Microsystems Inc., java.runtime.version=1.4.2_03-117.1, hibernate.c3p0.min_size=1, hibernate.cache.provider_class=net.sf.hibernate.cache.HashtableCacheProvider, user.name=uzomaduj, shared.loader=${catalina.base}/shared/classes,${catalina.base}/shared/lib/*.jar, connection.driver_class=org.postgresql.Driver, hibernate.c3p0.timeout=5000, user.language=en, java.naming.factory.initial=org.apache.naming.java.javaURLContextFactory, sun.boot.library.path=/System/Library/Frameworks/JavaVM.framework/Versions/1.4.2/Libraries, hibernate.jdbc.use_scrollable_resultset=true, dialect=net.sf.hibernate.dialect.PostgreSQLDialect, jdbc.use_scrollable_resultset=true, java.version=1.4.2_03, user.timezone=Europe/London, jdbc.batch_size=5, sun.arch.data.model=32, hibernate.use_outer_join=true, java.endorsed.dirs=/library/tomcat/common/endorsed, sun.cpu.isalist=, file.encoding.pkg=sun.io, package.access=sun.,org.apache.catalina.,org.apache.coyote.,org.apache.tomcat.,org.apache.jasper.,sun.beans., file.separator=/, java.specification.name=Java Platform API Specification, log4j.debug=true, hibernate.cglib.use_reflection_optimizer=true, java.class.version=48.0, user.country=US, connection.url=jdbc:postgresql://localhost:5432/beyarecords, java.home=/System/Library/Frameworks/JavaVM.framework/Versions/1.4.2/Home, org.xmldb.common.xml.queries.XPathQueryFactory=org.apache.xindice.core.xupdate.XPathQueryFactoryImpl, java.vm.info=mixed mode, os.version=10.3.2, transaction.factory_class=net.sf.hibernate.transaction.JDBCTransactionFactory, hibernate.transaction.factory_class=net.sf.hibernate.transaction.JDBCTransactionFactory, path.separator=:, connection.password=postgres, java.vm.version=1.4.2-34, hibernate.connection.password=postgres, java.util.prefs.PreferencesFactory=java.util.prefs.MacOSXPreferencesFactory, hibernate.jdbc.batch_size=5, java.awt.printerjob=apple.awt.CPrinterJob, sun.io.unicode.encoding=UnicodeBig, awt.toolkit=apple.awt.CToolkit, hibernate.connection.username=postgres, package.definition=sun.,java.,org.apache.catalina.,org.apache.coyote.,org.apache.tomcat.,org.apache.jasper., java.naming.factory.url.pkgs=org.apache.naming, user.home=/Users/uzomaduj, java.specification.vendor=Sun Microsystems Inc., hibernate.statement_cache.size=25, org.xml.sax.driver=org.apache.xerces.parsers.SAXParser, java.library.path=.:/Library/Java/Extensions:/System/Library/Java/Extensions:/usr/lib/java, java.vendor.url=http://apple.com/, hibernate.connection.driver_class=org.postgresql.Driver, connection.username=postgres, java.vm.vendor="Apple Computer, Inc.", gopherProxySet=false, hibernate.dialect=net.sf.hibernate.dialect.PostgreSQLDialect, hibernate.jdbc.use_streams_for_binary=true, common.loader=${catalina.home}/common/classes,${catalina.home}/common/endorsed/*.jar,${catalina.home}/common/lib/*.jar, java.runtime.name=Java(TM) 2 Runtime Environment, Standard Edition, java.class.path=/library/java/home/lib/tools.jar:/library/tomcat/bin/bootstrap.jar:/library/tomcat/bin/commons-logging-api.jar, use_outer_join=true, java.vm.specification.name=Java Virtual Machine Specification, java.vm.specification.version=1.0, catalina.home=/library/tomcat, sun.cpu.endian=big, sun.os.patch.level=unknown, connection.pool_size=0, java.io.tmpdir=/library/tomcat/temp, java.vendor.url.bug=http://developer.apple.com/java/, server.loader=${catalina.home}/server/classes,${catalina.home}/server/lib/*.jar, os.arch=ppc, java.awt.graphicsenv=apple.awt.CGraphicsEnvironment, java.ext.dirs=/Library/Java/Extensions:/System/Library/Java/Extensions:/System/Library/Frameworks/JavaVM.framework/Versions/1.4.2/Home/lib/ext, mrj.version=117.1, user.dir=/Library/Tomcat/bin, line.separator=
, java.vm.name=Java HotSpot(TM) Client VM, file.encoding=MacRoman, java.specification.version=1.4, hibernate.c3p0.max_statements=50, hibernate.show_sql=true, hibernate.connection.pool_size=0}
16:06:47,847 INFO Configuration:584 - processing one-to-many association mappings
16:06:47,849 DEBUG Binder:1301 - Second pass for collection: test.User.ArtistChoice
16:06:47,870 DEBUG Binder:1316 - Mapped collection key: user_id, element: artist_id, type: test.Artist
16:06:47,872 INFO Configuration:593 - processing one-to-one association property references
16:06:47,874 INFO Configuration:618 - processing foreign key constraints
16:06:47,876 DEBUG Configuration:628 - resolving reference to class: test.Artist
16:06:47,877 DEBUG Configuration:628 - resolving reference to class: test.User
16:06:47,936 INFO Dialect:82 - Using dialect: net.sf.hibernate.dialect.PostgreSQLDialect
16:06:47,939 INFO SettingsFactory:62 - Use outer join fetching: true
16:06:47,953 INFO C3P0ConnectionProvider:48 - C3P0 using driver: org.postgresql.Driver at URL: jdbc:postgresql://localhost:5432/beyarecords
16:06:47,955 INFO C3P0ConnectionProvider:49 - Connection properties: {user=postgres, password=postgres}
16:06:48,059 INFO TransactionFactoryFactory:31 - Transaction strategy: net.sf.hibernate.transaction.JDBCTransactionFactory
16:06:48,070 INFO TransactionManagerLookupFactory:33 - No TransactionManagerLookup configured (in JTA environment, use of process level read-write cache is not recommended)
16:06:48,640 INFO SettingsFactory:89 - Use scrollable result sets: true
16:06:48,642 INFO SettingsFactory:90 - JDBC 2 max batch size: 5
16:06:48,643 INFO SettingsFactory:96 - echoing all SQL to stdout
16:06:48,645 INFO SettingsFactory:99 - Query language substitutions: {}
16:06:48,647 INFO SettingsFactory:110 - cache provider: net.sf.hibernate.cache.HashtableCacheProvider
16:06:48,666 INFO Configuration:1057 - instantiating and configuring caches
16:06:48,899 INFO SessionFactoryImpl:119 - building session factory
16:06:48,902 DEBUG SessionFactoryImpl:125 - instantiating session factory with properties: {show_sql=true, java.vendor=Apple Computer, Inc., catalina.base=/library/tomcat, hibernate.connection.url=jdbc:postgresql://localhost:5432/beyarecords, catalina.useNaming=true, os.name=Mac OS X, sun.boot.class.path=/library/tomcat/common/endorsed/xalan-2.5.2.jar:/library/tomcat/common/endorsed/xercesImpl.jar:/library/tomcat/common/endorsed/xmlParserAPIs.jar:/System/Library/Frameworks/JavaVM.framework/Versions/1.4.2/Classes/classes.jar:/System/Library/Frameworks/JavaVM.framework/Versions/1.4.2/Classes/ui.jar:/System/Library/Frameworks/JavaVM.framework/Versions/1.4.2/Classes/laf.jar:/System/Library/Frameworks/JavaVM.framework/Versions/1.4.2/Classes/sunrsasign.jar:/System/Library/Frameworks/JavaVM.framework/Versions/1.4.2/Classes/jsse.jar:/System/Library/Frameworks/JavaVM.framework/Versions/1.4.2/Classes/jce.jar:/System/Library/Frameworks/JavaVM.framework/Versions/1.4.2/Classes/charsets.jar, hibernate.c3p0.max_size=2, sun.java2d.fontpath=, java.vm.specification.vendor=Sun Microsystems Inc., java.runtime.version=1.4.2_03-117.1, hibernate.c3p0.min_size=1, hibernate.cache.provider_class=net.sf.hibernate.cache.HashtableCacheProvider, user.name=uzomaduj, shared.loader=${catalina.base}/shared/classes,${catalina.base}/shared/lib/*.jar, connection.driver_class=org.postgresql.Driver, hibernate.c3p0.timeout=5000, user.language=en, java.naming.factory.initial=org.apache.naming.java.javaURLContextFactory, sun.boot.library.path=/System/Library/Frameworks/JavaVM.framework/Versions/1.4.2/Libraries, hibernate.jdbc.use_scrollable_resultset=true, dialect=net.sf.hibernate.dialect.PostgreSQLDialect, jdbc.use_scrollable_resultset=true, java.version=1.4.2_03, user.timezone=Europe/London, jdbc.batch_size=5, sun.arch.data.model=32, hibernate.use_outer_join=true, java.endorsed.dirs=/library/tomcat/common/endorsed, sun.cpu.isalist=, file.encoding.pkg=sun.io, package.access=sun.,org.apache.catalina.,org.apache.coyote.,org.apache.tomcat.,org.apache.jasper.,sun.beans., file.separator=/, java.specification.name=Java Platform API Specification, log4j.debug=true, hibernate.cglib.use_reflection_optimizer=true, java.class.version=48.0, user.country=US, connection.url=jdbc:postgresql://localhost:5432/beyarecords, java.home=/System/Library/Frameworks/JavaVM.framework/Versions/1.4.2/Home, org.xmldb.common.xml.queries.XPathQueryFactory=org.apache.xindice.core.xupdate.XPathQueryFactoryImpl, java.vm.info=mixed mode, os.version=10.3.2, transaction.factory_class=net.sf.hibernate.transaction.JDBCTransactionFactory, hibernate.transaction.factory_class=net.sf.hibernate.transaction.JDBCTransactionFactory, path.separator=:, connection.password=postgres, java.vm.version=1.4.2-34, hibernate.connection.password=postgres, java.util.prefs.PreferencesFactory=java.util.prefs.MacOSXPreferencesFactory, hibernate.jdbc.batch_size=5, java.awt.printerjob=apple.awt.CPrinterJob, sun.io.unicode.encoding=UnicodeBig, awt.toolkit=apple.awt.CToolkit, hibernate.connection.username=postgres, package.definition=sun.,java.,org.apache.catalina.,org.apache.coyote.,org.apache.tomcat.,org.apache.jasper., java.naming.factory.url.pkgs=org.apache.naming, user.home=/Users/uzomaduj, java.specification.vendor=Sun Microsystems Inc., hibernate.statement_cache.size=25, org.xml.sax.driver=org.apache.xerces.parsers.SAXParser, java.library.path=.:/Library/Java/Extensions:/System/Library/Java/Extensions:/usr/lib/java, java.vendor.url=http://apple.com/, hibernate.connection.driver_class=org.postgresql.Driver, connection.username=postgres, java.vm.vendor="Apple Computer, Inc.", gopherProxySet=false, hibernate.dialect=net.sf.hibernate.dialect.PostgreSQLDialect, hibernate.jdbc.use_streams_for_binary=true, common.loader=${catalina.home}/common/classes,${catalina.home}/common/endorsed/*.jar,${catalina.home}/common/lib/*.jar, java.runtime.name=Java(TM) 2 Runtime Environment, Standard Edition, java.class.path=/library/java/home/lib/tools.jar:/library/tomcat/bin/bootstrap.jar:/library/tomcat/bin/commons-logging-api.jar, use_outer_join=true, java.vm.specification.name=Java Virtual Machine Specification, java.vm.specification.version=1.0, catalina.home=/library/tomcat, sun.cpu.endian=big, sun.os.patch.level=unknown, connection.pool_size=0, java.io.tmpdir=/library/tomcat/temp, java.vendor.url.bug=http://developer.apple.com/java/, server.loader=${catalina.home}/server/classes,${catalina.home}/server/lib/*.jar, os.arch=ppc, java.awt.graphicsenv=apple.awt.CGraphicsEnvironment, java.ext.dirs=/Library/Java/Extensions:/System/Library/Java/Extensions:/System/Library/Frameworks/JavaVM.framework/Versions/1.4.2/Home/lib/ext, mrj.version=117.1, user.dir=/Library/Tomcat/bin, line.separator=
, java.vm.name=Java HotSpot(TM) Client VM, file.encoding=MacRoman, java.specification.version=1.4, hibernate.c3p0.max_statements=50, hibernate.show_sql=true, hibernate.connection.pool_size=0}
16:06:50,330 DEBUG SessionFactoryObjectFactory:39 - initializing class SessionFactoryObjectFactory
16:06:50,342 DEBUG SessionFactoryObjectFactory:76 - registered: d1e22501fae320e800fae320eed40000 (unnamed)
16:06:50,344 INFO SessionFactoryObjectFactory:82 - no JNDI name configured
16:06:50,346 DEBUG SessionFactoryImpl:196 - instantiated session factory
16:06:50,468 DEBUG SessionImpl:528 - opened session
16:06:50,474 DEBUG JDBCTransaction:37 - begin
16:06:50,477 DEBUG JDBCTransaction:41 - current autocommit status:false
16:06:50,520 DEBUG SessionImpl:1460 - find: Select artist.ArtistPhoto1 from test.Artist as artist where artist.ID=:artist_id
16:06:50,527 DEBUG QueryParameters:108 - named parameters: {artist_id=46}
16:06:50,559 DEBUG QueryTranslator:147 - compiling query
16:06:50,615 DEBUG SessionImpl:2193 - flushing session
16:06:50,623 DEBUG SessionImpl:2321 - Flushing entities and processing referenced collections
16:06:50,625 DEBUG SessionImpl:2664 - Processing unreferenced collections
16:06:50,627 DEBUG SessionImpl:2678 - Scheduling collection removes/(re)creates/updates
16:06:50,629 DEBUG SessionImpl:2217 - Flushed: 0 insertions, 0 updates, 0 deletions to 0 objects
16:06:50,630 DEBUG SessionImpl:2222 - Flushed: 0 (re)creations, 0 updates, 0 removals to 0 collections
16:06:50,632 DEBUG SessionImpl:1745 - Dont need to execute flush
16:06:50,634 DEBUG QueryTranslator:199 - HQL: Select artist.ArtistPhoto1 from test.Artist as artist where artist.ID=:artist_id
16:06:50,636 DEBUG QueryTranslator:200 - SQL: select artist0_.artist_photo1 as x0_0_ from artisttbl artist0_ where (artist0_.artist_id=? )
16:06:50,638 DEBUG BatcherImpl:192 - about to open: 0 open PreparedStatements, 0 open ResultSets
16:06:50,641 DEBUG SQL:223 - select artist0_.artist_photo1 as x0_0_ from artisttbl artist0_ where (artist0_.artist_id=? )
Hibernate: select artist0_.artist_photo1 as x0_0_ from artisttbl artist0_ where (artist0_.artist_id=? )
16:06:50,643 DEBUG BatcherImpl:227 - preparing statement
16:06:50,732 DEBUG Loader:196 - processing result set
16:06:50,734 DEBUG Loader:404 - result row:
16:06:50,774 DEBUG Loader:225 - done processing result set (1 rows)
16:06:50,776 DEBUG BatcherImpl:199 - done closing: 0 open PreparedStatements, 0 open ResultSets
16:06:50,778 DEBUG BatcherImpl:240 - closing statement
16:06:50,781 DEBUG SessionImpl:3000 - initializing non-lazy collections
Feb 23, 2004 4:06:51 PM org.apache.jk.server.JkCoyoteHandler action
INFO: Response already commited

5. Database - postgreSQl 7.4.1


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 23, 2004 12:25 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
I'm not gonna read that. There is no exception in that code. ClassCastExceptions are also extremely trivial to resolve.

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 23, 2004 12:28 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Oh, and don't use string manipulation to build queries, use the QBC API. I can't even read your query, as this is your internal helper class. I don't know where you get the exception, as you haven't shown any stacktrace, but from your history, I'd say your query is wrong. A Session.load(Artist.class, artistID) would have been much easier, by the way.

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
 Post subject: Christian...
PostPosted: Mon Feb 23, 2004 12:47 pm 
Regular
Regular

Joined: Mon Jan 19, 2004 10:39 pm
Posts: 84
Location: Nottingham, England
thanks for your constructive help.


Top
 Profile  
 
 Post subject: SQL query explation required.....
PostPosted: Tue Feb 24, 2004 5:40 pm 
Regular
Regular

Joined: Mon Jan 19, 2004 10:39 pm
Posts: 84
Location: Nottingham, England
Hi,
I have searched many resources but been unable to find a satisfactory answer to the problem I am having. I have constructed a query which I want tobring back one element of a row, a binary field, for which there are 3 binary fields associated with an artist record. I could have brought back the entire record in one go but as the 3 binary fields can become very big I decided to bring back one field at a time. So my plan is to return a record element of type Artist and then access it using artist.getArtistPhoto1() which has a type acceptance of byte[]. My query is:

1.
artist = (Artist)session.createQuery(select artist.ArtistPhoto1 from Artist artist where artist.ID=:artist_id)
.setParameter("artist_id",artID)
.setMaxResults(1)
.uniqueResult();

What I would like to know is why this throws a class cast exception as the query should return a single object of type Artist, should it not????. If I bring back the entire record like this:

2.
artist = (Artist)session.createQuery(from Artist artist where artist.ID=:artist_id)
.setParameter("artist_id",artID)
.setMaxResults(1)
.uniqueResult();

then I have no problems, and this I do not want to do. Is there a better way to achieve what i want to do?

I am using Hibernate 2.1.1 and postgreSQL 7.4.1.
The stacktrace associated with this issue is 2 lines:
Original Exception: java.lang.ClassCastException
at test.Artist.getArtistImage(Artist.java:119)

line 119 in my code is artist = (Artist)session.createQuery(select artist.ArtistPhoto1 from Artist artist where artist.ID=:artist_id).

Appologies in advance if the information I have supplied to comprehensive enough.

many thanks in advance


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 24, 2004 5:53 pm 
Expert
Expert

Joined: Thu Jan 08, 2004 6:17 pm
Posts: 278
artist.ArtistPhoto1 is not an Artist, it is a byte[].

You could have easily found this yourself just by:

Object whatTheHeckIsThisIfItsNotAnArtist = session.createQuery(select artist.ArtistPhoto1 from Artist artist where artist.ID=:artist_id)
.setParameter("artist_id",artID)
.setMaxResults(1)
.uniqueResult();
System.out.println("It's not an artist, it's a "+whatTheHeckIsThisIfItsNotAnArtist+", of class "+whatTheHeckIsThisIfItsNotAnArtist.getClass().getName());

Cheers,
Rob


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