hello,
When I tried inheritance with Hibernate3 annotation, it raised the following errors, what can I do ?
I use Hibernate3.1-beta3 and hibernate-3.1-annotation-beta5
Eric
Code:
package mo.kudocs.framework.bean;
import java.io.Serializable;
import java.util.Date;
import javax.persistence.AccessType;
import javax.persistence.Column;
import javax.persistence.EmbeddableSuperclass;
import javax.persistence.Entity;
import javax.persistence.GeneratorType;
import javax.persistence.Id;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.Table;
import javax.persistence.Transient;
@EmbeddableSuperclass
public class AbstractObject implements Serializable {
public static final long serialVersionUID = 1L;
@Id(generate=GeneratorType.NONE)
@Column(updatable = false)
protected long id;
@Column
protected Date createDate = new Date();
@Column
protected Date updateDate = new Date();
/**
*
*/
public AbstractObject() {
super();
}
@Transient
public String getIndexText() {
return id + " " + createDate + " " + updateDate;
}
@Transient
public String toString() {
StringBuffer buf = new StringBuffer();
buf.append("create date: " + createDate);
buf.append(", update date: " + updateDate);
return buf.toString();
}
/**
* @return Returns the createDate.
*/
public Date getCreateDate() {
return this.createDate;
}
/**
* @param createDate The createDate to set.
*/
public void setCreateDate(Date createDate) {
this.createDate = createDate;
}
/**
* @return Returns the updateDate.
*/
public Date getUpdateDate() {
return this.updateDate;
}
/**
* @param updateDate The updateDate to set.
*/
public void setUpdateDate(Date updateDate) {
this.updateDate = updateDate;
}
/**
* @return Returns the id.
*/
public long getId() {
return this.id;
}
/**
* @param id The id to set.
*/
public void setId(long id) {
this.id = id;
}
}
Code:
package mo.kudocs.framework.bean;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.PrimaryKeyJoinColumn;
import javax.persistence.Table;
import javax.persistence.Transient;
@Entity
@Table (name = "SYS_COUNTER")
@NamedQueries ( {
@NamedQuery (name = "syscounter.findAll", queryString = "select sc from SystemCounter sc"),
@NamedQuery (name = "syscounter.findByName", queryString = "select sc from SystemCounter sc where sc.name = :name")
})
public class SystemCounter extends AbstractObject {
public static final long serialVersionUID = 1L;
protected String name;
protected long value;
/**
*
*/
public SystemCounter() {
super();
}
/**
* @return Returns the name.
*/
@PrimaryKeyJoinColumn
@Column (nullable = false)
public String getName() {
return this.name;
}
/**
* @param name
* The name to set.
*/
public void setName(String name) {
this.name = name;
}
/**
* @return Returns the value.
*/
@Column (nullable = false)
public long getValue() {
return this.value;
}
/**
* @param value
* The value to set.
*/
public void setValue(long value) {
this.value = value;
}
@Transient
public String getIndexText() {
return name + " " + value;
}
@Transient
public String toString() {
StringBuffer buf = new StringBuffer();
buf.append("name=" + name + ", value=" + value);
return buf.toString();
}
}
Code:
SEVERE: Building SessionFactory failed.
org.hibernate.AnnotationException: No identifier specified for entity: mo.kudocs.framework.bean.SystemCounter
at org.hibernate.cfg.AnnotationBinder.bindClass(AnnotationBinder.java:645)
at org.hibernate.cfg.AnnotationConfiguration.processArtifactsOfType(AnnotationConfiguration.java:256)
at org.hibernate.cfg.AnnotationConfiguration.secondPassCompile(AnnotationConfiguration.java:191)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1120)