Help with Hibernate mapping

Posted by GigaPr on Stack Overflow See other posts from Stack Overflow or by GigaPr
Published on 2010-06-01T19:41:50Z Indexed on 2010/06/01 19:43 UTC
Read the original article Hit count: 265

Filed under:

Hi

i have the following classes

public class RSS 
{
    private Integer id;
    private String title;
    private String description;
    private String link;
    private Date dateCreated;
    private Collection rssItems;
    private String  url;
    private String language;
    private String rating;
    private Date pubDate;
    private Date lastBuildDate;
    private User user;
    private Date dateModified;

    public RSS() {
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public void setDescription(String description){
        this.description = description;
    }

    public String getDescription(){
        return this.description;
    }

    public void setLink(String link){
        this.link = link;
    }

    public String getLink(){
        return this.link;
    }

    public void setUrl(String url){
        this.url = url;
    }

    public String getUrl(){
        return this.url;
    }

    public void setLanguage(String language){
        this.language = language;
    }

    public String getLanguage(){
        return this.language;
    }

    public void setRating(String rating){
        this.rating = rating;
    }

    public String getRating(){
        return this.rating;
    }

    public Date getPubDate() {
        return pubDate;
    }

    public void setPubDate(Date pubDate) {
        this.pubDate = pubDate;
    }

    public Date getLastBuildDate() {
        return lastBuildDate;
    }

    public void setLastBuildDate(Date lastBuildDate) {
        this.lastBuildDate = lastBuildDate;
    }

    public Date getDateModified() {
        return dateModified;
    }

    public void setDateModified(Date dateModified) {
        this.dateModified = dateModified;
    }

    public Date getDateCreated() {
        return dateCreated;
    }

    public void setDateCreated(Date dateCreated) {
        this.dateCreated = dateCreated;
    }

    public Collection getRssItems() {
        return rssItems;
    }

    public void setRssItems(Collection rssItems) {
        this.rssItems = rssItems;
    }
}

public class RSSItem {

    private RSS rss;

    private Integer id;
    private String title;
    private String description;
    private String link;
    private Date dateCreated;
    private Date dateModified;
    private int rss_id;

    public RSSItem() {}

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public String getLink() {
        return link;
    }

    public void setLink(String link) {
        this.link = link;
    }

    public Date getDateCreated() {
        return dateCreated;
    }

    public void setDateCreated(Date dateCreated) {
        this.dateCreated = dateCreated;
    }

    public Date getDateModified() {
        return dateModified;
    }

    public void setDateModified(Date dateModified) {
        this.dateModified = dateModified;
    }

    public RSS getRss() {
        return rss;
    }

    public void setRss(RSS rss) {
        this.rss = rss;
    }
}

that i mapped as

    <hibernate-mapping>
  <class name="com.rssFeed.domain.RSS"  schema="PUBLIC" table="RSS">
    <id name="id" type="int">
      <column name="ID"/>
      <generator class="native"/>
    </id>
    <property name="title" type="string">
      <column name="TITLE" not-null="true"/>
    </property>        
    <property name="lastBuildDate" type="java.util.Date">
      <column name="LASTBUILDDATE"/>
    </property>
    <property name="pubDate" type="java.util.Date">
      <column name="PUBDATE" />
    </property>
    <property name="dateCreated" type="java.util.Date">
      <column name="DATECREATED" not-null="true"/>
    </property>
    <property name="dateModified" type="java.util.Date">
      <column name="DATEMODIFIED" not-null="true"/>
    </property>
    <property name="description" type="string">
      <column name="DESCRIPTION" not-null="true"/>
    </property>
    <property name="link" type="string">
      <column name="LINK" not-null="true"/>
    </property>
    <property name="url" type="string">
      <column name="URL" not-null="true"/>
    </property>
    <property name="language" type="string">
      <column name="LANGUAGE" not-null="true"/>
    </property>
    <property name="rating" type="string">
      <column name="RATING"/>
    </property>
     <set inverse="true" lazy="false" name="rssItems">
      <key>
        <column name="RSS_ID"/>
      </key>
      <one-to-many class="com.rssFeed.domain.RSSItem"/>
    </set>
  </class>
</hibernate-mapping>


<hibernate-mapping>
  <class name="com.rssFeed.domain.RSSItem" schema="PUBLIC" table="RSSItem">
    <id name="id" type="int">
      <column name="ID"/>
      <generator class="native"/>
    </id>
    <property name="title" type="string">
      <column name="TITLE" not-null="true"/>
    </property>
    <property name="description" type="string">
      <column name="DESCRIPTION" not-null="true"/>
    </property>
    <property name="link" type="string">
      <column name="LINK" not-null="true"/>
    </property>
    <property name="dateCreated" type="java.util.Date">
      <column name="DATECREATED"/>
    </property>
    <property name="dateModified" type="java.util.Date">
      <column name="DATEMODIFIED"/>
    </property>
    <many-to-one class="com.rssFeed.domain.RSS" fetch="select" name="rss">
      <column name="RSS_ID"/>
    </many-to-one>
  </class>
</hibernate-mapping>

But when i try to fetch an RSS I get the following error

Exception occurred in target VM: failed to lazily initialize a collection of role: com.rssFeed.domain.RSS.rssItems, no session or session was closed org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: com.rssFeed.domain.RSS.rssItems, no session or session was closed at org.hibernate.collection.AbstractPersistentCollection.throwLazyInitializationException(AbstractPersistentCollection.java:358) at org.hibernate.collection.AbstractPersistentCollection.throwLazyInitializationExceptionIfNotConnected(AbstractPersistentCollection.java:350) at org.hibernate.collection.AbstractPersistentCollection.readSize(AbstractPersistentCollection.java:97) at org.hibernate.collection.PersistentSet.size(PersistentSet.java:139) at com.rssFeed.dao.hibernate.HibernateRssDao.get(HibernateRssDao.java:47) at com.rssFeed.ServiceImplementation.RssServiceImplementation.get(RssServiceImplementation.java:46) at com.rssFeed.mvc.ViewRssController.handleRequest(ViewRssController.java:20) at org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter.handle(SimpleControllerHandlerAdapter.java:48) at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:875) at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:809) at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:476) at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:431) at javax.servlet.http.HttpServlet.service(HttpServlet.java:734) at javax.servlet.http.HttpServlet.service(HttpServlet.java:847) at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1523) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:279) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:188) at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:641) at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:97) at com.sun.enterprise.web.PESessionLockingStandardPipeline.invoke(PESessionLockingStandardPipeline.java:85) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:185) at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:332) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:233) at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:165) at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:791) at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:693) at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:954) at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:170) at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:135) at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:102) at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:88) at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:76) at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:53) at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:57) at com.sun.grizzly.ContextTask.run(ContextTask.java:69) at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:330) at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:309) at java.lang.Thread.run(Thread.java:619) <

what does it mean?

Thanks

© Stack Overflow or respective owner

Related posts about hibernate