-->
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.  [ 4 posts ] 
Author Message
 Post subject: problem with using entity annotation
PostPosted: Fri Mar 18, 2005 8:04 am 
Newbie

Joined: Fri Mar 18, 2005 7:58 am
Posts: 8
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();

}
}


Top
 Profile  
 
 Post subject:
PostPosted: Sun Mar 20, 2005 10:00 pm 
Beginner
Beginner

Joined: Sat Sep 25, 2004 12:42 am
Posts: 27
Try closing the entity annotation... e.g. @Entity()


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 25, 2005 12:44 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Hum, weird. 3 solutions:
- you use a very old JDK 5.0
- you're using the wrong class
- I'm insane reviewing my code.

Try to set @Entity before any other annotations.

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 06, 2005 5:29 pm 
Newbie

Joined: Sun Dec 12, 2004 5:52 pm
Posts: 9
I ran into something similar.

In my case, it turned out that because my imports looked like this:

import org.hibernate.annotations.Entity;
import javax.ejb.*;

The @Entity i used wasn't the right one.

So try using fully qualified names:

@org.hibernate.annotations.Entity()
@javax.ejb.Entity()

good luck :-)


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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.