Ajuda onde encontrar exemplos EJB,Hibernate,Jboss

9 respostas
P

Olá,

onde posso encontrar tutorial,exemplos pra analisar contendo

Java 6,Hibernate,EJB,Hibernate,Jboss 6

Se alguém puder me ajudar

agradeceria…

abs

9 Respostas

fabiomedeirosf

Tenho um blog que tenho postado alguns conteúdos.

Infelizmente de EJB ainda não postei nada, mas em breve terá ;). Conteúdos relativos a hibernate (JPA) já tenho disponível, se te ajudar: http://serjava.blogspot.com/

P

Obrigado pelo retorno

verifiquei um exemplo no blog

e vi uma classe Conexao e não existe o codigo dela poderia me enviar esse fonte...

abs

private Conexao conexao;
P

olá,

esquece já achei…

abs

fabiomedeirosf

Ok, precisando de algo posta ai. Ou pode deixar comments no blog.

P

Olá,

uma duvida estou com erro abaixo onde criei o arquivo persistence.xml

/Persistencia/WebContent/META-INF/persistence.xml

o que estou usando java 6,eclipse helios,tomcat 6,nysql e criei o projeto como Dynamic Web Project

INFO: HHH000021: Bytecode provider name : javassist
23/03/2012 11:04:57 org.hibernate.ejb.Ejb3Configuration configure
INFO: HHH000318: Could not find any META-INF/persistence.xml file in the classpath
Exception in thread "main" javax.persistence.PersistenceException: No Persistence provider for EntityManager named PersistenciaPU
	at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:69)
	at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:47)
	at br.com.serjava.persistencia.dao.Conexao.getEntityManager(Conexao.java:19)
	at br.com.serjava.persistencia.dao.TestaConexao.main(TestaConexao.java:18)
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/persistence" xsi:schemalocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
 <persistence-unit name="PersistenciaPU">
  
  <provider>org.hibernate.ejb.HibernatePersistence</provider>
   
  <properties>
   <property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver"></property>
   <property name="javax.persistence.jdbc.user" value="root"></property>
   <property name="javax.persistence.jdbc.password" value="paulo"></property>
   <property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/teste"></property>
  </properties>
  
 </persistence-unit>
</persistence>
P

o que fiz copiei a pasta META-INF que está em WebContent para src

e ao rodar o main

public class TestaConexao {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		Produto produto = new Produto();
		  produto.setNomeProduto("produto");
		  produto.setQuantidade(22);
		  produto.setValor(33.99);
		   
		  EntityManager em = new Conexao().getEntityManager();
		   
		  em.getTransaction().begin();
		  em.persist(produto);
		  em.getTransaction().commit();

}

me dá esse erro :

3/03/2012 11:19:38 org.hibernate.annotations.common.Version <clinit>
INFO: HCANN000001: Hibernate Commons Annotations {4.0.1.Final}
23/03/2012 11:19:38 org.hibernate.Version logVersion
INFO: HHH000412: Hibernate Core {4.1.1}
23/03/2012 11:19:38 org.hibernate.cfg.Environment <clinit>
INFO: HHH000206: hibernate.properties not found
23/03/2012 11:19:38 org.hibernate.cfg.Environment buildBytecodeProvider
INFO: HHH000021: Bytecode provider name : javassist
Exception in thread "main" javax.persistence.PersistenceException: Invalid persistence.xml.
Error parsing XML (line-1 : column -1): cvc-complex-type.3.2.2: Attribute 'xsi:schemalocation' is not allowed to appear in element 'persistence'.

	at org.hibernate.ejb.packaging.PersistenceXmlLoader.loadURL(PersistenceXmlLoader.java:145)
	at org.hibernate.ejb.packaging.PersistenceXmlLoader.deploy(PersistenceXmlLoader.java:169)
	at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:323)
	at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:55)
	at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:63)
	at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:47)
	at br.com.serjava.persistencia.dao.Conexao.getEntityManager(Conexao.java:19)
	at br.com.serjava.persistencia.dao.TestaConexao.main(TestaConexao.java:18)

como está o arquivo persistence.xml

/Persistencia/src/META-INF/persistence.xml

<persistence version="2.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/persistence" xsi:schemalocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
 <persistence-unit name="PersistenciaPU">
  
  <provider>org.hibernate.ejb.HibernatePersistence</provider>
   <class>br.com.serjava.persistencia.entity.Produto</class> 
  <properties>
   <property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver"></property>
   <property name="javax.persistence.jdbc.user" value="root"></property>
   <property name="javax.persistence.jdbc.password" value="paulo"></property>
   <property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/teste"></property>
   <property name="hibernate.hbm2ddl.auto" value="create"/> 
   <property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5InnoDBDialect"/>  
    
  </properties>
  
 </persistence-unit>
</persistence>
P

Olá,

uma dica o que fiz pra funcionar usando o banco mysql…

commentei a linha @ GeneratedValue
e criei uma sem parametro

