-->
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.  [ 1 post ] 
Author Message
 Post subject: Why does implicit join work when explicit fails?
PostPosted: Sat Jan 06, 2007 4:08 pm 
Newbie

Joined: Sat Jan 06, 2007 3:46 pm
Posts: 15
I was able to do a simple join with the implicit notation, as in the following code. Note that I'm using Hibernate within Spring:

Code:
Collection<Media> titles = getHibernateTemplate().find("FROM Media m, Title t WHERE m.titleId = t.id AND t.title LIKE '%" + inTitle + "%'");


But when I tried to re-write it explicitly, the returned collection only contains generic Java Objects (the appropriate number), not Media objects:

Code:
Collection<Media> titles = getHibernateTemplate().find("FROM Media m WHERE m.title.title LIKE '%" + inTitle + "%'");


Chances are, I rewrote the query wrong, but I'm not sure how. Thanks for any suggestions!

I'm using the Hibernate Annotations below (additional Hibernate info at the end; I wasn't sure how to get some of the oft-requested info using Annotations):

Media
Code:
package com.latencyzero.dvd.dao;






//
//  Java Imports
//

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.Table;


//
//  Third-party Imports
//

import org.apache.log4j.Logger;

import org.hibernate.annotations.Proxy;




@Entity
@Table(name = "media")
@Proxy(lazy = false)
public
class
Media
{
    @Id
    @Column(name = "id")
    public  Integer         getId()                                 { return mID; }
    public  void            setId(Integer inVal)                    { mID = inVal; }
   
    @Column(name = "titleID")
    public  Integer         getTitleId()                            { return mTitleID; }
    public  void            setTitleId(Integer inVal)               { mTitleID = inVal; }
   
    @Column(name = "formatID")
    public  Integer         getFormatId()                           { return mFormatID; }
    public  void            setFormatId(Integer inVal)              { mFormatID = inVal; }
   
    @ManyToOne(cascade = {CascadeType.PERSIST, CascadeType.MERGE})
    @JoinColumn(name="formatId")
    public  Format          getFormat()                             { return mFormat; }
    public  void            setFormat(Format inVal)                 { mFormat = inVal; }
   
    @ManyToOne(cascade = {CascadeType.PERSIST, CascadeType.MERGE})
    @JoinColumn(name="titleId")
    public  Title           getTitle()                              { return mTitle; }
    public  void            setTitle(Title inVal)                   { mTitle = inVal; }
   
    private Integer         mID;
    private Integer         mTitleID;
    private Integer         mFormatID;
   
    private Format          mFormat;
    private Title           mTitle;
   
    private static  Logger  sLogger                         =   Logger.getLogger(Media.class);
}


Format
Code:
package com.latencyzero.dvd.dao;






//
//  Java Imports
//

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;


//
//  Third-party Imports
//

import org.apache.log4j.Logger;

import org.hibernate.annotations.Proxy;




@Entity
@Table(name = "format")
@Proxy(lazy = false)
public
class
Format
{
    @Id
    @Column(name = "id")
    public  Integer         getId()                                 { return mID; }
    public  void            setId(Integer inVal)                    { mID = inVal; }
   
    @Column(name = "parentID")
    public  Integer         getParentId()                               { return mParentID; }
    public  void            setParentId(Integer inVal)                  { mParentID = inVal; }
   
    @Column(name = "name")
    public  String          getName()                               { return mName; }
    public  void            setName(String inVal)                   { mName = inVal; }
   
    private Integer         mID;
    private Integer         mParentID;
    private String          mName;
   
    private static  Logger  sLogger                         =   Logger.getLogger(Format.class);
}


Title
Code:
package com.latencyzero.dvd.dao;






//
//  Java Imports
//

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;


//
//  Third-party Imports
//

import org.apache.log4j.Logger;

import org.hibernate.annotations.Proxy;




@Entity
@Table(name = "title")
@Proxy(lazy = false)
public
class
Title
{
    @Id
    @Column(name = "id")
    public  Integer         getId()                                 { return mID; }
    public  void            setId(Integer inVal)                    { mID = inVal; }
   
    @Column(name = "title")
    public  String          getTitle()                              { return mTitle; }
    public  void            setTitle(String inVal)                  { mTitle = inVal; }
   
    private Integer         mID;
    private String          mTitle;
    private String          mImdbID;
   
    private static  Logger  sLogger                         =   Logger.getLogger(Title.class);
}



Hibernate version: 3.2.1ga

Name and version of the database you are using: MySQL 5.1.14beta


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.