cassiombc 16 de dez. de 2011
Galera eu coloquei a pasta META-INF no classpath mas ai ele gerou o seguinte
09 : 51 : 12 , 404 INFO [ main ] Main - javax . xml . transform . TransformerFactory = null
09 : 51 : 12 , 405 INFO [ main ] Main - java . endorsed . dirs = C : \ Program Files \ Java \ jre6 \ lib \ endorsed
09 : 51 : 12 , 409 INFO [ main ] Main - launchFile : C : \ Users \ dell \ Documents \ projetos_eclipse . metadata . plugins \ org . eclipse . wst . xsl . jaxp . launching \ launch \ launch . xml
09 : 51 : 13 , 027 FATAL [ main ] Main - No embedded stylesheet instruction for file : file : / C : / Users / dell / Documents / projetos_eclipse / JSP / META - INF / hibernate . cfg . xml
org . eclipse . wst . xsl . jaxp . debug . invoker . TransformationException : No embedded stylesheet instruction for file : file : / C : / Users / dell / Documents / projetos_eclipse / JSP / META - INF / hibernate . cfg . xml
at org . eclipse . wst . xsl . jaxp . debug . invoker . internal . JAXPSAXProcessorInvoker . transform ( JAXPSAXProcessorInvoker . java : 225 )
at org . eclipse . wst . xsl . jaxp . debug . invoker . internal . JAXPSAXProcessorInvoker . transform ( JAXPSAXProcessorInvoker . java : 186 )
at org . eclipse . wst . xsl . jaxp . debug . invoker . internal . Main . main ( Main . java : 73 )
Caused by : org . eclipse . wst . xsl . jaxp . debug . invoker . TransformationException : No embedded stylesheet instruction for file : file : / C : / Users / dell / Documents / projetos_eclipse / JSP / META - INF / hibernate . cfg . xml
at org . eclipse . wst . xsl . jaxp . debug . invoker . internal . JAXPSAXProcessorInvoker . transform ( JAXPSAXProcessorInvoker . java : 214 )
… 2 more
drsmachado 16 de dez. de 2011
Primeiro, você não possui um arquivo persistence,xml
Segundo, como este aquivo não existe, você não tem um EntityManager chamado eventos…
cassiombc 16 de dez. de 2011
Eu te tenho o hibernate.cfg.xml
<?xml version="1.0" encoding="UTF-8"?>
<hibernate-configuration>
<session-factory>
<property name= "connection.driver_class" > com.mysql.jdbc.Driver</property>
<property name= "connection.url" > jdbc:mysql://127.0.0.1:3306/mysql</property>
<property name= "connection.username" > root</property>
<property name= "connection.password" ></property>
<property name= "dialect" > org.hibernate.dialect.MYSQLDialect</property>
<property name= "c3p0.min_size" > 5</property>
<property name= "c3p0.max_size" > 20</property>
<property name= "c3p0.timeout" > 300</property>
<property name= "c3p0.max_statements" > 50</property>
<property name= "c3p0.idle_test_period" > 3000</property>
<property name= "show_sql" > true</property>
<mapping class= "Eventos.classes.Produtora" />
<mapping class= "Eventos.classes.Usuarios" />
</session-factory>
</hibernate-configuration>
drsmachado 16 de dez. de 2011
hibernate.cfg.xml != persistence.xml
Você está misturando as coisas, tentando criar uma aplicação utilizando JPA e EntityManager, mas baseando-se em uma estrutura do hibernate.
Você deve definir se vai utilizar EntityManager, então, crie o persistence.xml
Senão, troque o EntityManager por Session e boa.
Sugestão, jogue fora o tutorial que está seguindo, procure pela documentação oficial ou mesmo, por exemplos na net.
cassiombc 16 de dez. de 2011
eu criei uma classe hibernate util, e coloquei o hibernate.cfg.xml no classpath, e mandei funfa mas ele gerou o seguinte error:
0 [ main ] INFO org . hibernate . annotations . common . Version - Hibernate Commons Annotations 3.2.0 . Final
6 [ main ] INFO org . hibernate . cfg . Environment - Hibernate 3.6.8 . Final
7 [ main ] INFO org . hibernate . cfg . Environment - hibernate . properties not found
10 [ main ] INFO org . hibernate . cfg . Environment - Bytecode provider name : javassist
13 [ main ] INFO org . hibernate . cfg . Environment - using JDK 1.4 java . sql . Timestamp handling
70 [ main ] INFO org . hibernate . cfg . Configuration - configuring from resource : / hibernate . cfg . xml
71 [ main ] INFO org . hibernate . cfg . Configuration - Configuration resource : / hibernate . cfg . xml
316 [ main ] ERROR org . hibernate . util . XMLHelper - Error parsing XML : / hibernate . cfg . xml ( 3 ) Document is invalid : no grammar found .
316 [ main ] ERROR org . hibernate . util . XMLHelper - Error parsing XML : / hibernate . cfg . xml ( 3 ) Document root element “ hibernate - configuration ” , must match DOCTYPE root “ null ” .
Exception in thread “ main ” java . lang . ExceptionInInitializerError
at Eventos . Ultil . Jdbc2 . main ( Jdbc2 . java : 11 )
Caused by : org . hibernate . MappingException : invalid configuration
at org . hibernate . cfg . Configuration . doConfigure ( Configuration . java : 2241 )
at org . hibernate . cfg . AnnotationConfiguration . doConfigure ( AnnotationConfiguration . java : 230 )
at org . hibernate . cfg . AnnotationConfiguration . doConfigure ( AnnotationConfiguration . java : 71 )
at org . hibernate . cfg . Configuration . configure ( Configuration . java : 2158 )
at org . hibernate . cfg . AnnotationConfiguration . configure ( AnnotationConfiguration . java : 212 )
at org . hibernate . cfg . AnnotationConfiguration . configure ( AnnotationConfiguration . java : 71 )
at org . hibernate . cfg . Configuration . configure ( Configuration . java : 2137 )
at org . hibernate . cfg . AnnotationConfiguration . configure ( AnnotationConfiguration . java : 206 )
at Eventos . Ultil . HibernateUtil .( HibernateUtil . java : 10 )
… 1 more
Caused by : org . xml . sax . SAXParseException : Document is invalid : no grammar found .
at com . sun . org . apache . xerces . internal . util . ErrorHandlerWrapper . createSAXParseException ( Unknown Source )
at com . sun . org . apache . xerces . internal . util . ErrorHandlerWrapper . error ( Unknown Source )
at com . sun . org . apache . xerces . internal . impl . XMLErrorReporter . reportError ( Unknown Source )
at com . sun . org . apache . xerces . internal . impl . XMLErrorReporter . reportError ( Unknown Source )
at com . sun . org . apache . xerces . internal . impl . XMLNSDocumentScannerImpl . scanStartElement ( Unknown Source )
at com . sun . org . apache . xerces . internal . impl . XMLNSDocumentScannerImpl $ NSContentDriver . scanRootElementHook ( Unknown Source )
at com . sun . org . apache . xerces . internal . impl . XMLDocumentFragmentScannerImpl $ FragmentContentDriver . next ( Unknown Source )
at com . sun . org . apache . xerces . internal . impl . XMLDocumentScannerImpl $ PrologDriver . next ( Unknown Source )
at com . sun . org . apache . xerces . internal . impl . XMLDocumentScannerImpl . next ( Unknown Source )
at com . sun . org . apache . xerces . internal . impl . XMLNSDocumentScannerImpl . next ( Unknown Source )
at com . sun . org . apache . xerces . internal . impl . XMLDocumentFragmentScannerImpl . scanDocument ( Unknown Source )
at com . sun . org . apache . xerces . internal . parsers . XML11Configuration . parse ( Unknown Source )
at com . sun . org . apache . xerces . internal . parsers . XML11Configuration . parse ( Unknown Source )
at com . sun . org . apache . xerces . internal . parsers . XMLParser . parse ( Unknown Source )
at com . sun . org . apache . xerces . internal . parsers . AbstractSAXParser . parse ( Unknown Source )
at com . sun . org . apache . xerces . internal . jaxp . SAXParserImpl $ JAXPSAXParser . parse ( Unknown Source )
at org . dom4j . io . SAXReader . read ( SAXReader . java : 465 )
at org . hibernate . cfg . Configuration . doConfigure ( Configuration . java : 2238 )
… 9 more
Minha classe hibernate ultil :
package Eventos.Ultil ;
import org.hibernate.SessionFactory ;
import org.hibernate.cfg.AnnotationConfiguration ;
public class HibernateUtil {
private static SessionFactory sessionFactory ;
static {
sessionFactory = new AnnotationConfiguration (). configure ()
. buildSessionFactory ();
}
public static SessionFactory getSessionFactory (){
return sessionFactory ;
}
public static void shutdown (){
getSessionFactory (). close ();
}
}
Meu XML
<?xml version="1.0" encoding="UTF-8"?>
<hibernate-configuration>
<session-factory>
<property name= "connection.driver_class" > com.mysql.jdbc.Driver</property>
<property name= "connection.url" > jdbc:mysql://127.0.0.1:3306/mysql</property>
<property name= "connection.username" > root</property>
<property name= "connection.password" ></property>
<property name= "dialect" > org.hibernate.dialect.MYSQLDialect</property>
<property name= "c3p0.min_size" > 5</property>
<property name= "c3p0.max_size" > 20</property>
<property name= "c3p0.timeout" > 300</property>
<property name= "c3p0.max_statements" > 50</property>
<property name= "c3p0.idle_test_period" > 3000</property>
<property name= "show_sql" > true</property>
<mapping class= "Eventos.classes.Produtora" />
<mapping class= "Eventos.classes.Usuarios" />
</session-factory>
</hibernate-configuration>