Ajuda com Hibernate

27 respostas
J

Pessoal, alguem poderia me dar uma ajuda com o Hibernate, dando-me alguns passos ou indicando material de estudo? sou iniciante tanto no java quanto no hibernate e não consigo fazer o mesmo funcionar, tentei rodar alguns exemplos que vieram com o proprio hibernate e naum rolou, tentei seguir um artigo aqui do GUJ mesmo, feito pra versao 1 do hibernate, adaptei pra versao 2, mas tb tive problemas…alguem possui algum material do tipo for dummies?

valeu…

27 Respostas

aborges

Que tipo de problemas vc realmente teve ? Qt vc conhece da linhagem Java?

J

comecei a trabalhar com java ha cerca de 1 mes, comecei fazendo exemplos q lidassem com arquivos, depois passei para sockets e agora fiz uma aplicacao cliente-servidor utilizando xml-rpc, nesse ponto q entraria o hibernate, pois pretendo usa-lo para conectar ao BD com as requisicoes vindas atraves do xml-rpc.
O erro q ocorre qdo tento rodar a aplicacao de exemplo do artigo q usei como base eh esse:

Exception in thread main java.lang.NoClassDefFoundError: org/dom4j/Attribute

at AmigoDAO.(AmigoDAO.java:10)

at Chama.main(Chama.java:4)

sendo q possuo essa essa classe no meu CLASSPATH

valeu

TedLoprao

Tem certeza que colocou o dom4j.jar no classpath??? A princípio é isso!!!

F

Com certeza é isso :smiley:

J

Esta no CLASSPATH, mas pra garantir coloquei lah no j2sdk mesmo, aih deu outro erro relativo a commons-logging, coloquei esse jar lah tb, aih deu o seguinte erro:

log4j:WARN No appenders could be found for logger (net.sf.hibernate.cfg.Environment).

log4j:WARN Please initialize the log4j system properly.

Exception in thread main java.lang.NoClassDefFoundError: org/apache/commons/collections/SequencedHashMap

at net.sf.hibernate.mapping.PersistentClass.(PersistentClass.java:30)

at net.sf.hibernate.mapping.RootClass.(RootClass.java:16)

at net.sf.hibernate.cfg.Binder.bindRoot(Binder.java:1242)

at net.sf.hibernate.cfg.Configuration.add(Configuration.java:249)

at net.sf.hibernate.cfg.Configuration.addInputStream(Configuration.java:285)

at net.sf.hibernate.cfg.Configuration.addClass(Configuration.java:351)

at AmigoDAO.(AmigoDAO.java:11)

at Chama.main(Chama.java:4)

valeu pessoal, toh realmente apanhando nesse inicio…

_fs

Também tem que colocar o common-collections no classpath.

Cara, pega todos os jars que tem no diretorio LIB do hibernate e coloque no classpath da sua aplicação.

Cara, essa Exception

java.lang.NoClassDefFoundError:

indica que alguém tentou instanciar uma classe, e ela não foi encontrada.

J

fiz isso, olha o q retornou:

log4j:WARN No appenders could be found for logger (net.sf.hibernate.cfg.Environment).

log4j:WARN Please initialize the log4j system properly.

Exception in thread main net.sf.hibernate.HibernateException: could not instantiate CacheProvider: net.sf.ehcache.hibernate.Provider

at net.sf.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:133)

at net.sf.hibernate.cfg.Configuration.buildSettings(Configuration.java:1132)

at net.sf.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:766)

at AmigoDAO.(AmigoDAO.java:15)

at Chama.main(Chama.java:4)

Caused by: java.lang.ClassNotFoundException: net.sf.ehcache.hibernate.Provider

at java.net.URLClassLoader$1.run(URLClassLoader.java:199)

at java.security.AccessController.doPrivileged(Native Method)

at java.net.URLClassLoader.findClass(URLClassLoader.java:187)

at java.lang.ClassLoader.loadClass(ClassLoader.java:289)

at java.lang.ClassLoader.loadClass(ClassLoader.java:235)

at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:302)

at java.lang.Class.forName0(Native Method)

