2 Replies Latest reply on Oct 30, 2013 4:07 AM by Wolf-Dieter Fink Branched from an earlier discussion.

    Re: ejb+oracle problem with file persistence

    Wolf-Dieter Fink Master

      I'm a bit confused.

      You use a Employ entity in your session (you should not use a stateful one here)

      but also create a main program where it look like you use a Vendi entity?

      The hibernate configuration is not really needed.

       

      You might have a look into the greeter quickstart to see how it can be used.

        • 1. Re: ejb+oracle problem with file persistence
          Alessio Varalta Newbie

          I modified the session and the main ... now in the main I create the entity and then I go to sell new class, so I should get the entity manager and then I can call the function of the session to insert the data in the db...I can not find errors, if not the problem connecting to db

           

           

          @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();

              }

          }

           

           

          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);

              }

             

           

           

           

          }

           

           

           

          @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();

              }

          }

           

          <?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>

           

          Standalone file

          <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>

          • 2. Re: ejb+oracle problem with file persistence
            Wolf-Dieter Fink Master

            You should handle all persistence inside the server container.

            In this case the container provide the EntityManager via @PersistenceContext injection and you can use it.

             

            With a java application (main class) you need to controll all by yourself, this is plain Java and you should read the oracle tutorials for that.

            Here you will get help for Java EE stuff which mean everything around JBoss and it's EE container