-->
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: How to join on object
PostPosted: Sun Jun 16, 2013 9:30 pm 
Newbie

Joined: Sun Jun 16, 2013 9:24 pm
Posts: 1
I have the following tables
Brand (brand_id, brand_name)
Website (website_id, brand_id, etc...)

Where a website can have many brands.
Below is a copy of my Brand and Website classes:
Code:
public class Website  implements java.io.Serializable {
private int websiteId;
     private WebsiteType websiteType;
     private Brand brand;
     private Serializable websiteTradingName;
     private Serializable websiteDomain;
     private Serializable analyticsId;
     private String countryId;
     private Boolean websiteStatus;
     private Serializable websiteHomeFolder;
     private Serializable websitePrivacyPolicy;
     private Set cmsPages = new HashSet(0);
     private Set websiteDomainNames = new HashSet(0);
     private Set cmsLogins = new HashSet(0);
     private Set websiteImages = new HashSet(0);

@Id
   
    @Column(name="website_id", unique=true, nullable=false)
    public int getWebsiteId() {
        return this.websiteId;
    }
   
    public void setWebsiteId(int websiteId) {
        this.websiteId = websiteId;
    }
@ManyToOne(fetch=FetchType.LAZY)
    @JoinColumn(name="website_type_id", nullable=false)
    public WebsiteType getWebsiteType() {
        return this.websiteType;
    }
   
    public void setWebsiteType(WebsiteType websiteType) {
        this.websiteType = websiteType;
    }
@ManyToOne(fetch=FetchType.LAZY)
    @JoinColumn(name="brand_id", nullable=false)
    public Brand getBrand() {
        return this.brand;
    }
   
    public void setBrand(Brand brand) {
        this.brand = brand;
    }
   
    @Column(name="website_trading_name", nullable=false)
    public Serializable getWebsiteTradingName() {
        return this.websiteTradingName;
    }
   
    public void setWebsiteTradingName(Serializable websiteTradingName) {
        this.websiteTradingName = websiteTradingName;
    }
   
    @Column(name="website_domain", nullable=false)
    public Serializable getWebsiteDomain() {
        return this.websiteDomain;
    }
   
    public void setWebsiteDomain(Serializable websiteDomain) {
        this.websiteDomain = websiteDomain;
    }
   
    @Column(name="analytics_id")
    public Serializable getAnalyticsId() {
        return this.analyticsId;
    }
   
    public void setAnalyticsId(Serializable analyticsId) {
        this.analyticsId = analyticsId;
    }
   
    @Column(name="country_id", nullable=false, length=2)
    public String getCountryId() {
        return this.countryId;
    }
   
    public void setCountryId(String countryId) {
        this.countryId = countryId;
    }
   
    @Column(name="website_status")
    public Boolean getWebsiteStatus() {
        return this.websiteStatus;
    }
   
    public void setWebsiteStatus(Boolean websiteStatus) {
        this.websiteStatus = websiteStatus;
    }
   
    @Column(name="website_home_folder")
    public Serializable getWebsiteHomeFolder() {
        return this.websiteHomeFolder;
    }
   
    public void setWebsiteHomeFolder(Serializable websiteHomeFolder) {
        this.websiteHomeFolder = websiteHomeFolder;
    }
   
    @Column(name="website_privacy_policy")
    public Serializable getWebsitePrivacyPolicy() {
        return this.websitePrivacyPolicy;
    }
   
    public void setWebsitePrivacyPolicy(Serializable websitePrivacyPolicy) {
        this.websitePrivacyPolicy = websitePrivacyPolicy;
    }
@OneToMany(cascade=CascadeType.ALL, fetch=FetchType.LAZY, mappedBy="website")
    public Set getCmsPages() {
        return this.cmsPages;
    }
   
    public void setCmsPages(Set cmsPages) {
        this.cmsPages = cmsPages;
    }
@OneToMany(cascade=CascadeType.ALL, fetch=FetchType.LAZY, mappedBy="website")
    public Set getWebsiteDomainNames() {
        return this.websiteDomainNames;
    }
   
    public void setWebsiteDomainNames(Set websiteDomainNames) {
        this.websiteDomainNames = websiteDomainNames;
    }
@OneToMany(cascade=CascadeType.ALL, fetch=FetchType.LAZY, mappedBy="website")
    public Set getCmsLogins() {
        return this.cmsLogins;
    }
   
    public void setCmsLogins(Set cmsLogins) {
        this.cmsLogins = cmsLogins;
    }
@OneToMany(cascade=CascadeType.ALL, fetch=FetchType.LAZY, mappedBy="website")
    public Set getWebsiteImages() {
        return this.websiteImages;
    }
   
    public void setWebsiteImages(Set websiteImages) {
        this.websiteImages = websiteImages;
    }
}


Code:
public class Brand  implements java.io.Serializable {
private static final long serialVersionUID = 1L;

     private int brandId;
     private String brandName;
     private Set websites = new HashSet(0);

    public Brand() {
    }

   
    public Brand(int brandId, String brandName) {
        this.brandId = brandId;
        this.brandName = brandName;
    }
    public Brand(int brandId, String brandName, Set websites) {
       this.brandId = brandId;
       this.brandName = brandName;
       this.websites = websites;
    }
   
    @Id
    @Column(name="brand_id", unique=true, nullable=false)
    public int getBrandId() {
        return this.brandId;
    }
   
    public void setBrandId(int brandId) {
        this.brandId = brandId;
    }
   
    @Column(name="brand_name", nullable=false, length=50)
    public String getBrandName() {
        return this.brandName;
    }
   
    public void setBrandName(String brandName) {
        this.brandName = brandName;
    }
   
    @OneToMany(cascade=CascadeType.ALL, fetch=FetchType.LAZY, mappedBy="brand")
    public Set getWebsites() {
        return this.websites;
    }
   
    public void setWebsites(Set websites) {
        this.websites = websites;
    }

}


What I want to do is "select * from website where brand_id = X"

I'm new to Hibernate and can't figure out how to do this. Can someone please help.
thanks


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.