wood burning stoves 2.0*
The moose likes Object Relational Mapping and the fly likes How to use Hibernate along with GWT instantiation on eclipse 3.2 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "How to use Hibernate along with GWT instantiation on eclipse 3.2" Watch "How to use Hibernate along with GWT instantiation on eclipse 3.2" New topic
Author

How to use Hibernate along with GWT instantiation on eclipse 3.2

sudhansu goyal
Greenhorn

Joined: Nov 28, 2007
Posts: 4
Hello Everybody,
i am making a web application which is based on GWT instantiation.. at server end i want to use hibernate for accessing database but when i run it on eclipse 3.2 having GWT instantiation plug in(after writing all the code of client side and server side including use of hibernate)it is giving this error

Error is org.hibernate.HibernateException: Could not parse configuration: /hibernate.cfg.xml

which comes for these lines in the server side code


SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();
Session session =sessionFactory.openSession();
Manager manager = new Manager(session);
user=manager.searchUser(username);

where user is object of database entity and manager is the class which access the database ...

my hibernate.cfg.xml is as following

///////////////////////////////

<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="connection.url">
jdbc:mysql://localhost:3306/test
</property>
<property name="connection.driver_class">
com.mysql.jdbc.Driver
</property>
<property name="connection.username">
root
</property>
<property name="connection.password">
dexter
</property>
<!-- Set AutoCommit to true -->
<property name="connection.autocommit">
true
</property>
<!-- SQL Dialect to use. Dialects are database specific -->
<property name="dialect">
org.hibernate.dialect.MySQLDialect
</property>
<!-- Mapping files -->
<mapping resource="com/visualbuilder/hibernate/User.hbm.xml" />
</session-factory>
</hibernate-configuration>

///////////////////////////////

what i think that when i run this as GWT application on eclipse 3.2 it is giving this error due to absence of hibernate lib at server end i am not so clear...
if somebody will help me i will be thankful to him...
please reply soonn....
Edvins Reisons
Ranch Hand

Joined: Dec 11, 2006
Posts: 364
Originally posted by sudhansu goyal:

Error is org.hibernate.HibernateException: Could not parse configuration: /hibernate.cfg.xml



This message means that something is wrong with the hibernate.cfg.xml configuration file.
Are there any other messages in the exception stack that point more precisely to what went wrong?
sudhansu goyal
Greenhorn

Joined: Nov 28, 2007
Posts: 4
No there is only single exception that a written previously...
i have used try catch on the code written above session etc..
i think it is due to because server does not find hibernate library at its end
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Hmm. You are probably hidding some of the stacktrace; stacetraces in Java are never one-liners. It unlikely to be down to a missing library, there is a specific error (NoClassDefFoundError) for that sort of issue. Edvins has called it right I think, there is something wrong with your hibernate.cfg.xml. Looking at it though it loks like valid XML and appears to conform to the DTD. Is User.hbm.xml valid and deployed to the correct place?


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17250
    
    6

Along with Paul's thoughts, is your hibernate.cfg.xml file located at the base of your classpath?

Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
sudhansu goyal
Greenhorn

Joined: Nov 28, 2007
Posts: 4
this is my User.hbm.xml

///////////



<?xml version="1.0" encoding='utf-8'?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >

<hibernate-mapping>

<class name="com.visualbuilder.hibernate.User" table="details" >
<id name="User_Name" type="java.lang.String" column="User_Name" >
</id>
<property name="Password" type="java.lang.String" column="Password" length="45" />

</class>

</hibernate-mapping>

///////////

this file ismapping a table details having two columns User_Name and Password both are of type varchar and User_Name is primary key of the database...
my directory structure is as following----

innvu is the GWT project name that a make on eclipse 3.2

innvy
src (folder)
com.innvy.home.register (package)
public (folder)
register.gwt.xml
com.innvy.home.register.client (package)
register.java
registerService.java
registerServiceAsync.java
com.innvy.home.register.server (package)
registerServiceImpl.java
com.visualbuilder.hibernate (package)
User.java
User.hbm.xml
com.visualbuilder.hibernate.client (package)
Manager.java

hibernate.cfg.xml
web.xml
Hibernate_library (Library for hibernate)
Mysql_Library (Library for mysql dbms)
Jre_system_library (Library for jdk)
Gwt library (Library for gwt designer)

i am mapping the User entity in User.java and User.hbm.xml..
the error that i told you was coming when i dont add mysql mibrary in my project..
but when i add it also in my project the error is coming

//////////////////////////////////////

[ERROR] Failure to load module 'com.innvy.home.register.register'
java.lang.NoSuchMethodError: org.eclipse.jdt.internal.compiler.ast.TypeDeclaration.kind()I
at com.google.gwt.dev.jdt.TypeOracleBuilder.isInterface(TypeOracleBuilder.java:481)
at com.google.gwt.dev.jdt.TypeOracleBuilder.processType(TypeOracleBuilder.java:531)
at com.google.gwt.dev.jdt.TypeOracleBuilder.access$000(TypeOracleBuilder.java:93)
at com.google.gwt.dev.jdt.TypeOracleBuilder$2.visit(TypeOracleBuilder.java:410)
at org.eclipse.jdt.internal.compiler.ast.TypeDeclaration.traverse(TypeDeclaration.java:1007)
at org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration.traverse(CompilationUnitDeclaration.java:305)
at com.google.gwt.dev.jdt.TypeOracleBuilder.build(TypeOracleBuilder.java:395)
at com.google.gwt.dev.cfg.ModuleDef.getTypeOracle(ModuleDef.java:294)
at com.google.gwt.dev.cfg.ModuleDef.refresh(ModuleDef.java:359)
at com.google.gwt.dev.cfg.ModuleDefLoader.loadFromClassPath(ModuleDefLoader.java:86)


//////////////////////////////////////

i want to implement GWT RPC and simultaneously want to access database at server side(registerServiceImpl.java) using hibernate.. i think now a make clear almost of my project.. if somebody could help me the i will be thankful to him..
sudhansu goyal
Greenhorn

Joined: Nov 28, 2007
Posts: 4
Directory Structure is as following---

innvy
#--#src (main folder containg all the things)
------com.innvy.home.register (package)
>----------------------public (folder)
>----------------------register.gwt.xml
------com.innvy.home.register.client (package)
>----------------------register.java
>----------------------registerService.java
>----------------------registerServiceAsync.java
------com.innvy.home.register.server (package)
>----------------------registerServiceImpl.java
------com.visualbuilder.hibernate (package)
>----------------------User.java
>----------------------User.hbm.xml
------com.visualbuilder.hibernate.client (package)
>----------------------Manager.java
------hibernate.cfg.xml (file)
------web.xml (filr)
Hibernate_library (Library for hibernate)
Mysql_Library (Library for mysql dbms)
Jre_system_library (Library for jdk)
Gwt library (Library for gwt designer)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to use Hibernate along with GWT instantiation on eclipse 3.2