at java.lang.Class.forName(Class.java:141)

at net.sf.hibernate.util.ReflectHelper.classForName(ReflectHelper.java:102)

at net.sf.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:130)

 4 more

valeu…

TedLoprao

Adivinha!!!
Faltou o ehcache.jar!!!

Dentro da pasta lib do hibernate vc tem o arquivo README que tem a lista de jars que tu tm que colocar no classpath!!!

Fallow

_fs

cara, de novo … você colocou o ehcache no seu classpath?

sério, coloca todos os jars do diretório lib do hibernate no classpath da sua aplicação.

J

acabei de fazer isso, joguei todo o conteudo do hibernate/lib pro j2sdk/jre/lib/ext, apesar de eu jah ter posto o hibernate/lib no CLASSPATH, e ainda dah erro:

log4j:WARN No appenders could be found for logger (net.sf.hibernate.cfg.Environment).

log4j:WARN Please initialize the log4j system properly.

Exception in thread main net.sf.hibernate.PropertyNotFoundException: Could not find a getter for endereco in class Amigo

at net.sf.hibernate.property.BasicPropertyAccessor.getGetter(BasicPropertyAccessor.java:182)

at net.sf.hibernate.mapping.Property.getGetter(Property.java:175)

at net.sf.hibernate.persister.AbstractEntityPersister.(AbstractEntityPersister.java:733)

at net.sf.hibernate.persister.EntityPersister.(EntityPersister.java:714)

at net.sf.hibernate.persister.PersisterFactory.createClassPersister(PersisterFactory.java:42)

at net.sf.hibernate.impl.SessionFactoryImpl.(SessionFactoryImpl.java:137)

at net.sf.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:768)

at AmigoDAO.(AmigoDAO.java:15)

at Chama.main(Chama.java:4)

valeu pessoal…

TedLoprao

Agora, aparentemente a sua classe amigo foi mapeada como possuindo uma propriedade endereco, mas a classe amigo não possui o método getEndereco()…

J

realmente faltava esse metodo, adicionei ele e agora me retorna esse erro:

log4j:WARN No appenders could be found for logger (net.sf.hibernate.cfg.Environment).

log4j:WARN Please initialize the log4j system properly.

Exception in thread main java.lang.UnsupportedOperationException: The user must supply a JDBC connection

at net.sf.hibernate.connection.UserSuppliedConnectionProvider.getConnection(UserSuppliedConnectionProvider.java:32)

at net.sf.hibernate.impl.BatcherImpl.openConnection(BatcherImpl.java:278)

at net.sf.hibernate.impl.SessionImpl.connect(SessionImpl.java:3297)

at net.sf.hibernate.impl.SessionImpl.connection(SessionImpl.java:3277)

at net.sf.hibernate.impl.BatcherImpl.prepareStatement(BatcherImpl.java:61)

at net.sf.hibernate.impl.BatcherImpl.prepareStatement(BatcherImpl.java:56)

at net.sf.hibernate.impl.BatcherImpl.prepareBatchStatement(BatcherImpl.java:109)

at net.sf.hibernate.persister.EntityPersister.insert(EntityPersister.java:460)

at net.sf.hibernate.persister.EntityPersister.insert(EntityPersister.java:442)

at net.sf.hibernate.impl.ScheduledInsertion.execute(ScheduledInsertion.java:29)

at net.sf.hibernate.impl.SessionImpl.executeAll(SessionImpl.java:2407)

at net.sf.hibernate.impl.SessionImpl.execute(SessionImpl.java:2360)

at net.sf.hibernate.impl.SessionImpl.flush(SessionImpl.java:2229)

at AmigoDAO.insert(AmigoDAO.java:20)

at Chama.main(Chama.java:11)

parece-me um problema de mapeamento com o driver JDBC eh isso? segue o arquivo de configuracao q usei:

hibernate.connection.driver class = org.gjt.mm.mysql.Driver # o driver
hibernate.connection.url = jdbc:mysql://localhost:3306/test # a url
hibernate.connection.username = user # o username
hibernate.connection.password = pass # a senha

adicionei ele esse arquivo e tb o jar do mysql ao CLASSPATH .

Qual seria o erro agora?

se quiserem posso mandar todos os arquivos q estou usando…

valeu

TedLoprao

Parece que ele não está encontrando o seu arquivo hibernate.properties!!!
Mas não sei afirmar se é realmente isso…
O arquivo está no classpath e se chama hibernate.properties???

J

sim, se chama hibernate.properties e pra evitar problemas coloquei no j2sdk/jre/lib/ext
E essas duas linhas inicias do log4j vc sabe o q significam?

log4j:WARN No appenders could be found for logger (net.sf.hibernate.cfg.Environment).
log4j:WARN Please initialize the log4j system properly.

valeu

TedLoprao

Isso não é problema!!!

Ele não achou o log4j.properties se não me engano!!!

Vc usa alguma ide para fazer os seus programas?? pq colocar isso lá no j2sdk/jre/lib/ext não é uma boa!!

fallow

J

estou mandando todos os arquivos(classes e config) pra ver se alguem me ajuda a encontrar os meus erros:

Classe Amigo

public class Amigo

{

public String nome;

public String endereco;

public String telefone;

public String celular;

public String email;

public java.util.Date nascimento;
public Amigo(){
}
public String getNome(){
    return nome;
}
public void setNome(String nome){
    this.nome = nome;
}  
    public String getEndereco(){
        return endereco;
    }
    public void setEndereco(String endereco){
        this.endereco = endereco;
    }
    public String getTelefone(){
        return telefone;
    }
    public void setTelefone(String telefone){
        this.telefone = telefone;
    }
    public String getCelular(){
        return celular;
    }
    public void setCelular(String celular){
        this.celular = celular;
    }
    public String getEmail(){
        return email;
    }
    public void setEmail(String email){
        this.email = email;
    }
public java.util.Date getNascimento(){
    return nascimento;
}    
public void setNascimento(java.util.Date nascimento){
    this.nascimento = nascimento;
}

}

Amigo.hbm.xml

<?xml version=“1.0”?>
<!DOCTYPE hibernate-mapping PUBLIC “-//Hibernate/Hibernate Mapping DTD//EN” “http://hibernate.sourceforge.net/hibernate-mapping.dtd”>
<hibernate-mapping>
<class name=“Amigo” table=“amigos”>

<generator class=“assigned”/>

<property name=“endereco” type=“string”/>
<property name=“telefone” column=“fone” type=“string”/>
<property name=“celular” column=“cel” type=“string”/>
<property name=“email” type=“string”/>
<property name=“nascimento” type=“date”/>
</class>
</hibernate-mapping>

Classe AmigoDAO

import net.sf.hibernate.<em>;

import java.util.Date;

import net.sf.hibernate.cfg.Configuration;

import net.sf.hibernate.cfg.Environment;

//import org.dom4j.</em>;