public class Produto implements Serializable {
	@Id
	//@GeneratedValue(generator = "produto_id_produto_seq", strategy = GenerationType.SEQUENCE)
	@GeneratedValue
	@Column(name = "id_produto")
	private Integer idProduto;

copiei outro arquivo de um outro projeto pois qdo copio da web me da erro ai vai uma dica !!!

e copiei a pasta META_INF do WebContent para src

<persistence version="1.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd">
     <persistence-unit name="PersistenciaPU">
  
  <provider>org.hibernate.ejb.HibernatePersistence</provider>
   
  <properties>
   <property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver"></property>
   <property name="hibernate.connection.username" value="root"></property>
   <property name="hibernate.connection.password" value="paulo"></property>
   <property name="hibernate.connection.url" value="jdbc:mysql://localhost:3306/teste"></property>
   <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/>  
   <property name="hibernate.hbm2ddl.auto" value="update"/>  
  </properties>
  
 </persistence-unit>
23/03/2012 11:40:46 org.hibernate.annotations.common.Version <clinit>
INFO: HCANN000001: Hibernate Commons Annotations {4.0.1.Final}
23/03/2012 11:40:46 org.hibernate.Version logVersion
INFO: HHH000412: Hibernate Core {4.1.1}
23/03/2012 11:40:46 org.hibernate.cfg.Environment <clinit>
INFO: HHH000206: hibernate.properties not found
23/03/2012 11:40:46 org.hibernate.cfg.Environment buildBytecodeProvider
INFO: HHH000021: Bytecode provider name : javassist
23/03/2012 11:40:47 org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
INFO: HHH000402: Using Hibernate built-in connection pool (not for production use!)
23/03/2012 11:40:47 org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
INFO: HHH000115: Hibernate connection pool size: 20
23/03/2012 11:40:47 org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
INFO: HHH000006: Autocommit mode: true
23/03/2012 11:40:47 org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
INFO: HHH000401: using driver [com.mysql.jdbc.Driver] at URL [jdbc:mysql://localhost:3306/teste]
23/03/2012 11:40:47 org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
INFO: HHH000046: Connection properties: {user=root, password=****, autocommit=true, release_mode=auto}
23/03/2012 11:40:47 org.hibernate.dialect.Dialect <init>
INFO: HHH000400: Using dialect: org.hibernate.dialect.MySQLDialect
23/03/2012 11:40:47 org.hibernate.engine.transaction.internal.TransactionFactoryInitiator initiateService
INFO: HHH000268: Transaction strategy: org.hibernate.engine.transaction.internal.jdbc.JdbcTransactionFactory
23/03/2012 11:40:47 org.hibernate.hql.internal.ast.ASTQueryTranslatorFactory <init>
INFO: HHH000397: Using ASTQueryTranslatorFactory
23/03/2012 11:40:48 org.hibernate.tool.hbm2ddl.SchemaUpdate execute
INFO: HHH000228: Running hbm2ddl schema update
23/03/2012 11:40:48 org.hibernate.tool.hbm2ddl.SchemaUpdate execute
INFO: HHH000102: Fetching database metadata
23/03/2012 11:40:48 org.hibernate.tool.hbm2ddl.SchemaUpdate execute
INFO: HHH000396: Updating schema
23/03/2012 11:40:48 org.hibernate.tool.hbm2ddl.DatabaseMetadata getTableMetadata
INFO: HHH000262: Table not found: PRODUTO_AUDIT
23/03/2012 11:40:48 org.hibernate.tool.hbm2ddl.DatabaseMetadata getTableMetadata
INFO: HHH000262: Table not found: REVINFO
23/03/2012 11:40:48 org.hibernate.tool.hbm2ddl.DatabaseMetadata getTableMetadata
INFO: HHH000262: Table not found: produto
23/03/2012 11:40:48 org.hibernate.tool.hbm2ddl.DatabaseMetadata getTableMetadata
INFO: HHH000262: Table not found: PRODUTO_AUDIT
23/03/2012 11:40:48 org.hibernate.tool.hbm2ddl.DatabaseMetadata getTableMetadata
INFO: HHH000262: Table not found: REVINFO
23/03/2012 11:40:48 org.hibernate.tool.hbm2ddl.DatabaseMetadata getTableMetadata
INFO: HHH000262: Table not found: produto
23/03/2012 11:40:48 org.hibernate.tool.hbm2ddl.SchemaUpdate execute
INFO: HHH000232: Schema update complete
C

Olá,

Verifica esse link ajuda http://www.devmedia.com.br/curso/ejb-3-0-com-netbeans-e-glassfish-aplicacao-completa/246.

So que esse é com glassfish, mas acredito que no site tenha algum exemplo com jboss.

Abraço.

P

obrigado vou dar uma olhada…

abs

Criado 23 de março de 2012
Ultima resposta 23 de mar. de 2012
Respostas 9
Participantes 3