1

Right next part of my saga of getting EJB working hoping someone here can help me out

Here is my server log saying my deployment was successful:

2012-03-11 22:02:41,837 INFO  [org.jboss.web.tomcat.service.deployers.TomcatDeployment] (HDScanner) undeploy, ctxPath=/SE2-war
2012-03-11 22:02:41,882 INFO  [org.jboss.jpa.deployment.PersistenceUnitDeployment] (HDScanner) Stopping persistence unit persistence.unit:unitName=SE2.ear/SE2-ejb.jar#wvp08heuPU
2012-03-11 22:02:42,429 WARN  [org.jboss.ejb3.interceptor.InterceptorInfoRepository] (HDScanner) EJBTHREE-1852: InterceptorInfoRepository is deprecated
2012-03-11 22:02:42,650 INFO  [org.jboss.profileservice.management.upload.remoting.DeployHandler] (WorkerThread#0[127.0.0.1:3125]) invoke, payload: {DeploymentTargetID=names=[SE2.ear], clientAddress=/127.0.0.1}, parameter: start
2012-03-11 22:02:42,900 INFO  [org.jboss.ejb3.deployers.JBossASKernel] (HDScanner) Created KernelDeployment for: SE2-ejb.jar
2012-03-11 22:02:42,901 INFO  [org.jboss.ejb3.deployers.JBossASKernel] (HDScanner) installing bean: jboss.j2ee:ear=SE2.ear,jar=SE2-ejb.jar,name=NewSessionBean,service=EJB3
2012-03-11 22:02:42,901 INFO  [org.jboss.ejb3.deployers.JBossASKernel] (HDScanner)   with dependencies:
2012-03-11 22:02:42,901 INFO  [org.jboss.ejb3.deployers.JBossASKernel] (HDScanner)   and demands:
2012-03-11 22:02:42,902 INFO  [org.jboss.ejb3.deployers.JBossASKernel] (HDScanner)  jboss-switchboard:appName=SE2,module=SE2-ejb,name=NewSessionBean; Required: Create
2012-03-11 22:02:42,902 INFO  [org.jboss.ejb3.deployers.JBossASKernel] (HDScanner)  jboss.ejb:service=EJBTimerService; Required: Described
2012-03-11 22:02:42,902 INFO  [org.jboss.ejb3.deployers.JBossASKernel] (HDScanner)   and supplies:
2012-03-11 22:02:42,903 INFO  [org.jboss.ejb3.deployers.JBossASKernel] (HDScanner)  Class:ejb.NewSessionBeanRemote
2012-03-11 22:02:42,903 INFO  [org.jboss.ejb3.deployers.JBossASKernel] (HDScanner)  jndi:NewSessionBean
2012-03-11 22:02:42,903 INFO  [org.jboss.ejb3.deployers.JBossASKernel] (HDScanner)  jndi:SE2/NewSessionBean/remote-ejb.NewSessionBeanRemote
2012-03-11 22:02:42,903 INFO  [org.jboss.ejb3.deployers.JBossASKernel] (HDScanner)  jndi:SE2/NewSessionBean/remote
2012-03-11 22:02:42,904 INFO  [org.jboss.ejb3.deployers.JBossASKernel] (HDScanner) Added bean(jboss.j2ee:ear=SE2.ear,jar=SE2-ejb.jar,name=NewSessionBean,service=EJB3) to KernelDeployment of: SE2-ejb.jar
2012-03-11 22:02:42,980 INFO  [org.jboss.ejb3.session.SessionSpecContainer] (HDScanner) Starting jboss.j2ee:ear=SE2.ear,jar=SE2-ejb.jar,name=NewSessionBean,service=EJB3
2012-03-11 22:02:43,054 INFO  [org.jboss.ejb3.EJBContainer] (HDScanner) STARTED EJB: ejb.NewSessionBean ejbName: NewSessionBean
2012-03-11 22:02:43,410 INFO  [org.jboss.ejb3.proxy.impl.jndiregistrar.JndiSessionRegistrarBase] (HDScanner) Binding the following Entries in Global JNDI:

    SE2/NewSessionBean/remote - EJB3.x Default Remote Business Interface
    SE2/NewSessionBean/remote-ejb.NewSessionBeanRemote - EJB3.x Remote Business Interface

2012-03-11 22:02:43,411 WARN  [org.jboss.ejb3.TimerServiceContainer] (HDScanner) EJBTHREE-2193: using deprecated TimerServiceFactory for restoring timers
2012-03-11 22:02:43,424 INFO  [org.jboss.jpa.deployment.PersistenceUnitDeployment] (HDScanner) Starting persistence unit persistence.unit:unitName=SE2.ear/SE2-ejb.jar#wvp08heuPU
2012-03-11 22:02:43,454 INFO  [org.jboss.web.tomcat.service.deployers.TomcatDeployment] (HDScanner) deploy, ctxPath=/SE2-war
2012-03-11 22:02:43,561 INFO  [org.jboss.web.tomcat.service.deployers.TomcatDeployment] (WorkerThread#0[127.0.0.1:3125]) undeploy, ctxPath=/SE2-war
2012-03-11 22:02:43,621 INFO  [org.jboss.jpa.deployment.PersistenceUnitDeployment] (WorkerThread#0[127.0.0.1:3125]) Stopping persistence unit persistence.unit:unitName=SE2.ear/SE2-ejb.jar#wvp08heuPU
2012-03-11 22:02:43,629 INFO  [org.jboss.ejb3.session.SessionSpecContainer] (WorkerThread#0[127.0.0.1:3125]) Stopping jboss.j2ee:ear=SE2.ear,jar=SE2-ejb.jar,name=NewSessionBean,service=EJB3
2012-03-11 22:02:43,781 INFO  [org.jboss.ejb3.EJBContainer] (WorkerThread#0[127.0.0.1:3125]) STOPPED EJB: ejb.NewSessionBean ejbName: NewSessionBean
2012-03-11 22:02:44,394 WARN  [org.jboss.ejb3.interceptor.InterceptorInfoRepository] (WorkerThread#0[127.0.0.1:3125]) EJBTHREE-1852: InterceptorInfoRepository is deprecated
2012-03-11 22:02:44,418 INFO  [org.jboss.ejb3.deployers.JBossASKernel] (WorkerThread#0[127.0.0.1:3125]) Created KernelDeployment for: SE2-ejb.jar
2012-03-11 22:02:44,425 INFO  [org.jboss.ejb3.deployers.JBossASKernel] (WorkerThread#0[127.0.0.1:3125]) installing bean: jboss.j2ee:ear=SE2.ear,jar=SE2-ejb.jar,name=NewSessionBean,service=EJB3
2012-03-11 22:02:44,426 INFO  [org.jboss.ejb3.deployers.JBossASKernel] (WorkerThread#0[127.0.0.1:3125])   with dependencies:
2012-03-11 22:02:44,426 INFO  [org.jboss.ejb3.deployers.JBossASKernel] (WorkerThread#0[127.0.0.1:3125])   and demands:
2012-03-11 22:02:44,426 INFO  [org.jboss.ejb3.deployers.JBossASKernel] (WorkerThread#0[127.0.0.1:3125])     jboss-switchboard:appName=SE2,module=SE2-ejb,name=NewSessionBean; Required: Create
2012-03-11 22:02:44,426 INFO  [org.jboss.ejb3.deployers.JBossASKernel] (WorkerThread#0[127.0.0.1:3125])     jboss.ejb:service=EJBTimerService; Required: Described
2012-03-11 22:02:44,427 INFO  [org.jboss.ejb3.deployers.JBossASKernel] (WorkerThread#0[127.0.0.1:3125])   and supplies:
2012-03-11 22:02:44,427 INFO  [org.jboss.ejb3.deployers.JBossASKernel] (WorkerThread#0[127.0.0.1:3125])     Class:ejb.NewSessionBeanRemote
2012-03-11 22:02:44,427 INFO  [org.jboss.ejb3.deployers.JBossASKernel] (WorkerThread#0[127.0.0.1:3125])     jndi:NewSessionBean
2012-03-11 22:02:44,427 INFO  [org.jboss.ejb3.deployers.JBossASKernel] (WorkerThread#0[127.0.0.1:3125])     jndi:SE2/NewSessionBean/remote-ejb.NewSessionBeanRemote
2012-03-11 22:02:44,427 INFO  [org.jboss.ejb3.deployers.JBossASKernel] (WorkerThread#0[127.0.0.1:3125])     jndi:SE2/NewSessionBean/remote
2012-03-11 22:02:44,428 INFO  [org.jboss.ejb3.deployers.JBossASKernel] (WorkerThread#0[127.0.0.1:3125]) Added bean(jboss.j2ee:ear=SE2.ear,jar=SE2-ejb.jar,name=NewSessionBean,service=EJB3) to KernelDeployment of: SE2-ejb.jar
2012-03-11 22:02:44,466 INFO  [org.jboss.ejb3.session.SessionSpecContainer] (WorkerThread#0[127.0.0.1:3125]) Starting jboss.j2ee:ear=SE2.ear,jar=SE2-ejb.jar,name=NewSessionBean,service=EJB3
2012-03-11 22:02:44,467 INFO  [org.jboss.ejb3.EJBContainer] (WorkerThread#0[127.0.0.1:3125]) STARTED EJB: ejb.NewSessionBean ejbName: NewSessionBean
2012-03-11 22:02:44,475 INFO  [org.jboss.ejb3.proxy.impl.jndiregistrar.JndiSessionRegistrarBase] (WorkerThread#0[127.0.0.1:3125]) Binding the following Entries in Global JNDI:

    SE2/NewSessionBean/remote - EJB3.x Default Remote Business Interface
    SE2/NewSessionBean/remote-ejb.NewSessionBeanRemote - EJB3.x Remote Business Interface

2012-03-11 22:02:44,477 WARN  [org.jboss.ejb3.TimerServiceContainer] (WorkerThread#0[127.0.0.1:3125]) EJBTHREE-2193: using deprecated TimerServiceFactory for restoring timers
2012-03-11 22:02:44,484 INFO  [org.jboss.jpa.deployment.PersistenceUnitDeployment] (WorkerThread#0[127.0.0.1:3125]) Starting persistence unit persistence.unit:unitName=SE2.ear/SE2-ejb.jar#wvp08heuPU
2012-03-11 22:02:44,529 INFO  [org.jboss.web.tomcat.service.deployers.TomcatDeployment] (WorkerThread#0[127.0.0.1:3125]) deploy, ctxPath=/SE2-war

Here is my persistence unit and its context:

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.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_2_0.xsd">
  <persistence-unit name="wvp08heuPU" transaction-type="JTA">
    <provider>oracle.toplink.essentials.PersistenceProvider</provider>
    <jta-data-source>java:/MYSQL</jta-data-source>
    <exclude-unlisted-classes>false</exclude-unlisted-classes>
    <properties>
      <property name="toplink.ddl-generation" value="create-tables"/>
    </properties>
  </persistence-unit>
</persistence>

Here's my problem: Looking at my database I have no persisted entities - the code below shows my entity:

package entities;

import java.io.Serializable;
import java.util.Calendar;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.UniqueConstraint;

@Entity
@Table(name="Account", uniqueConstraints=@UniqueConstraint(columnNames="email"))
public class Account implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private int account_id;

    private String email;
    private String name;
    @Temporal(javax.persistence.TemporalType.TIMESTAMP)
    private Calendar dateCreated;
    private int status;
    private String password;
    private String bio;
    private String profilePictureURL;

//getters and setters
    @Override
    public int hashCode() {
        int hash = 0;
        hash += (int) account_id;
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Account)) {
            return false;
        }
        Account other = (Account) object;
        if (this.account_id != other.account_id) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "entities.Account[ id=" + account_id + " ]";
    }

}

Any ideas?

EDIT:

My session bean:

package ejb;

import entities.Account;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

@Stateless
public class NewSessionBean implements NewSessionBeanRemote {

    @PersistenceContext(unitName = "wvp08heuPU")
    private EntityManager em;

    @Override
    public void AddAccount(Account a){
        em.persist(a);
    }
}

SOLUTION:

MAIN ISSUE WAS THIS: My persistence layer was not able to create the tables on the database as didn't have the functionality

In order to solve my real issue as Oscar pointed out I changed my persistence provider to Hibernate 2.0 - This along with a varied list of changes enabled my EJB to work.

A couple of issues I had which you may be looking to solve as well:

  • ClassNotFound Exception - move your persistence .jar files to the server/default directory of your JBoss 6 server

  • Class Cannot be cast - When using EclipseLink and JBoss 6 it seems there are some compatibility issues and I couldn't get this to work; I wouldn't bother trying.

  • MYSQL Not Found - make sure you only have one mysql connector driver being listed not ONLY in your JBoss libs folder but also in netbeans. You can default this using SET claspath which google will tell you the rest.

apaul
  • 16,092
  • 8
  • 47
  • 82
Lewis Wheeler
  • 220
  • 6
  • 17
  • `@Column(unique=true) private String email;` is sufficient for simple constraint. – viktor Mar 11 '12 at 22:44
  • Thanks viktor - I knew there was a method of doing it as part of the body of the class but that method also worked. Any idea's on my actual problem? – Lewis Wheeler Mar 11 '12 at 22:46

1 Answers1

3

And where is the call to entityManager.persist(account);? there should exist a business component in charge of persisting the entities, be it a session EJB or a POJO.

Óscar López
  • 232,561
  • 37
  • 312
  • 386
  • Hi Oscar - Your right I should have a call to that i've edited my above question with my Session Bean (which has the persist part). Eitherway if im not mistaken even if I don't have the call to the entity manager the table should still be created in the database? Thats how i've done it before anyhow... but that was with JBoss 7. – Lewis Wheeler Mar 11 '12 at 22:37
  • 1
    Your question was misleading, the title states "Entities not persisting"; now -if I understand correctly- the problem is that the tables are not being created in the database, not that they can't be persisted. Take a look at this [post](http://stackoverflow.com/questions/3279902/jpa-and-toplink-create-table-on-if-they-dont-already-exist) for further details on how to solve your problem. – Óscar López Mar 11 '12 at 23:04
  • Hi Oscar - Thanks again for your reply. Your right of course my question should of been instead 'EJB: entities not being created in the database' Your answer helped me to better understand the issue. In order to have the persistence provider create my tables for me I cannot use TopLink Essentials as it dosen't support this. It can instead be used to make the ddl files for you do it manually. If your after the same functionality as me i'd go for hibernate 2.0 instead as this is FINALLY how I managed to get my ejb working. – Lewis Wheeler Mar 12 '12 at 00:38
  • @LewisWheeler right, in hibernate table creation works seamlessly with this line in `persistence.xml`: `` where `???` can be any of the values explained in [here](http://stackoverflow.com/questions/438146/hibernate-question-hbm2ddl-auto-possible-values-and-what-they-do) – Óscar López Mar 12 '12 at 00:41