public class AmigoDAO{
private SessionFactory factory;

public AmigoDAO() throws Exception{
	Configuration cfg = new Configuration();
	cfg.addClass(Amigo.class);
//	Datastore datastore = hibernate.createDatastore();
//	datastore.storeClass(Amigo.class);

// factory = cfg.buildSessionFactory();
this.factory = cfg.buildSessionFactory();
}
public void insert(Amigo amigo) throws Exception{
Session session = factory.openSession();
session.save(amigo);
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 Amigo retrieve(String pk) throws Exception{
Session session = factory.openSession();
Amigo amigo = (Amigo)session.load(Amigo.class,pk);
session.flush();
session.close();
return amigo;
}
public void delete(Amigo amigo) throws Exception{
Session session = factory.openSession();
session.delete(amigo);
session.flush();
session.close();
}
}

hibernate.properties

hibernate.connection.driver class = org.gjt.mm.mysql.Driver # o driver
hibernate.connection.url = jdbc:mysql://localhost:3306/agenda # a url
hibernate.connection.username = user # o username
hibernate.connection.password = pass # a senha

Classe Chama

public class Chama{

public Chama(){

}

public static void main(String[] args) throws Exception{

Amigo amigo = new Amigo();

AmigoDAO novo = new AmigoDAO();

amigo.nome=Anselmo;

amigo.endereco=Carlos Kraemer;

amigo.telefone=2134567;

amigo.celular=91231203;

amigo.email=[email removido];

amigo.nascimento= new java.util.Date(104,07,29);

novo.insert(amigo);

}

}

serah q alguma alguma caridosa pode me dar uma mão? estou desde ontem encima disso e nad ainda… :frowning:

J

Esqueci de responder antes…estou usando o Netbeans 3.6 agora

TedLoprao

bom, quanto ao NetBeans eu não posso ajudar… Mas alguém aqui no guj pode!!!

Quanto a erros, vi que seu Amigo não possui id… Mas acho que foi quando vc colocou o arquivo aqui!! Pelo visto vc vai usar o nome como chave!!

Para testar vc poderia gerar a Connection na mão e passar por parametro… e depois verificar o esquema do classpath pq para mim o erro deve ser esse!!

Fallow

F

Falta o arquivos de propriedades do LOG4J

log4j.properties

# DEBUG
# INFO
# WARN
# ERROR
# FATAL

log4j.rootLogger= DEBUG, dest1 

log4j.appender.dest1=org.apache.log4j.ConsoleAppender
log4j.appender.dest1.layout= org.apache.log4j.PatternLayout
log4j.appender.dest1.layout.ConversionPattern=%d %-5p %-5c{3} %x -> %m%n

Vc pode usar no lugar de DEBUG as outras constantes comentadas também. :wink:

J

valeu cara isso resolveu essa questao do log4j, parece que o mapeamento estah sendo feito corretamente, mas parece q o arquivo de configuracao do banco de dados naum estah sendo lido

2004-07-30 13:50:29,918 INFO  hibernate.cfg.Environment  -> Hibernate 2.1.3

2004-07-30 13:50:29,946 INFO  hibernate.cfg.Environment  -> hibernate.properties not found

2004-07-30 13:50:29,974 INFO  hibernate.cfg.Environment  -> using CGLIB reflection optimizer

2004-07-30 13:50:30,073 INFO  hibernate.cfg.Configuration  -> Mapping resource: Amigo.hbm.xml

2004-07-30 13:50:32,672 DEBUG hibernate.util.DTDEntityResolver  -> trying to locate <a href="http://hibernate.sourceforge.net/hibernate-mapping.dtd">http://hibernate.sourceforge.net/hibernate-mapping.dtd</a> in classpath under net/sf/hibernate/

2004-07-30 13:50:32,681 DEBUG hibernate.util.DTDEntityResolver  -> <a href="http://hibernate.sourceforge.net/hibernate-mapping.dtdnot">http://hibernate.sourceforge.net/hibernate-mapping.dtdnot</a> found in classpath

2004-07-30 13:50:35,266 INFO  hibernate.cfg.Binder  -> Mapping class: Amigo -> amigos

2004-07-30 13:50:35,899 DEBUG hibernate.cfg.Binder  -> Mapped property: nome -> nome, type: string

2004-07-30 13:50:36,041 DEBUG hibernate.cfg.Binder  -> Mapped property: endereco -> endereco, type: string

2004-07-30 13:50:36,043 DEBUG hibernate.cfg.Binder  -> Mapped property: telefone -> fone, type: string

2004-07-30 13:50:36,045 DEBUG hibernate.cfg.Binder  -> Mapped property: celular -> cel, type: string

2004-07-30 13:50:36,046 DEBUG hibernate.cfg.Binder  -> Mapped property: email -> email, type: string

2004-07-30 13:50:36,048 DEBUG hibernate.cfg.Binder  -> Mapped property: nascimento -> nascimento, type: date

2004-07-30 13:50:36,050 INFO  hibernate.cfg.Configuration  -> processing one-to-many association mappings

2004-07-30 13:50:36,051 INFO  hibernate.cfg.Configuration  -> processing one-to-one association property references

2004-07-30 13:50:36,052 INFO  hibernate.cfg.Configuration  -> processing foreign key constraints

2004-07-30 13:50:36,270 WARN  hibernate.cfg.SettingsFactory  -> No dialect set - using GenericDialect: The dialect was not set. Set the property hibernate.dialect.

2004-07-30 13:50:36,282 INFO  hibernate.dialect.Dialect  -> Using dialect: net.sf.hibernate.dialect.GenericDialect

2004-07-30 13:50:36,285 INFO  hibernate.cfg.SettingsFactory  -> Use outer join fetching: false

2004-07-30 13:50:36,373 WARN  hibernate.connection.UserSuppliedConnectionProvider  -> No connection properties specified - the user must supply JDBC connections

2004-07-30 13:50:36,465 INFO  hibernate.transaction.TransactionManagerLookupFactory  -> No TransactionManagerLookup configured (in JTA environment, use of process level read-write cache is not recommended)

2004-07-30 13:50:36,469 INFO  hibernate.cfg.SettingsFactory  -> Use scrollable result sets: false

2004-07-30 13:50:36,472 INFO  hibernate.cfg.SettingsFactory  -> Use JDBC3 getGeneratedKeys(): false

2004-07-30 13:50:36,473 INFO  hibernate.cfg.SettingsFactory  -> Optimize cache for minimal puts: false

2004-07-30 13:50:36,475 INFO  hibernate.cfg.SettingsFactory  -> Query language substitutions: {}

2004-07-30 13:50:36,477 INFO  hibernate.cfg.SettingsFactory  -> cache provider: net.sf.ehcache.hibernate.Provider

2004-07-30 13:50:36,495 INFO  hibernate.cfg.Configuration  -> instantiating and configuring caches

2004-07-30 13:50:37,648 INFO  hibernate.impl.SessionFactoryImpl  -> building session factory

2004-07-30 13:50:37,652 DEBUG hibernate.impl.SessionFactoryImpl  -> instantiating session factory with properties: {java.runtime.name=Java 2 Runtime Environment, Standard Edition, sun.boot.library.path=/usr/local/j2sdk1.4.2_04/jre/lib/i386, java.vm.version=1.4.2_04-b05, java.vm.vendor=Sun Microsystems Inc., java.vendor.url=http://java.sun.com/, path.separator=:, java.vm.name=Java HotSpot™ Client VM, <a href="http://file.encoding.pkg=sun.io">file.encoding.pkg=sun.io</a>, user.country=US, sun.os.patch.level=unknown, java.vm.specification.name=Java Virtual Machine Specification, user.dir=/xmlrpc, java.runtime.version=1.4.2_04-b05, java.awt.graphicsenv=sun.awt.X11GraphicsEnvironment, java.endorsed.dirs=/usr/local/j2sdk1.4.2_04/jre/lib/endorsed, os.arch=i386, java.io.tmpdir=/tmp, line.separator=

, java.vm.specification.vendor=Sun Microsystems Inc., os.name=Linux, sun.java2d.fontpath=, java.library.path=/usr/local/j2sdk1.4.2_04/jre/lib/i386/client:/usr/local/j2sdk1.4.2_04/jre/lib/i386:/usr/local/j2sdk1.4.2_04/jre//lib/i386:/opt/kde/lib, java.specification.name=Java Platform API Specification, java.class.version=48.0, java.util.prefs.PreferencesFactory=java.util.prefs.FileSystemPreferencesFactory, os.version=2.4.5, user.home=/root, user.timezone=America/Sao_Paulo, java.awt.printerjob=sun.print.PSPrinterJob, file.encoding=ANSI_X3.4-1968, java.specification.version=1.4, user.name=root, java.class.path=.:/usr/local/jakarta-log4j-1.2.8/dist/lib/log4j-1.2.8.jar:/usr/local/j2ssh/dist/lib/j2ssh-core.jar:/usr/local/j2ssh/lib:/usr/local/j2ssh/dist/lib:/usr/local/java_xml_pack-summer-02_01/jaxp-1.2_01/jaxp-api.jar:/usr/local/xmlrpc-1.2-b1/xmlrpc-1.2-b1.jar:/usr/local/jdom-b10/build/jdom.jar:/usr/local/src/hibernate/hibernate-2.1/lib:/usr/local/src/hibernate/hibernate-2.1/lib/dom4j-1.4.jar:/xmlrpc/libs, java.vm.specification.version=1.0, java.home=/usr/local/j2sdk1.4.2_04/jre, sun.arch.data.model=32, user.language=en, java.specification.vendor=Sun Microsystems Inc., hibernate.cglib.use_reflection_optimizer=true, java.vm.info=mixed mode, java.version=1.4.2_04, java.ext.dirs=/usr/local/j2sdk1.4.2_04/jre/lib/ext, sun.boot.class.path=/usr/local/j2sdk1.4.2_04/jre/lib/endorsed/sax2.jar:/usr/local/j2sdk1.4.2_04/jre/lib/rt.jar:/usr/local/j2sdk1.4.2_04/jre/lib/i18n.jar:/usr/local/j2sdk1.4.2_04/jre/lib/sunrsasign.jar:/usr/local/j2sdk1.4.2_04/jre/lib/jsse.jar:/usr/local/j2sdk1.4.2_04/jre/lib/jce.jar:/usr/local/j2sdk1.4.2_04/jre/lib/charsets.jar:/usr/local/j2sdk1.4.2_04/jre/classes, java.vendor=Sun Microsystems Inc., file.separator=/, java.vendor.url.bug=http://java.sun.com/cgi-bin/bugreport.cgi, sun.io.unicode.encoding=UnicodeLittle, sun.cpu.endian=little, sun.cpu.isalist=}

2004-07-30 13:50:40,117 DEBUG hibernate.impl.SessionFactoryObjectFactory  -> initializing class SessionFactoryObjectFactory

2004-07-30 13:50:40,142 DEBUG hibernate.impl.SessionFactoryObjectFactory  -> registered: 40288092fe10f5ca00fe10f5d7610000 (unnamed)

2004-07-30 13:50:40,145 INFO  hibernate.impl.SessionFactoryObjectFactory  -> no JNDI name configured

2004-07-30 13:50:40,147 DEBUG hibernate.impl.SessionFactoryImpl  -> instantiated session factory

2004-07-30 13:50:40,726 DEBUG hibernate.impl.SessionImpl  -> opened session

2004-07-30 13:50:40,743 DEBUG hibernate.impl.SessionImpl  -> generated identifier: Anselmo

2004-07-30 13:50:40,753 DEBUG hibernate.impl.SessionImpl  -> saving [Amigo#Anselmo]

2004-07-30 13:50:40,879 DEBUG hibernate.impl.SessionImpl  -> flushing session

2004-07-30 13:50:40,907 DEBUG hibernate.impl.SessionImpl  -> Flushing entities and processing referenced collections

2004-07-30 13:50:40,924 DEBUG hibernate.impl.SessionImpl  -> Processing unreferenced collections

2004-07-30 13:50:40,926 DEBUG hibernate.impl.SessionImpl  -> Scheduling collection removes/(re)creates/updates

2004-07-30 13:50:40,929 DEBUG hibernate.impl.SessionImpl  -> Flushed: 1 insertions, 0 updates, 0 deletions to 1 objects

2004-07-30 13:50:40,930 DEBUG hibernate.impl.SessionImpl  -> Flushed: 0 (re)creations, 0 updates, 0 removals to 0 collections

2004-07-30 13:50:40,943 DEBUG hibernate.impl.Printer  -> listing entities:

2004-07-30 13:50:41,252 DEBUG hibernate.impl.Printer  -> Amigo{nome=Anselmo, celular=91231203, email=[email removido], telefone=2134567, nascimento=29 August 2004, endereco=Carlos Kraemer}

2004-07-30 13:50:41,256 DEBUG hibernate.impl.SessionImpl  -> executing flush

2004-07-30 13:50:41,268 DEBUG hibernate.persister.EntityPersister  -> Inserting entity: [Amigo#Anselmo]

2004-07-30 13:50:41,271 DEBUG hibernate.impl.BatcherImpl  -> about to open: 0 open PreparedStatements, 0 open ResultSets

Exception in thread main java.lang.UnsupportedOperationException: The user must supply a JDBC connection

at net.sf.hibernate.connection.UserSuppliedConnectionProvider.getConnection(UserSuppliedConnectionProvider.java:32)

at net.sf.hibernate.impl.BatcherImpl.openConnection(BatcherImpl.java:278)

at net.sf.hibernate.impl.SessionImpl.connect(SessionImpl.java:3297)

at net.sf.hibernate.impl.SessionImpl.connection(SessionImpl.java:3277)

at net.sf.hibernate.impl.BatcherImpl.prepareStatement(BatcherImpl.java:61)

at net.sf.hibernate.impl.BatcherImpl.prepareStatement(BatcherImpl.java:56)

at net.sf.hibernate.impl.BatcherImpl.prepareBatchStatement(BatcherImpl.java:109)

at net.sf.hibernate.persister.EntityPersister.insert(EntityPersister.java:460)

at net.sf.hibernate.persister.EntityPersister.insert(EntityPersister.java:442)

at net.sf.hibernate.impl.ScheduledInsertion.execute(ScheduledInsertion.java:29)

at net.sf.hibernate.impl.SessionImpl.executeAll(SessionImpl.java:2407)

at net.sf.hibernate.impl.SessionImpl.execute(SessionImpl.java:2360)

at net.sf.hibernate.impl.SessionImpl.flush(SessionImpl.java:2229)

at AmigoDAO.insert(AmigoDAO.java:21)

at Chama.main(Chama.java:14)

vc sabe o q posso fazer?

J

vc sabe se na versao 2 do hibernate se eu nomear o arquivo como hibernate.properties e coloca-lo no CLASSPATH ele carrega automaticamente? ou tenho q chama-lo em algum ponto?

valeu…

TedLoprao

Eu se fosse vc criaria a conexão na mão e passaria por parametro para o openSession… Ai veria se isso funcionava… se funcionar o problema deve estar no classpath mesmo!!!

J

me desculpe, mas como disse no inicio sou iniciante e naum sei como fazer essa conexao na mao q vc falou…

valeu…

TedLoprao

De uma olhada no tutorial aqui do GUJ em :
http://www.guj.com.br/user.article.get.chain?page=1&article.id=7

Ali vc ve como pegar uma connection com o DriverManager…

Fallow

J

meu grande problema estah aqui embaixo, se eu conseguir fazer o hibernate ler esse arquivo de propriedades…

2004-07-30 13:50:29,946 INFO hibernate.cfg.Environment -> hibernate.properties not found

mas jah tentei de tudo, cloloquei esse arquivo onde estaum todos os demais, coloquei em ./libs, sendo q esta estah no CLASSPATH, tentei tb colocar no j2sdk/jre/lib/ext…mas nada disso funcionou…

Jah estou quase no final do segundo dia e infelizmente naum coloquei esse hibernate a funcionar…jah encontrei em outros locais na net pessoas com problemas identicos ao meu, mas ainda naum encontrei as solucoes…

F

Coloque na raiz de sua estrutura para tentar salvar o dia.

Ex.:
pasta - > br -> com -> abc
hibernate.properties

J

pois eh…jah fiz isso tb, alem de tudo o q citei no post anterior…jah toh ficando maluco…
Passos q fiz:

  1. coloquei o hibernate.properties onde estah a minha aplicacao
  2. $RAIZ_APLICACAO/libs
  3. j2sdk/jre/lib/ext

sendo q essas 3 localizacoes estao no CLASSPATH,

alem disso, tentei:

  1. renomear o arquivo pro mesmo nome do objeto(amigo.properties)
  2. o mesmo, mas iniciando com A(maiusculo) -> Amigo.properties
  3. tentei tb Hibernate.properties

como podem ver estou no desespero…e a solucao pra variar deve ser ridicula…soh q ainda naum a encontrei…:frowning:

valeu…

Criado 29 de julho de 2004
Ultima resposta 30 de jul. de 2004
Respostas 27
Participantes 5