Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

where is the error

 
Samanthi perera
Ranch Hand
Posts: 510
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
this is my file structure


this is my config.xml





this is my main class


in this main class line AnnotationConfiguration().configure().buildSessionFactory(); gives this error



 
Devaka Cooray
ExamLab Creator
Marshal
Pie
Posts: 4588
302
Chrome Eclipse IDE Google App Engine IntelliJ IDE jQuery Postgres Database Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Samanthi perera wrote:AnnotationConfiguration().configure().buildSessionFactory()

AnnotationConfiguration is a class. How do you create a new object from a class?
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please post only the code relevant to the question. This is a compilation error--no configuration file is involved.
 
Samanthi perera
Ranch Hand
Posts: 510
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Okay. See the difference? You were already told what the problem was, and the code in the link is not the same as yours where the problem is.
 
Jaikiran Pai
Marshal
Pie
Posts: 10447
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Did you recheck the code with the example that you took it from? Clearly it's not the same. And Devaka already told you what the problem is with that piece of code.
 
Samanthi perera
Ranch Hand
Posts: 510
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ok.I have added new keyword to main class.

anyway when i run the example it gives this error.


I think it is not creating sessionfactory ?
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hard to say, since you don't post the rest of the stack trace. Do you have the annotated class?
 
Samanthi perera
Ranch Hand
Posts: 510
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I debug the code

java.lang.ClassNotFoundException
org/hibernate/cfg/AnnotationConfiguration
null

 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And the libraries you're deploying are...?

Come on: we've been over this stuff many times: TellTheDetails.
 
Samanthi perera
Ranch Hand
Posts: 510
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
mysql-connector-java-5.0.8-bin
hibernate-annotations
hibernate-commons-annotations
hibernate3
ejb3-persistence
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm skeptical, because the error *clearly* indicates which class isn't found.
 
Samanthi perera
Ranch Hand
Posts: 510
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
now it is change the error


anyway my Configuration.cfx.xml file in the project folderr
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It should be on the classpath. I don't understand why you have to make this so difficult, over and over.
 
Samanthi perera
Ranch Hand
Posts: 510
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am using Eclips IDE.
I creatred the config file using
File -> New->Other ->Hibernate -> Hibernate Configuration File
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So what? It needs to be on the classpath.
 
Samanthi perera
Ranch Hand
Posts: 510
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How to add it to classpath?
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Put it in your source directory?
 
Samanthi perera
Ranch Hand
Posts: 510
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i have added.
Still have errors.


i add a debug line in
session=new AnnotationConfiguration().configure().buildSessionFactory();
after debug pointer come to this line i press F5.
then this error comes.
 
Samanthi perera
Ranch Hand
Posts: 510
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i have added 3306 to the url in config.xml

<property name="hibernate.connection.url">jdbc:mysql://localhost:3306/school</property>

the error is still there
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you see the error? There's a class missing.
 
Samanthi perera
Ranch Hand
Posts: 510
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Which jar shuold i add?
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


I think if you don't know how to figure that out you should take a step back before trying to deal with an ORM, because if you can't figure out how to fix the *simple* things when something goes wrong fixing the *complicated* stuff that can happen in Hibernate is going to be a pretty tall order.

- What class is missing?
- What jar is it in (and how do you know)?
- If you *think* you're deploying that jar, how can you find out if you're right?
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The answer must be 42

Mark
 
Samanthi perera
Ranch Hand
Posts: 510
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
what do you mean 42?
 
Devaka Cooray
ExamLab Creator
Marshal
Pie
Posts: 4588
302
Chrome Eclipse IDE Google App Engine IntelliJ IDE jQuery Postgres Database Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mark Spritzler wrote:The answer must be 42

Exactly
 
Samanthi perera
Ranch Hand
Posts: 510
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i don't understand what is mean by 42.
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34839
369
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Samanthi perera wrote:i don't understand what is mean by 42.

42 is the answer to the ultimate question (life the universe and everything) in the Hitchhikers Guide to the Galaxy. It is used as a joke.
 
Shashank Acharya
Greenhorn
Posts: 21
Android Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


I tried this in Netbeans 6.8 & I hope it will work in Eclipse.

Another thing please create one HibernateUtil.java in Project as shown at Vaannilla Tutorial.
Don't try to create SessionFactory at main class.Use HibernateUtil class getSessionFactory() Method.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic