Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

hbm file version working but annotation not

 
Samanthi perera
Ranch Hand
Posts: 510
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am using Netbenas IDE.
I did same example using hbm file and annotation.

here my config file


here my hbm file


here is my User class


here is main class

this example is working fine.No problem.


anyway i try same with annotation
here my annotation class


then it gives this error

 
Samanthi perera
Ranch Hand
Posts: 510
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i change my User class


still i am getting error

 
Anbarasu Aladiyan
Ranch Hand
Posts: 182
Chrome Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Samanthi perera,
You have added your hbm file version but not the annotated class.
When you are using annotated version, it must be specified like or using the package.
 
Samanthi perera
Ranch Hand
Posts: 510
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
here is my new config file


still i get error

 
Anbarasu Aladiyan
Ranch Hand
Posts: 182
Chrome Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Replace above line by then try
 
Samanthi perera
Ranch Hand
Posts: 510
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ya .i did that .
then it gives me tyhis error

i don't know why it can't find my class.
 
Christian Dillinger
Ranch Hand
Posts: 197
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hibernate Annotations comes with a really great documentation for beginners. Read it and you'll see, that you have to write something like that



and not like that



The unfriendly part in "a friendly place for Java greenhorns":
Did you ever hear about such things called "tutorial" or "documentation"? Do you really really really want to learn Java, Hibernate and the other things by posting each and every little problem into forums? You've been told that in some other threads... RTFM! Or try google at first.
 
Anbarasu Aladiyan
Ranch Hand
Posts: 182
Chrome Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Samanthi perera,
replace above line by
Use . not /.
 
Samanthi perera
Ranch Hand
Posts: 510
 
Christian Dillinger
Ranch Hand
Posts: 197
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The solution to you question is in that tutorial...
 
Samanthi perera
Ranch Hand
Posts: 510
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
no.
Still i have the error


 
Christian Dillinger
Ranch Hand
Posts: 197
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maybe you should repost your configuration, your mapped class and your main class. Because no one knows what you changed between to different runs. E.g. one of your stacktraces contained this: "people/User.hbm.xml". Now you class is Annotation.User or isn't it or is it or not?
 
Samanthi perera
Ranch Hand
Posts: 510
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
this is my config file


User class


util class


error

 
Christian Dillinger
Ranch Hand
Posts: 197
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are several classes called Annotation. Maybe Hibernate assumes Annotation.User to be an inner class of some of these classes. E.g. java.text.Annotation. Rename your package to annotation. Naming conventions aren't always useless... In this special case: each part of the fully qualified package-name are written in lower-case.
 
Anbarasu Aladiyan
Ranch Hand
Posts: 182
Chrome Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check the Entity package you are importingI think it must be
 
Samanthi perera
Ranch Hand
Posts: 510
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
config class


user class


Now it is working.
 
Samanthi perera
Ranch Hand
Posts: 510
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
config class


user class


Now it is working.
 
Anbarasu Aladiyan
Ranch Hand
Posts: 182
Chrome Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
SessionFactory sessionFack=new AnnotationConfiguration().configure().buildSessionFactory();
I think you are not using the cfg.xml file
 
Samanthi perera
Ranch Hand
Posts: 510
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
why did you say that?
what is the meanning of that?
 
Anbarasu Aladiyan
Ranch Hand
Posts: 182
Chrome Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's my guess. I think you are using two classes for building session factory. One is for using cfg.xml file and another one is for annotated version.
If you are using annotated version for building session factory then no need to worry about your cfg file.
 
Samanthi perera
Ranch Hand
Posts: 510
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
this is my user class


this is my cfg.xml


If you are using these two classes can you tell me how to make a SessionFactory using
1)only cfg.xml
2)only annotated class
 
Anbarasu Aladiyan
Ranch Hand
Posts: 182
Chrome Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think you are not getting my point. post "HibernateUtil" and "AnnotationConfiguration" class codes.
 
Samanthi perera
Ranch Hand
Posts: 510
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
aha.then it is ok.
I am not using the Hibernate util class.I mean in this example.
anyway it is here.

 
Christian Dillinger
Ranch Hand
Posts: 197
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Anbarasu Aladiyan wrote:I think you are not getting my point. post "HibernateUtil" and "AnnotationConfiguration" class codes.


Why are you doing this? If you want to help him, don't ask him for code of AnnotationConfiguration. That's a Hibernate class not his own.
 
Anbarasu Aladiyan
Ranch Hand
Posts: 182
Chrome Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Christian Dillinger wrote:
Anbarasu Aladiyan wrote:I think you are not getting my point. post "HibernateUtil" and "AnnotationConfiguration" class codes.


Why are you doing this? If you want to help him, don't ask him for code of AnnotationConfiguration. That's a Hibernate class not his own.
There are two ways to build the session factory. Using cfg.xml file and another one is without using the cfg xml file (in which we can give the configuration details using java code. Which is likely used when we do annotated version).
If we use annotated version then obliviously it has nothing to do with cfg file (since we can configuration details using java code when we build session factory)

Also I don't think that is possible to help without seeing the code
 
Christian Dillinger
Ranch Hand
Posts: 197
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Anbarasu Aladiyan wrote:There are two ways to build the session factory. Using cfg.xml file and another one is without using the cfg xml file (in which we can give the configuration details using java code. Which is likely used when we do annotated version).
If we use annotated version then obliviously it has nothing to do with cfg file (since we can configuration details using java code when we build session factory)

Also I don't think that is possible to help without seeing the code


Why should anyone want to get rid of the cfg.xml completly just because he uses annotated entities? You because you CAN configure your annotated classes programmatically it's by far not OBVIOUS that you do not want a hibernate.cfg.xml. You need the class AnnotationConfiguration if you want to use annotated classes, that's the whole difference.
What is easier when you add a new entity? Insert one line in a textfile without recompiling or change code in another class?

BTW we seen his complete code over and over again in the thread and the problem finally got solved...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic