-
1. Re: ejb+oracle problem with file persistence
gaiapuffo Oct 29, 2013 4:59 AM (in response to gaiapuffo)and got the following error
Exception in thread "main" javax.persistence.PersistenceException: No Persistence provider for EntityManager named Allenavita
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:69)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:47)
at com.ibytecode.client.utility.ClientForSave.main(ClientForSave.java:18)
I downloaded the jboss server and modified the standalone files, so changing the datasource
<datasources>
<datasource jndi-name="java:jboss/datasources/OracleDS" pool-name="OracleDS" enabled="true" use-java-context="true">
<connection-url>jdbc:oracle:thin:@localhost:1521:xe</connection-url>
<driver>oracle</driver>
<security>
<user-name>SYSTEM</user-name>
<password>puffo</password>
</security>
</datasource>
<drivers>
<driver name="oracle" module="com.oracle.ojdbc6">
<xa-datasource-class>oracle.jdbc.OracleDriver</xa-datasource-class>
</driver>
</drivers>
</datasources>
Then i insert oracle.ojdbc6 in modules-com di jboss..Then I created the persistence file:
<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.0"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd">
<!-- PERSISTENCE UNITS DEVELOPMENT -->
<persistence-unit name="Allenavita" transaction-type="JTA">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<jta-data-source >java:jboss/datasources/OracleDS</jta-data-source>
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.Oracle10gDialect" />
<property name="hibernate.show_sql" value="true"/>
</properties>
</persistence-unit>
</persistence>
and cfg file
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory name="">
<!-- Related to the connection START -->
<property name="connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
<property name="connection.url">jdbc:oracle:thin:@localhost:1521:xe</property>
<property name="connection.user">SYSTEM</property>
<property name="connection.password">puffo</property>
<property name="connection.pool_size">2</property>
<!-- Related to the connection END
Related to hibernate properties START -->
<property name="show_sql">true</property>
<property name="dialet">org.hibernate.dialect.OracleDialect</property>
<!-- Related to hibernate properties END
Related to mapping START
Related to the mapping END -->
</session-factory>
</hibernate-configuration>
Then the project
My Entity:
@Entity
@Table(name="Employ")
public class Employ implements Serializable{
@Id private int id;
private String name;
private int salary;
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; }
public int getSalary() { return salary; }
public void setSalary(int salary) { this. salary = salary; }
public Employ() {
super();
}
}
My session
La session
@Stateful
public class Vendi implements ProductLocal {
@PersistenceContext(unitName="Allenavita")
private EntityManager em;
Employ empoly;
/**
* Default constructor.
* @return
*/
public void Inserimento(EntityManager em) {
System.out.println("Sono entrato in Product");
this.em = em;
}
public Vendi(){};
// TODO Auto-generated constructor stub
public void insert(Employ empoly){
System.out.println("Sono entrato in Product");
em.persist(empoly);
}
}
classe main
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println("sono nel main");
EntityManagerFactory emf = Persistence.createEntityManagerFactory("Allenavita");
System.out.println("valore emf");
if(emf==null){
System.out.println("valore emf");
}
EntityManager em = emf.createEntityManager();
Employ emp=new Employ();
emp.setName("Alessio");
emp.setSalary(1400);
Vendi sell=new Vendi();
sell.Inserimento(em);
sell.insert(emp);
}