hi
I am using annotations with hibernate 3.When i try to run i get the following error.The stack trace is:
Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in file [E:\V11\AnnotationsInV11\src\application.xml]: Initialization of bean failed; nested exception is org.hibernate.AnnotationException: Annotated class should have an @Entity annotation: MyObjectImpl
org.hibernate.AnnotationException: Annotated class should have an @Entity annotation: MyObjectImpl
at org.hibernate.cfg.AnnotationBinder.bindClass(AnnotationBinder.java:210)
at org.hibernate.cfg.AnnotationConfiguration.addAnnotatedClass(AnnotationConfiguration.java:44)
at org.springframework.orm.hibernate3.LocalAnnotationSessionFactoryBean.postProcessConfiguration(LocalAnnotationSessionFactoryBean.java:89)
Following is my Source Code:
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
@Table(name = "MY_OBJECT_TABLE")
@Entity
public class MyObjectImpl
implements Serializable {
private
long id;
private
String foo;
private
String trans;
@Id(generate=GeneratorType.IDENTITY)
@Column(name = "ID")
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
@Column(name = "FOO", nullable = false, updatable = true, length = 50)
public String getFoo() {
return foo;
}
public void setFoo(String foo) {
this.foo = foo;
}
// This indicates that this bean property is not persistent (aka transient)
@Transient
public String getTrans() {
return trans;
}
public void setTrans(String trans) {
this.trans = trans;
}
public static void main(String[] args) {
ApplicationContext ac=new FileSystemXmlApplicationContext("src\\application.xml");
SessionFactory sessionFactory = (SessionFactory)ac.getBean("sessionFactory");
Session s = sessionFactory.openSession();
MyObjectImpl o = new MyObjectImpl();
o.setFoo("bar");
s.save(o);
s.flush();
s.close();
}
}
|