Galera,
Estou comecando agora a estudar o hibernate e já me deparei com um erro que eu não entendi nada!! Eu adcionei a biblioteca do hibernate que já vem no NetBeans. Será que é isso? Se for, eu entri no site do hibernate e fiquei todo perdido no que tenho que baixar.
[quote]run:
22/08/2010 22:46:04 org.hibernate.cfg.annotations.Version
INFO: Hibernate Annotations 3.3.1.GA
22/08/2010 22:46:04 org.hibernate.cfg.Environment
INFO: Hibernate 3.2.5
22/08/2010 22:46:04 org.hibernate.cfg.Environment
INFO: hibernate.properties not found
22/08/2010 22:46:04 org.hibernate.cfg.Environment buildBytecodeProvider
INFO: Bytecode provider name : cglib
22/08/2010 22:46:04 org.hibernate.cfg.Environment
INFO: using JDK 1.4 java.sql.Timestamp handling
22/08/2010 22:46:04 org.hibernate.cfg.AnnotationBinder bindClass
INFO: Binding entity from annotated class: firsthibernateapp.Users
22/08/2010 22:46:04 org.hibernate.cfg.annotations.EntityBinder bindTable
INFO: Bind entity firsthibernateapp.Users on table testehibernate.users
22/08/2010 22:46:04 org.hibernate.cfg.AnnotationConfiguration secondPassCompile
INFO: Hibernate Validator not found: ignoring
22/08/2010 22:46:04 org.hibernate.connection.C3P0ConnectionProvider configure
INFO: C3P0 using driver: com.mysql.jdbc.Driver at URL: jdbc:mysql://localhost:3306/testehibernate
22/08/2010 22:46:04 org.hibernate.connection.C3P0ConnectionProvider configure
INFO: Connection properties: {user=root, password=****}
22/08/2010 22:46:04 org.hibernate.connection.C3P0ConnectionProvider configure
INFO: autocommit mode: false
Exception in thread “main” java.lang.NoClassDefFoundError: com/mchange/v2/c3p0/DataSources
at org.hibernate.connection.C3P0ConnectionProvider.configure(C3P0ConnectionProvider.java:154)
at org.hibernate.connection.ConnectionProviderFactory.newConnectionProvider(ConnectionProviderFactory.java:124)
at org.hibernate.connection.ConnectionProviderFactory.newConnectionProvider(ConnectionProviderFactory.java:56)
at org.hibernate.cfg.SettingsFactory.createConnectionProvider(SettingsFactory.java:414)
at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:62)
at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:2009)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1292)
at org.hibernate.cfg.AnnotationConfiguration.buildSessionFactory(AnnotationConfiguration.java:859)
at firsthibernateapp.Main.main(Main.java:31)
Caused by: java.lang.ClassNotFoundException: com.mchange.v2.c3p0.DataSources
at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:303)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:316)
… 9 more
Java Result: 1
CONSTRUÍDO COM SUCESSO (tempo total: 0 segundos)[/quote]
Minhas classes estão assim:
[code]/*
- To change this template, choose Tools | Templates
- and open the template in the editor.
*/
package firsthibernateapp;
import java.io.Serializable;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
/**
*
-
@author Administrador
*/
@Entity
@Table(name=“testehibernate.users”)
public class Users implements Serializable {
@Id
private Integer id;
@Column(name="name")
private String myName;
public Users()
{
}
public Integer getId()
{
return id;
}
public void setId(Integer id)
{
this.id = id;
}
public String getMyName()
{
return myName;
}
public void setMyName(String myName)
{
this.myName = myName;
}
@Override
public boolean equals(Object obj)
{
if (obj == null)
{
return false;
}
if (getClass() != obj.getClass())
{
return false;
}
final Users other = (Users) obj;
if (this.id != other.id && (this.id == null || !this.id.equals(other.id)))
{
return false;
}
return true;
}
@Override
public int hashCode()
{
int hash = 3;
hash = 67 * hash + (this.id != null ? this.id.hashCode() : 0);
return hash;
}
}
[/code]
[code]/*
- To change this template, choose Tools | Templates
- and open the template in the editor.
*/
package firsthibernateapp;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.AnnotationConfiguration;
/**
*
-
@author Administrador
*/
public class Main {/**
-
@param args the command line arguments
*/
public static void main(String[] args) {SessionFactory sf = new AnnotationConfiguration()
.setProperty(“hibernate.dialect”, “org.hibernate.dialect.MySQLDialect”)
.setProperty(“hibernate.connection.driver_class”, “com.mysql.jdbc.Driver”)
.setProperty(“hibernate.connection.url”, “jdbc:mysql://localhost:3306/testehibernate”)
.setProperty(“hibernate.connection.username”, “root”)
.setProperty(“hibernate.connection.password”, “x123456”)
.setProperty(“hibernate.show_sql”, “true”)
.setProperty(“hibernate.format_sql”, “true”)
.setProperty(“hibernate.c3p0.acquire_increment”, “1”)
.setProperty(“hibernate.c3p0.idle_test_period”, “100”)
.setProperty(“hibernate.c3p0.max_size”, “10”)
.setProperty(“hibernate.c3p0.max_statements”, “0”)
.setProperty(“hibernate.c3p0.min_size”, “5”)
.setProperty(“hibernate.c3p0.timeout”, “100”)
.addAnnotatedClass(Users.class)
.buildSessionFactory();Session session = sf.openSession();
session.beginTransaction();Users user = (Users) session.get(Users.class, 1);
System.out.println("The user is: "+user.getMyName());session.getTransaction().commit();
session.close();
sf.close();
}
-
}
[/code]
Agradeço antecipadamente!