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.