Hello, I think you can use pass-thru OQL to do your complex query :
Here's the example which is given in Castor Doc : On http://www.castor.org/jdo-faq.html#OQL : OQLQuery oql = castorDb.getOQLQuery( "CALL SQL SELECT id, name, date "+ "FROM user WHERE upper(name) like $1 AS myapp.Product"); Be remember that : . the order of the fields listed must match what is defined in the mapping file. . The class which is in the AS clause must be mapped to a table . You give directly the SQL query to Castor, and so make the query you want ... But take care of the fields you put on the SELECT clause, and of the Class you give in the AS clause ... You must have the same fields (not less, not more) in the SELECT clause than you have in the Class you want to retrieve, and they must appear in the same order than they are declared in the Class. Problem : if you have an Colection Attribut in your Class, you can't use it like this. I had to create a new Class - PersonView - with no Collection Attribut, and add it to the mapping file, and then to use it in the AS clause. The Object you will retrieve from the oql.execute() will give you a myapp.Product object. May be that will help you. Sylvie. ___________________ CREDI RA Sylvie Palluel [EMAIL PROTECTED] ___________________ > -----Message d'origine----- > De : Peter Jeszenszky [mailto:[EMAIL PROTECTED] > Envoy� : mercredi 9 juillet 2003 16:47 > � : [EMAIL PROTECTED] > Objet : [castor-dev] Complex query problem > > > Hello, > > I must execute a complex query that currently can not be > formulated in the OQL subset that Castor supports. To achieve > my goal I do the > following: > > import java.sql.*; > import org.exolab.castor.jdo.engine.DatabaseImpl; > > Database db; > > db.begin(); > > // Query the underlying JDBC connection > Connection conn = (Connection) ((DatabaseImpl) > db).getConnection(); > > Statement st = conn.createStatement(); > > // Execute the SQL query that returns the IDs of the > objects that satisfy the search condition > ResultSet rs = st.executeQuery("SELECT id FROM > foo WHERE ..."); > > Vector result = new Vector(); // This vector holds > the result objects > > while (rs.next()) { > // Request the ID of the next object > int id = rs.getInt(1); > > // Load the object with that ID > Foo foo = (Foo) db.load(Foo.class, new Integer(id)); > result.addElement(foo); > } > > db.close(); > > I would like to know whether the solution above is safe and > gives the correct results. Yours sincerely, > > Peter > > ----------------------------------------------------------- > If you wish to unsubscribe from this mailing, send mail to > [EMAIL PROTECTED] with a subject of: > unsubscribe castor-dev > > ********************************************************************** This email and any files transmitted with it are confidential and intended solely for the use of the individual or entity to whom they are addressed. If you have received this email in error please notify the system manager. This footnote also confirms that this email message has been swept by MIMEsweeper for the presence of computer viruses. www.mimesweeper.com ********************************************************************** ----------------------------------------------------------- If you wish to unsubscribe from this mailing, send mail to [EMAIL PROTECTED] with a subject of: unsubscribe castor-dev
