-->
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.  [ 3 posts ] 
Author Message
 Post subject: Annotation @Embedded - why does this crash?
PostPosted: Tue Feb 02, 2010 9:51 am 
Newbie

Joined: Tue Apr 03, 2007 8:10 am
Posts: 1
Location: Berlin
Hi,

I am running into a weird problem using Hibernate Annotations (3.3.1.GA).

The offending class looks like this:

Code:
@Entity
@Table(name="protocol_item")
@AttributeOverrides(
{
@AttributeOverride(name="ID",column=@Column(name="id"))
}
)
@SequenceGenerator(name = "seq", sequenceName = "protocol_item_id_seq")
public class protocolItem extends annotableBiotype implements binary_attachable, Comparable {


   
//...
//many stuff left out here!


    private protocolVersion version = null;

 
    /**
     * @return the version
     */
 
// This embedded class is causing the trouble
    @Embedded
    public protocolVersion getProtocolVersion() {
        if (this.version==null){
           this.version =  new protocolVersion();
        }
        return version;
    }

    /**
     * @param version the version to set
     */
    public void setProtocolVersion(protocolVersion version) {
        this.version = version;
    }

   @ManyToOne
    @JoinColumn(name="summary")
    public protocolSummary getSummary() {
        return summary;
    }

//more stuff left out here...
//which all works fine...

   }



the embeddable class goes like this:

Code:
@Embeddable
public class protocolVersion implements Comparable, Serializable {

    private int major =1;

    private int minor = 0;

    /**
     * @return the major
     */
    public int getMajorversion() {
        return major;
    }

    /**
     * @param major the major to set
     */
    public void setMajorversion(int major) {
        this.major = major;
    }

    /**
     * @return the minor
     */
    public int getMinorversion() {
        return minor;
    }

    /**
     * @param minor the minor to set
     */
    public void setMinorversion(int minor) {
        this.minor = minor;
    }

    @Override
  public String toString(){
    StringBuffer bfr = new StringBuffer();
    bfr.append(this.getMajorversion());
    bfr.append(".");
    bfr.append(this.getMinorversion());
      return bfr.toString();
  }


public int compareTo(Object o){
    if (o == null){
        return 1;
    }
    if (o == this){
        return 0;
    }
    protocolVersion v = (protocolVersion)o;
    int bfr = 0;
    bfr = this.getMajorversion()-v.getMajorversion();
    if (bfr != 0){
        return bfr;
    } else {
        return this.getMinorversion()-v.getMinorversion();
    }
}

public boolean equals(Object o){
   return this.compareTo(o)==0;
}


    @Override
    public int hashCode() {
        int hash = 5;
        hash = 71 * hash + this.major;
        hash = 71 * hash + this.minor;
        return hash;
    }



}


the table (in PostgreSQL 8.1), most columns left out for clarity:

Code:
CREATE TABLE protocol_item
(
  id serial NOT NULL,
  summary character varying(80) NOT NULL,
   majorversion integer NOT NULL DEFAULT 1,
  minorversion integer NOT NULL DEFAULT 0,
  CONSTRAINT protocol_item_pkey PRIMARY KEY (id),
   CONSTRAINT protocol_item_summary_fkey FOREIGN KEY (summary)
      REFERENCES protocol_summaries (id) MATCH SIMPLE
      ON UPDATE NO ACTION ON DELETE NO ACTION,
  CONSTRAINT protocol_item_summary_key UNIQUE (summary, majorversion, minorversion)
)


This construct causes a

Code:
java.lang.StackOverflowError
        at org.hibernate.cfg.AbstractPropertyHolder.getOverriddenColumn(AbstractPropertyHolder.java:77)
        at org.hibernate.cfg.ComponentPropertyHolder.getOverriddenColumn(ComponentPropertyHolder.java:105)
        at org.hibernate.cfg.AbstractPropertyHolder.getOverriddenColumn(AbstractPropertyHolder.java:79)
        at org.hibernate.cfg.ComponentPropertyHolder.getOverriddenColumn(ComponentPropertyHolder.java:105)
        at org.hibernate.cfg.AbstractPropertyHolder.getOverriddenColumn(AbstractPropertyHolder.java:79)
        at org.hibernate.cfg.ComponentPropertyHolder.getOverriddenColumn(ComponentPropertyHolder.java:105)
        (...many more of the same...)


error on startup, at calling to

Code:
SessionFactory sf = new AnnotationConfiguration().configure().buildSessionFactory();


I am absolutely stuck and have no idea what is going on here. The whole project has ca. 100 entity classes which all work just fine, except this single one.


Top
 Profile  
 
 Post subject: Re: Annotation @Embedded - why does this crash?
PostPosted: Tue Feb 02, 2010 10:00 am 
Regular
Regular

Joined: Thu Dec 10, 2009 10:53 am
Posts: 50
Maybe this is the culprit, which causes an infinite loop:
Code:
        if (this.version==null){
           this.version =  new protocolVersion();
        }


Otherwise I would just try debugging what happens in:
at org.hibernate.cfg.AbstractPropertyHolder.getOverriddenColumn(AbstractPropertyHolder.java:77)
and
at org.hibernate.cfg.ComponentPropertyHolder.getOverriddenColumn(ComponentPropertyHolder.java:105)


Top
 Profile  
 
 Post subject: Re: Annotation @Embedded - why does this crash?
PostPosted: Wed Feb 03, 2010 6:18 pm 
Expert
Expert

Joined: Tue May 13, 2008 3:42 pm
Posts: 919
Location: Toronto & Ajax Ontario www.hibernatemadeeasy.com
Throw some logging or a breakpoint in there. Something's causing an infinite or more likely, recursive loop.

_________________
Cameron McKenzie - Author of "Hibernate Made Easy" and "What is WebSphere?"
http://www.TheBookOnHibernate.com Check out my 'easy to follow' Hibernate & JPA Tutorials


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

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.