Hibernate version: 3.1beta3
Hibernate Annotations version: 3.1beta5
Full stack trace of any exception that occurs:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in class path resource [applicationContext.xml]: Initialization of bean failed; nested exception is org.hibernate.AnnotationException: No identifier specified for entity: ru.siteforge.model.Account
org.hibernate.AnnotationException: No identifier specified for entity: ru.siteforge.model.Account
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)
...
Name and version of the database: MySQL 4.0.24
Code:
@Entity
@Inheritance(strategy = InheritanceType.JOINED)
@Table(name = "sf_persistent_object")
abstract class PersistentObject implements Serializable
{
private static final long serialVersionUID = -3555198930641746803L;
private long id;
private Calendar lastModifiedDate;
private Calendar creationDate;
private Account lastChanger;
private Account creator;
@Id(generate = GeneratorType.TABLE, generator = "obj_id_gen")
@Column(name = "id")
public long getId()
{
return id;
}
@Column(name = "last_modified_date", nullable = false)
public Calendar getLastModifiedDate()
{
return lastModifiedDate;
}
@Column(name = "creation_date", nullable = false)
public Calendar getCreationDate()
{
return creationDate;
}
@ManyToOne(cascade = CascadeType.ALL)
@JoinColumn(name = "fk_last_changer_id", nullable = false)
public Account getLastChanger()
{
return lastChanger;
}
@ManyToOne(cascade = {CascadeType.PERSIST, CascadeType.MERGE})
@JoinColumn(name = "fk_creator_id", nullable = false)
public Account getCreator()
{
return creator;
}
public void setId(long id)
{
this.id = id;
}
public void setLastModifiedDate(Calendar lastModified)
{
this.lastModifiedDate = lastModified;
}
public void setCreationDate(Calendar creationDate)
{
this.creationDate = creationDate;
}
public void setCreator(Account owner)
{
this.creator = owner;
}
public void setLastChanger(Account lastChanger)
{
this.lastChanger = lastChanger;
}
}
Code:
@Entity(access = AccessType.PROPERTY)
@PrimaryKeyJoinColumn(name="fk_persistent_object_id")
@Table(name = "sf_account")
@TableGenerator(name = "obj_id_gen", tableName = "GEN_TABLE", pkColumnValue = "global_object_id", allocationSize = 1)
@GeneratedIdTable(
name="GEN_TABLE",
table = @Table(name="sf_hibernate_sequences")
)
public class Account extends PersistentObject
{
private static final long serialVersionUID = -9009838260646199450L;
private String username;
private String password;
private String email;
public Account()
{
super();
}
public Account(String email, String password)
{
this.email = email;
this.password = password;
}
@Basic
@Column(name = "email")
public String getEmail()
{
return email;
}
public void setEmail(String email)
{
this.email = email;
}
@Basic
@Column(name = "username")
public String getUsername()
{
return username;
}
public void setUsername(String username)
{
this.username = username;
}
@Basic
@Column(name="password")
public String getPassword()
{
return password;
}
public void setPassword(String password)
{
this.password = password;
}
}
When I specified identifier in Account class all start working, but inheritance not and I have following sql:
Hibernate: select account0_.id as id0_0_, account0_.password as password0_0_, account0_.username as username0_0_, account0_.email as email0_0_ from sf_account account0_ where account0_.id=?
Hibernate: insert into sf_account (password, username, email, id) values (?, ?, ?, ?)
What I doing wrong?