my dog learned polymorphism*
The moose likes Other Application Frameworks and the fly likes An exception throws in hibernate Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Other Application Frameworks
Bookmark "An exception throws in hibernate" Watch "An exception throws in hibernate" New topic
Author

An exception throws in hibernate

Mohamad Ibrahim
Greenhorn

Joined: Jun 26, 2007
Posts: 26
I am trying to connect to mysql using hibernate and i get this exception


java.lang.NoClassDefFoundError: java/util/concurrent/ConcurrentMap

thanks
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Looks like you are probably trying to run Hibernate with an obsolete version of the JDK.


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Mohamad Ibrahim
Greenhorn

Joined: Jun 26, 2007
Posts: 26
Paul Sturrock wrote:Looks like you are probably trying to run Hibernate with an obsolete version of the JDK.

JDK 1.6 it is not obsolete
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Indeed not. However, it contains that class. If you were running Hibernate with JDK 1.6 you would not get a NoClassDefFoundError. I'd ckech how you run Hibernate, make sure you are using the version of java you think you are.
Mohamad Ibrahim
Greenhorn

Joined: Jun 26, 2007
Posts: 26
Paul Sturrock wrote:Indeed not. However, it contains that class. If you were running Hibernate with JDK 1.6 you would not get a NoClassDefFoundError. I'd ckech how you run Hibernate, make sure you are using the version of java you think you are.

I am sure , it works fine with other applications.
i am running hibernate as desktop application
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

The fact remains that if you're running under a 1.6 JVM, the class exists, and that isn't the error you'll get.

Please detail precisely how you're running the app, including all relevant path, classpath, etc. info.
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Well, sorry to persist with this, but if you were running it with that version of the JDK you would not see this error. I notice you have asked another question about WebSphere 6.1 elsewhere in the ranch, which coincidently does not support JDK 1.6. You sure you've not just mistakenly used the wrong JDK?
Mohamad Ibrahim
Greenhorn

Joined: Jun 26, 2007
Posts: 26
David Newton wrote:The fact remains that if you're running under a 1.6 JVM, the class exists, and that isn't the error you'll get.

Please detail precisely how you're running the app, including all relevant path, classpath, etc. info.



package main;


import java.util.Iterator;
import java.util.List;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;


public class Base
{

public static void main(String[] args)
{
try
{
Configuration conf = new Configuration().addClass(Users.class);
SessionFactory sf = conf.configure().buildSessionFactory() ;

// Users us = new Users() ;
//// us.setUsername("boodi") ;
//// us.setPassword("123456") ;
//
//
//
// Session session = sf.openSession();
//
// session.load(us , new Integer(1));
// System.out.println(us.getUsername());
// session.flush() ;
// session.close() ;
//
// //Transaction tr = session.beginTransaction() ;
// System.out.println(session.get(Users.class , new Users().getUsername()));
// tr.commit() ;
// tr = null ;

Session session = sf.openSession() ;
Transaction trns = session.beginTransaction() ;
List list = (List)session.get("from names as n where m.password = 123" , Users.class) ;
for(Iterator it = list.iterator() ; it.hasNext() ;)
{
Users us = (Users)it.next() ;
System.out.println(us.getUsername()) ;
}
trns.commit() ;
session.close() ;
}
catch (Exception e) {
e.printStackTrace() ;
}
}
}



there is a bean called Users


Users.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="main.Users" table="names">
<id name="id" type="int" unsaved-value="null">
<column name="id" sql-type="int" not-null="true"></column>
<generator class="increment"></generator>
</id>
<property name="username" column="username"></property>
<property name="password" column="password"></property>
</class>

</hibernate-mapping>



log4j
### direct log messages to stdout ###
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n

### set log levels - for more verbose logging change 'info' to 'debug' ###

log4j.rootLogger=debug, stdout

log4j.logger.org.hibernate=info
#log4j.logger.org.hibernate=debug

### log HQL query parser activity
#log4j.logger.org.hibernate.hql.ast.AST=debug

### log just the SQL
log4j.logger.org.hibernate.SQL=debug

### log JDBC bind parameters ###
log4j.logger.org.hibernate.type=info

### log schema export/update ###
log4j.logger.org.hibernate.tool.hbm2ddl=info

### log HQL parse trees
#log4j.logger.org.hibernate.hql=debug

### log cache activity ###
log4j.logger.org.hibernate.cache=info

### log transaction activity
#log4j.logger.org.hibernate.transaction=debug

### log JDBC resource acquisition
#log4j.logger.org.hibernate.jdbc=debug

### enable the following line if you want to track down connection ###
### leakages when using DriverManagerConnectionProvider ###
#log4j.logger.org.hibernate.connection.DriverManagerConnectionProvider=trace




hibernate.cfg.xml
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="connection.url">jdbc:mysql://localhost:3306/users</property>
<property name="connection.username">root</property>
<property name="connection.password"></property>
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="show_sql">true</property>

</session-factory>

</hibernate-configuration>



and the jars are
commons-collections.jar
commons-collections-3.1.jar
commons-digester.jar
commons-fileupload.jar
commons-lang.jar
commons-logging.jar
commons-validator.jar
hibernate3.jar
hsqldb.jar
jakarta-oro.jar
mysql-connector-java-5.0.8-bin.jar
struts.jar
taglibs-datetime.jar
taglibs-mailer.jar
taglibs-string.jar
utility.jar
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

David Newton wrote:Please detail precisely how you're running the app, including all relevant path, classpath, etc. info.

What you posted is great, but entirely unrelated to what we need to know in order to help.

Also, in the future, when posting code or configuration, please UseCodeTags. Unformatted code and configuration is unnecessarily difficult to read.
Mohamad Ibrahim
Greenhorn

Joined: Jun 26, 2007
Posts: 26
David Newton wrote:
David Newton wrote:Please detail precisely how you're running the app, including all relevant path, classpath, etc. info.

What you posted is great, but entirely unrelated to what we need to know in order to help.

Also, in the future, when posting code or configuration, please UseCodeTags. Unformatted code and configuration is unnecessarily difficult to read.



In the same path of Base.class there are log4j.properties and Users.hbm.xml , and hibernate.cfg.xml is under the root of classes .
I develop my application using ibm rational application developer , so i run the Base class as Java Application .
The structure of the application is a web application but i try to test my code as desktop application
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Eclipse will tell you the details of what you are running if you check the run configuration. I'd look there to make 100% sure your are running the JDK you think you are.


I develop my application using ibm rational application developer

If you are using a version that runs WAS 6.1 and you have not changed the defaults, then you are probably not running JDK 1.6 for the reason I mentioned earlier.
Mohamad Ibrahim
Greenhorn

Joined: Jun 26, 2007
Posts: 26
Paul Sturrock wrote:Eclipse will tell you the details of what you are running if you check the run configuration. I'd look there to make 100% sure your are running the JDK you think you are.


I develop my application using ibm rational application developer

If you are using a version that runs WAS 6.1 and you have not changed the defaults, then you are probably not running JDK 1.6 for the reason I mentioned earlier.


I am very sure with the JDK plus i have a lot of applications working fine with this JDK .
plus i deploy my work on another machine which the WAS 6.1 is installed
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Have you checked? Can you post a picture of what eclipse shows in its run configuration for your application?

The reason for your error is you are not running your program with JDK 1.6.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Mohamad Ibrahim wrote:I develop my application using ibm rational application developer, so i run the Base class as Java Application. The structure of the application is a web application but i try to test my code as desktop application

For some reason we're not communicating.

The bottom line is that you're not running under a 1.6 JVM, no matter how much you think you are. As I don't know how you're running the app, I have no way of knowing the path of the JDK you're using, how your IDE you're running it under is configured, etc.
Mohamad Ibrahim
Greenhorn

Joined: Jun 26, 2007
Posts: 26
Paul Sturrock wrote:Have you checked? Can you post a picture of what eclipse shows in its run configuration for your application?

The reason for your error is you are not running your program with JDK 1.6.




[Thumbnail for 2.JPG]

[Thumbnail for 1.JPG]

David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

That just shows it's installed and configured, not (a) how you're running your program, and (b) the program's runtime configuration.
Mohamad Ibrahim
Greenhorn

Joined: Jun 26, 2007
Posts: 26
David Newton wrote:That just shows it's installed and configured, not (a) how you're running your program, and (b) the program's runtime configuration.



plus i dont know whats program's runtime configuration


[Thumbnail for 3.JPG]

Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

From the Run menu, select "Runtime Configurations..." and find the one for your application.
Mohamad Ibrahim
Greenhorn

Joined: Jun 26, 2007
Posts: 26
Paul Sturrock wrote:From the Run menu, select "Runtime Configurations..." and find the one for your application.



Thanks very much for every one tried to help me .
in the run menu nothing called Runtime Configuration , but there is Preferences from window menu


[Thumbnail for 4.JPG]

Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

So that is the default JDK Eclipse is using, which will be the one you are running your program with, unless you've overridden it in the project settings or in the run configuration*. But it can't be the one your program is running with (for the reason detailed above).

(*Sorry, a typo I should have said "Run Configurations...")
Mohamad Ibrahim
Greenhorn

Joined: Jun 26, 2007
Posts: 26
Paul Sturrock wrote:So that is the default JDK Eclipse is using, which will be the one you are running your program with, unless you've overridden it in the project settings or in the run configuration*. But it can't be the one your program is running with (for the reason detailed above).

(*Sorry, a typo I should have said "Run Configurations...")



if the runtime is not correct how can i fix it


[Thumbnail for 5.JPG]

 
 
subject: An exception throws in hibernate
 
Similar Threads
What are the jar files required for jpa and hibernate in Weblogic 9.2
Problem with Hibernate test application
Concurrent updates does not throw any exception
hibernate dialect
Hibernate: org.springframework.beans.factory.BeanCreationException