Um problema que ta rolando aki comigo é que nao consigo fazer o hibernate2 rodar uma unica vez.
Antes ele não achava meu properties agora é meu arquivo de conf, que ele não acha na hora de rodar ele so da NOT FOUND, alguem pode me ajudar ai.
Coloquei o jar do hibernate2 no meu classpath, e o properties dele no …jrelibext, será que é isto alguem pode me dar uma LUZ ai.
–>>hibernate.properties
hibernate.connection.driver_class = org.gjt.mm.mysql.Driver
hibernate.connection.url = jdbc:mysql://localhost/test
hibernate.connection.username = root
hibernate.connection.password = 120582
hibernate.connection.pool_size = 25
hibernate.c3p0.minPoolSize=5
hibernate.c3p0.maxPoolSize=20
hibernate.c3p0.timeout=1800
hibernate.c3p0.max_statement=50
hibernate.dialect = net.sf.hibernate.dialect.MySQLDialect
–>>Record.hbm.xml
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping SYSTEM "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd" >
<hibernate-mapping>
<class name="Record" table="teste" >
<id name="cod">
<generator class="increment"/>
</id>
<property name="nome" not-null="true"/>
</class>
</hibernate-mapping>
–>>RecordDAO.java
import net.sf.hibernate.AssertionFailure;
import net.sf.hibernate.FlushMode;
import net.sf.hibernate.Hibernate;
import net.sf.hibernate.Session;
import net.sf.hibernate.SessionFactory;
import net.sf.hibernate.cfg.*;
import net.sf.hibernate.tool.hbm2ddl.SchemaExport;
import java.util.*;
import java.io.*;
public class RecordDAO{
private SessionFactory factory;
public RecordDAO() throws Exception{
factory = new Configuration().buildSessionFactory();
}
public boolean isConnected() throws Exception{
Session session = factory.openSession();
return session.isConnected();
}
public void insert(Record record) throws Exception{
Session session = factory.openSession();
session.save(record);
session.flush();
session.close();
}
public java.util.List getList(String condicao) throws Exception{
Session session = factory.openSession();
java.util.List amigos = session.find( condicao );
session.flush();
session.close();
return amigos;
}
public Record retrieve(String pk) throws Exception{
Session session = factory.openSession();
Record record = (Record)session.load(Record.class, pk);
session.flush();
session.close();
return record;
}
public void delete(Record record) throws Exception{
Session session = factory.openSession();
session.delete(record);
session.flush();
session.close();
}
}
–>>Record.java
import java.math.BigDecimal;
import java.util.Date;
public class Record {
private int id;
private int quantity;
public Record() {}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
–>>Main.java
import java.math.BigDecimal;
import java.sql.*;
import java.util.*;
import java.util.Date;
import java.util.List;
import javax.swing.*;
public class Main {
public static void main(String[] args) throws Exception {
Connection connection = null;
try{
Class.forName( "org.gjt.mm.mysql.Driver" );
//connection = DriverManager.getConnection("jdbc:mysql://localhost/test" ,"root", "120582" );
RecordDAO record = new RecordDAO();
List list = record.getList( "from teste in class Record" );
Enumeration enumerator = Collections.enumeration( list );
while( enumerator.hasMoreElements() ){
Record aux = (Record) enumerator.nextElement();
JOptionPane.showMessageDialog( null, "Codigo: " + aux.getId() +"
Nome: " + aux.getName() );
}
}
catch(ClassNotFoundException cnfex){
cnfex.printStackTrace();
}
catch(SQLException sqlex){
sqlex.printStackTrace();
}
}
}