-->
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: Problem with a query -with to tables -:)
PostPosted: Wed May 24, 2006 1:08 pm 
Newbie

Joined: Mon Apr 10, 2006 3:32 pm
Posts: 13
Hi everybody:

I have this

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >
<hibernate-mapping package="de.laliluna.example">
<class name="book" table="book">
<composite-id>
<key-property name="id" />
<key-many-to-one name="customer" column="customer_fk" class="de.laliluna.hibernate.customer" />
</composite-id>
<property name="title" column="title" type="java.lang.String" />
<property name="author" column="author" type="java.lang.String" />
<property name="available" column="available"/>
</class>
<query name="query_user"><![CDATA[from book, de.laliluna.hibernate.customer]]></query>

</hibernate-mapping>

And my class:

try
{
Session session = InitSessionFactory.getInstance().getCurrentSession();
Transaction tx = session.beginTransaction();
Query auth = session.getNamedQuery("query_user");
List res = auth.list();

Iterator iter = res.iterator();
if(iter.hasNext() )
{


book val = (book)iter.next();


//System.out.print(val.getauthor());
//book val = (book)iterex.next();

}
}

and i gotting this error

Exception in thread main
java.lang.ClassCastException: [Ljava.lang.Object;

at de.laliluna.example.TestExample.search(TestExample.java:153)

at de.laliluna.example.TestExample.main(TestExample.java:49)


How can i fix this problem?

Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version:

Mapping documents:

Code between sessionFactory.openSession() and session.close():

Full stack trace of any exception that occurs:

Name and version of the database you are using:

The generated SQL (show_sql=true):

Debug level Hibernate log excerpt:


Last edited by mauricio_led on Wed May 24, 2006 1:49 pm, edited 1 time in total.

Top
 Profile  
 
 Post subject:
PostPosted: Wed May 24, 2006 1:29 pm 
Newbie

Joined: Mon Apr 10, 2006 3:32 pm
Posts: 13
I fix it!!!!! :)

while(iter.hasNext() )
{

Object[] val = (Object[])iter.next();
book ko = (book)val[0];
customer cost = (customer)val[1];
System.out.print(ko.getauthor());
}


: p


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.