Note that there are some explanatory texts on larger screens.

plurals
  1. POSpring MVC and Hibernate: How to print out left joined fields?
    primarykey
    data
    text
    <p>I'm new to Spring (MVC) and Hibernate... I got the following problem:</p> <p>I'm developing a RSS App which in short parse a RSS feed, store the fields in a database and displays the RSS info on a web page.</p> <p>Some RSS feeds got an image. I have no problem parse and store it, but I got a problem displaying it together with the RSS info. The RSS info is stored in one table (fields: id, title, description, url, link, language, date) while the RSS image info is stored in another one (fields: id, title, description, url, height, width, rss_id). There should be a one-to-one relation. </p> <p>My Hibernate query for retriving all the RSS look like this and is working:</p> <pre><code>public List&lt;RSS&gt; getAllRSS() { return getHibernateTemplate().find("from RSS as rss left join fetch rss.rssImage as image"); } </code></pre> <p>For printing out the RSS info I use the following code:</p> <pre><code>RSSService rssService = (RSSService) ctx.getBean("rssService"); RSS rss = new RSS(); List list = rssService.listAllRSS(); Iterator i = list.iterator(); while(i.hasNext()){ rss = (RSS) i.next(); System.out.println("rss title:" + rss.getTitle()); } </code></pre> <p>And this is working. But how can I retrive the fields from the image?</p> <p>RSS class:</p> <pre><code>public class RSS { private Integer id; private String title; private Date dateCreated; private String description; private String link; private String url; private String language; private String rating; private Date dateModified; private Set rssItems; private Set rssImage; /** * @return the id */ public Integer getId() { return id; } /** * @param id the id to set */ public void setId(Integer id) { this.id = id; } public Date getDateCreated() { return dateCreated; } public void setDateCreated(Date dateCreated) { this.dateCreated = dateCreated; } public String getTitle() { return title; } public void setTitle(String title) { this.title = title; } public Date getDateModified() { return dateModified; } public void setDateModified(Date dateModified) { this.dateModified = dateModified; } public String getDescription() { return description; } public void setDescription(String description) { this.description = description; } public String getLanguage() { return language; } public void setLanguage(String language) { this.language = language; } public String getLink() { return link; } public void setLink(String link) { this.link = link; } public String getRating() { return rating; } public void setRating(String rating) { this.rating = rating; } public String getUrl() { return url; } public void setUrl(String url) { this.url = url; } /** * @return the rssItems */ public Set getRssItems() { return rssItems; } /** * @param rssItems the rssItems to set */ public void setRssItems(Set rssItems) { this.rssItems = rssItems; } /** * @return the rssImage */ public Set getRssImage() { return rssImage; } /** * @param rssImage the rssImage to set */ public void setRssImage(Set rssImage) { this.rssImage = rssImage; } } </code></pre> <p>RSS Image class:</p> <pre><code>public class RSSImage { private Integer id; private String title; private String url; private String description; private String width; private String height; private Date dateCreated; private Date dateModified; private RSS rss; /** * @return the id */ public Integer getId() { return id; } /** * @param id the id to set */ public void setId(Integer id) { this.id = id; } /** * @return the title */ public String getTitle() { return title; } /** * @param title the title to set */ public void setTitle(String title) { this.title = title; } /** * @return the url */ public String getUrl() { return url; } /** * @param url the url to set */ public void setUrl(String url) { this.url = url; } /** * @return the description */ public String getDescription() { return description; } /** * @param description the description to set */ public void setDescription(String description) { this.description = description; } /** * @return the width */ public String getWidth() { return width; } /** * @param width the width to set */ public void setWidth(String width) { this.width = width; } /** * @return the height */ public String getHeight() { return height; } /** * @param height the height to set */ public void setHeight(String height) { this.height = height; } /** * @return the dateCreated */ public Date getDateCreated() { return dateCreated; } /** * @param dateCreated the dateCreated to set */ public void setDateCreated(Date dateCreated) { this.dateCreated = dateCreated; } /** * @return the dateModified */ public Date getDateModified() { return dateModified; } /** * @param dateModified the dateModified to set */ public void setDateModified(Date dateModified) { this.dateModified = dateModified; } /** * @return the rss */ public RSS getRss() { return rss; } /** * @param rss the rss to set */ public void setRss(RSS rss) { this.rss = rss; } } </code></pre> <p>Thanks :)</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload