-->
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.  [ 2 posts ] 
Author Message
 Post subject: Exception in thread "main" java.lang.NoSuchMethodError
PostPosted: Tue May 19, 2009 2:32 am 
Newbie

Joined: Sat May 09, 2009 2:37 am
Posts: 3
Please solve the problem


hibernate-cfg.xml:


<?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="hibernate.bytecode.use_reflection_optimizer">false</property>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.password"></property>
<property name="hibernate.connection.url">jdbc:mysql://172.18.226.38:3306/hibernate</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
<mapping class="net.roseindia.Product"/>

</session-factory>
</hibernate-configuration>


Product.java:

package net.roseindia;

// Generated May 18, 2009 7:40:50 PM by Hibernate Tools 3.2.4.GA

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;

/**
* Product generated by hbm2java
*/
@Entity
@Table(name = "product", catalog = "hibernate")
public class Product implements java.io.Serializable {

private int prodid;
private String prodname;
private float prodprice;

public Product() {
}

public Product(int prodid, String prodname, float prodprice) {
this.prodid = prodid;
this.prodname = prodname;
this.prodprice = prodprice;
}

@Id
@Column(name = "PRODID", unique = true, nullable = false)
public int getProdid() {
return this.prodid;
}

public void setProdid(int prodid) {
this.prodid = prodid;
}

@Column(name = "PRODNAME", nullable = false, length = 15)
public String getProdname() {
return this.prodname;
}

public void setProdname(String prodname) {
this.prodname = prodname;
}

@Column(name = "PRODPRICE", nullable = false, precision = 12, scale = 0)
public float getProdprice() {
return this.prodprice;
}

public void setProdprice(float prodprice) {
this.prodprice = prodprice;
}

}


ProductData.java

package net.roseindia;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import net.roseindia.Product;
import org.hibernate.util.*;
import org.hibernate.cfg.AnnotationConfiguration;
import org.hibernate.cfg.Configuration;


public class ProductData {


public static void main(String[] args)throws Exception {
// TODO Auto-generated method stub
/** Getting the Session Factory and session */
AnnotationConfiguration config =
new AnnotationConfiguration();
config.addAnnotatedClass(net.roseindia.Product.class);
config.configure();

/*The SessionFactory is obtained
through the config object*/
SessionFactory factory =
config.buildSessionFactory();
Session session=factory.openSession();
Transaction tx=session.beginTransaction();

/** Creating Pojo */
Product pojo = new Product();
pojo.setProdid(new Integer(5));
pojo.setProdname("XYZ");
/** Saving POJO */
session.save(pojo);
/** Commiting the changes */
tx.commit();
System.out.println("Record Inserted");
/** Closing Session */
session.close();
}

}


I am getting error like this:

Exception in thread "main" java.lang.NoSuchMethodError: org.hibernate.util.ReflectHelper.classForName(Ljava/lang/String;Ljava/lang/Class;)Ljava/lang/Class;
at org.hibernate.cfg.AnnotationConfiguration.buildSessionFactory(AnnotationConfiguration.java:752)
at net.roseindia.ProductData.main(ProductData.java:30)


Top
 Profile  
 
 Post subject: Re: Exception in thread "main" java.lang.NoSuchMethodError
PostPosted: Tue May 19, 2009 3:42 am 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
You are probably mixing incompatible versions of hibernate core and annotations.

_________________
Sanne
http://in.relation.to/


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