EJB + JPA Troubles

hello
can anyone help me with this problem
atm i'm making a project which uses EJBs (with JPA) and some fields in the EJBs get auto generated when persisting an EJB entity to the database
Writing to the database and reading out of it works perfectly, but when i persist a brand new entity to the table, i don't receive the brand new generated ID
(ID is a primary key in the table)
is there any way to update the persisted entity right after persisting it to the database ? so that my entity, which got persisted, gets his ID injected?
this is my code for inserting a new entity into the database:
@Transactional
public class JPAScenarioDAO implements ScenarioDAO{
    private EntityManager entityManager;
     * Spring injects entityManager
     * @param entityManager manager that handles persistence operations
    @PersistenceContext
    public void setEntityManager(EntityManager entityManager)
      this.entityManager = entityManager;
    public JPAScenarioDAO() {}
    public void createScenario(Scenario scenario){
        entityManager.persist(scenario); // <-- help?
    public void updateScenario(Scenario scenario){
        entityManager.merge(scenario);
    public void removeScenario(Scenario scenario){
        entityManager.remove(scenario);
}The scenario is an EJB that i generated from a table
import java.io.Serializable;
import java.sql.Timestamp;
import java.util.List;
import javax.persistence.Column;
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.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
@Entity
@NamedQueries({
    @NamedQuery(name = "Scenario.getScenarios",
                query = "select o from Scenario o"),
    @NamedQuery(name = "Scenario.getScenariosBetweenDates",
                query = "select o from Scenario o where o.date >= :datum1 and o.date <= :datum2"),
    @NamedQuery(name = "Scenario.getScenariosByEdition",
                query = "select o from Scenario o where o.edition = :edition"),
    @NamedQuery(name = "Scenario.getScenariosByIssue",
                query = "select o from Scenario o where o.issue = :issue"),
    @NamedQuery(name = "Scenario.getLast2ScenariosFromEdition",
                query = "select o from Scenario o where o.edition = :edition order by o.date desc")
@Table(name = "WEBE_MAKR_DRAAIBOEK")
public class Scenario implements Serializable {
    @Id
    @GeneratedValue(strategy=GenerationType.SEQUENCE, generator="s_webe_makr_draaiboek")
    @Column(name="DRAAIBOEK_ID", nullable = false)
    private Long scenarioID;
    @Column(name="JAAR")
    private Long year;
    @Column(name="WEEK")
    private Long week;
    @Column(name="DATUM")
    private Timestamp date;
    @ManyToOne
    @JoinColumn(name = "EDITIE_ID", referencedColumnName = "EDITIE_ID")
    private Edition edition;
    @OneToMany(mappedBy = "scenario")
    private List<ScenarioItemStatus> scenarioItemStatusList;
    @ManyToOne
    @JoinColumn(name = "VERSCHIJNING_ID", referencedColumnName = "VERSCHIJNING_ID")
    private Issue issue;
    @OneToMany(mappedBy = "scenario")
    private List<ScenarioHistory> scenarioHistoryList;
    // CONSTRUCTOR
    public Scenario() {}
    // GETTERS
    public Long getScenarioID() {
        return scenarioID;
    public Long getYear() {
        return year;
    public Long getWeek() {
        return week;
    public Timestamp getDate() {
        return date;
    public Edition getEdition() {
        return edition;
    public Issue getIssue() {
        return issue;
    public List<ScenarioItemStatus> getScenarioItemStatusList() {
        return scenarioItemStatusList;
    public List<ScenarioHistory> getScenarioHistoryList() {
        return scenarioHistoryList;
    // SETTERS
    public void setScenarioID(Long scenarioID) {
        this.scenarioID = scenarioID;
    public void setDate(Timestamp date) {
        this.date = date;
    public void setYear(Long year) {
        this.year = year;
    public void setWeek(Long week) {
        this.week = week;
    public void setEdition(Edition edition) {
        this.edition = edition;
    public void setIssue(Issue issue) {
        this.issue = issue;
    public void setScenarioItemStatusList(List<ScenarioItemStatus> scenarioItemStatusList) {
        this.scenarioItemStatusList = scenarioItemStatusList;
    public void setScenarioHistoryList(List<ScenarioHistory> scenarioHistoryList) {
        this.scenarioHistoryList = scenarioHistoryList;
    // EXTRA METHODS
    public ScenarioItemStatus addScenarioItemStatus(ScenarioItemStatus scenarioItemStatus) {
        getScenarioItemStatusList().add(scenarioItemStatus);
        scenarioItemStatus.setScenario(this);
        return scenarioItemStatus;
    public ScenarioItemStatus removeScenarioItemStatus(ScenarioItemStatus scenarioItemStatus) {
        getScenarioItemStatusList().remove(scenarioItemStatus);
        scenarioItemStatus.setScenario(null);
        return scenarioItemStatus;
    public ScenarioHistory addScenarioHistory(ScenarioHistory scenarioHistory) {
        getScenarioHistoryList().add(scenarioHistory);
        scenarioHistory.setScenario(this);
        return scenarioHistory;
    public ScenarioHistory removeScenarioHistory(ScenarioHistory scenarioHistory) {
        getScenarioHistoryList().remove(scenarioHistory);
        scenarioHistory.setScenario(null);
        return scenarioHistory;
}Edited by: NeoSniperkiller on 17-apr-2008 14:46

What database and JPA provider are you using? Since you are using a SEQUENCE object to generate the id, you should see it assigned after calling the persist(). Potentially you are using IDENTITY sequencing (not on Oracle), so you must first call flush() to have the id assigned.
see,
[http://en.wikibooks.org/wiki/Java_Persistence/Identity_and_Sequencing#Object.27s_id_is_not_assign_after_persist|http://en.wikibooks.org/wiki/Java_Persistence/Identity_and_Sequencing#Object.27s_id_is_not_assign_after_persist]
-- James : EclipseLink

Similar Messages

  • Adf ejb jpa persistance problem

    Hi everyone,
    I`m a newbie to adf technology.
    I was trying Build a Web Application with JDeveloper 11g Using EJB, JPA, and JavaServer Faces tutorial
    ([http://www.oracle.com/technology/obe/obe11jdev/11/ejb/ejb.html])
    I have a problem when I try to run it.
    It says;
    javax.ejb.EJBException: EJB Exception: ; nested exception is:
    Exception [EclipseLink-4002|http://forums.oracle.com/forums/] (Eclipse Persistence Services - 1.0.1 (Build 20080905)): org.eclipse.persistence.exceptions.DatabaseException
    Internal Exception: java.sql.SQLSyntaxErrorException: ORA-00904: "EMAİL": ge&ccedil;ersiz belirleyici (invalid identifier)
    I thing it`s becouse I use a turkish operating system.
    I tried to change the encoding settings to windows1252 intead of windows 1254 but same problem occures.
    It makes the column EMAIL to EMAİL
    Could you please help me abpout this problem?

    Hi,
    can you print out the value that is received in the session facde to see where the conversion happens?
    Frank

  • Stored procedure, EJB, JPA, and JavaServer Faces

    Hi!
    I am currently working on a Web application using EJB, JPA, and JavaServer Faces. A part of the
    business logic is already stored in the database as stored procedures, so we need to call those
    procedures (instead of named queries) through a EJB and represent the data on the web tier.
    Where can I find an extensive tutorial using this technology? There is no such tutorial in the Oracle Learning Library.
    Maybe somebody can provide a link and/or example.
    Thanks in advance for your help!

    Hi,
    http://download.oracle.com/docs/cd/B10464_05/web.904/b10313/queries.htm#1135305
    For more help, see the TopLink / JPA forum
    TopLink/JPA
    Frank

  • Problems with ADF when running sample EJB, JPA, JSF Tutorial

    Hi,
    I'm new to jDeveloper.
    I've downloaded the version 11.1.1.2.0 and tried to do my first tutorials with the product.
    I started with the sample 'Build Applications with EJB, JPA and JSF' and run to following problems:
    - Part1: Step 10 expose the EJb as a Data Control
    Here right-click FODFacadeBean.java and choose Create Data Control.
    this option 'Create Data Control' does not come up at all. There is not such option
    - Part 2: Step 1 Add Tag Libraries to a project
    The option to select ' ADF Faces Components 11 '
    does not come up either. I can not see any ADF related options...
    Is there something missing from my installation, as I can not access these ADF components ?
    Should I include the ADF components at some stage during the installation to be able to access these
    or is this some licencing option ?
    I downloaded the product yesterday from the public download site, filename jdevstudio11112install.exe
    Jan-Erik

    Hi,
    I'm new to jDeveloper.Welcome to OTN :)
    I've downloaded the version 11.1.1.2.0 and tried to do my first tutorials with the product.
    I started with the sample 'Build Applications with EJB, JPA and JSF' and run to following problems:
    - Part1: Step 10 expose the EJb as a Data Control
    Here right-click FODFacadeBean.java and choose Create Data Control.
    this option 'Create Data Control' does not come up at all. There is not such optionI just tried and able to see the option (and able to generate the DC from the facade as well). Could you please share the tutorial link to see if you are missing something?
    >
    - Part 2: Step 1 Add Tag Libraries to a project
    The option to select ' ADF Faces Components 11 '
    does not come up either. I can not see any ADF related options...Did you select Fusion Web Application (ADF) Template for creating your application? If yes, the ADF Faces Components 11 tag library would've been added by default (Check out in the list of tag libraries that are already added - before clicking on the Add button).
    -Arun

  • Jpa trouble

    hello
    can anyone help me with this problem
    atm i'm making a project which uses EJBs (with JPA) and some fields in the EJBs get auto generated when persisting an EJB entity to the database
    Writing to the database and reading out of it works perfectly, but when i persist a brand new entity to the table, i don't receive the brand new generated ID
    (ID is a primary key in the table)
    is there any way to update the persisted entity right after persisting it to the database ? so that my entity, which got persisted, gets his ID injected?
    this is my code for inserting a new entity into the database:
    @Transactional
    public class JPAScenarioDAO implements ScenarioDAO{
        private EntityManager entityManager;
         * Spring injects entityManager
         * @param entityManager manager that handles persistence operations
        @PersistenceContext
        public void setEntityManager(EntityManager entityManager)
          this.entityManager = entityManager;
        public JPAScenarioDAO() {}
        public void createScenario(Scenario scenario){
            entityManager.persist(scenario); // <-- help?
        public void updateScenario(Scenario scenario){
            entityManager.merge(scenario);
        public void removeScenario(Scenario scenario){
            entityManager.remove(scenario);
    }The scenario is an EJB that i generated from a table
    import java.io.Serializable;
    import java.sql.Timestamp;
    import java.util.List;
    import javax.persistence.Column;
    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.NamedQueries;
    import javax.persistence.NamedQuery;
    import javax.persistence.OneToMany;
    import javax.persistence.Table;
    @Entity
    @NamedQueries({
        @NamedQuery(name = "Scenario.getScenarios",
                    query = "select o from Scenario o"),
        @NamedQuery(name = "Scenario.getScenariosBetweenDates",
                    query = "select o from Scenario o where o.date >= :datum1 and o.date <= :datum2"),
        @NamedQuery(name = "Scenario.getScenariosByEdition",
                    query = "select o from Scenario o where o.edition = :edition"),
        @NamedQuery(name = "Scenario.getScenariosByIssue",
                    query = "select o from Scenario o where o.issue = :issue"),
        @NamedQuery(name = "Scenario.getLast2ScenariosFromEdition",
                    query = "select o from Scenario o where o.edition = :edition order by o.date desc")
    @Table(name = "WEBE_MAKR_DRAAIBOEK")
    public class Scenario implements Serializable {
        @Id
        @GeneratedValue(strategy=GenerationType.SEQUENCE, generator="s_webe_makr_draaiboek")
        @Column(name="DRAAIBOEK_ID", nullable = false)
        private Long scenarioID;
        @Column(name="JAAR")
        private Long year;
        @Column(name="WEEK")
        private Long week;
        @Column(name="DATUM")
        private Timestamp date;
        @ManyToOne
        @JoinColumn(name = "EDITIE_ID", referencedColumnName = "EDITIE_ID")
        private Edition edition;
        @OneToMany(mappedBy = "scenario")
        private List<ScenarioItemStatus> scenarioItemStatusList;
        @ManyToOne
        @JoinColumn(name = "VERSCHIJNING_ID", referencedColumnName = "VERSCHIJNING_ID")
        private Issue issue;
        @OneToMany(mappedBy = "scenario")
        private List<ScenarioHistory> scenarioHistoryList;
        // CONSTRUCTOR
        public Scenario() {}
        // GETTERS
        public Long getScenarioID() {
            return scenarioID;
        public Long getYear() {
            return year;
        public Long getWeek() {
            return week;
        public Timestamp getDate() {
            return date;
        public Edition getEdition() {
            return edition;
        public Issue getIssue() {
            return issue;
        public List<ScenarioItemStatus> getScenarioItemStatusList() {
            return scenarioItemStatusList;
        public List<ScenarioHistory> getScenarioHistoryList() {
            return scenarioHistoryList;
        // SETTERS
        public void setScenarioID(Long scenarioID) {
            this.scenarioID = scenarioID;
        public void setDate(Timestamp date) {
            this.date = date;
        public void setYear(Long year) {
            this.year = year;
        public void setWeek(Long week) {
            this.week = week;
        public void setEdition(Edition edition) {
            this.edition = edition;
        public void setIssue(Issue issue) {
            this.issue = issue;
        public void setScenarioItemStatusList(List<ScenarioItemStatus> scenarioItemStatusList) {
            this.scenarioItemStatusList = scenarioItemStatusList;
        public void setScenarioHistoryList(List<ScenarioHistory> scenarioHistoryList) {
            this.scenarioHistoryList = scenarioHistoryList;
        // EXTRA METHODS
        public ScenarioItemStatus addScenarioItemStatus(ScenarioItemStatus scenarioItemStatus) {
            getScenarioItemStatusList().add(scenarioItemStatus);
            scenarioItemStatus.setScenario(this);
            return scenarioItemStatus;
        public ScenarioItemStatus removeScenarioItemStatus(ScenarioItemStatus scenarioItemStatus) {
            getScenarioItemStatusList().remove(scenarioItemStatus);
            scenarioItemStatus.setScenario(null);
            return scenarioItemStatus;
        public ScenarioHistory addScenarioHistory(ScenarioHistory scenarioHistory) {
            getScenarioHistoryList().add(scenarioHistory);
            scenarioHistory.setScenario(this);
            return scenarioHistory;
        public ScenarioHistory removeScenarioHistory(ScenarioHistory scenarioHistory) {
            getScenarioHistoryList().remove(scenarioHistory);
            scenarioHistory.setScenario(null);
            return scenarioHistory;
    }Edited by: NeoSniperkiller on 17-apr-2008 14:44

    public void createScenario(Scenario scenario){
            entityManager.persist(scenario); // <-- help?
        }I've seen this happen.
    Changing it to
    public Scenario createScenario(Scenario scenario){
            entityManager.persist(scenario); // <-- help?
            return scenario;
        }(and using the returned value) for some reason worked.
    Not quite sure yet why, I'll have to do some research to figure out exactly what happens.

  • C++ Look alike for Java EJB-- JPA-- Backing Store

    Hi All,
    I'm familar with the creation of an EJB data model , JPA, and tying it into Coherence via Toplink Essentials to the Data Store of my choice. What is the mechanizum used for doing the same with a C++ client wrting cache objects and having Coherence back store those ojects to a database of chioce?

    Hi Morsie,
    C++ is only supported for Extend clients.
    Here is some information on C++ extend clients:
    http://coherence.oracle.com/pages/viewpage.action?pageId=1343491
    Extend clients are not actually members of the cluster but instead connect to the cluster via TCP/IP. So, since cache store operations occur in the cluster, they are completely unaffected by the fact that you are accessing a cache via a C++ Extend client.
    Please let me know if you have any further questions.
    -John

  • EJB - JPA Controller Not Work in EJB

    In the beginning, I created a EAR application by following the tutorial at http://wiki.netbeans.org/DevelopJavaEE6App/
    After the application was completed successfully, as I wanted the Session Bean focusing business logic more, I utilized NetBeans wizard to create JPA Controller from Entities and moved all data manipulation methods from the Session Bean to the JPA Controller. As a result, it did not work.
    CustomerJpaController:
    package com.customerapp.jpa;
    import com.customerapp.entity.Customer;
    import com.customerapp.jpa.exceptions.NonexistentEntityException;
    import com.customerapp.jpa.exceptions.PreexistingEntityException;
    import java.util.List;
    import javax.persistence.EntityManager;
    import javax.persistence.EntityManagerFactory;
    import javax.persistence.Persistence;
    import javax.persistence.Query;
    import javax.persistence.EntityNotFoundException;
    import javax.persistence.criteria.CriteriaQuery;
    import javax.persistence.criteria.Root;
    import com.customerapp.entity.DiscountCode;
    public class CustomerJpaController {
        public CustomerJpaController() {
            emf = Persistence.createEntityManagerFactory("CustomerApp-ejbPU");
        private EntityManagerFactory emf = null;
        public EntityManager getEntityManager() {
            return emf.createEntityManager();
        public void create(Customer customer) throws PreexistingEntityException, Exception {
            EntityManager em = null;
            try {
                em = getEntityManager();
                em.getTransaction().begin();
                DiscountCode discountCode = customer.getDiscountCode();
                if (discountCode != null) {
                    discountCode = em.getReference(discountCode.getClass(), discountCode.getDiscountCode());
                    customer.setDiscountCode(discountCode);
                em.persist(customer);
                if (discountCode != null) {
                    discountCode.getCustomerList().add(customer);
                    discountCode = em.merge(discountCode);
                em.getTransaction().commit();
            } catch (Exception ex) {
                if (findCustomer(customer.getCustomerId()) != null) {
                    throw new PreexistingEntityException("Customer " + customer + " already exists.", ex);
                throw ex;
            } finally {
                if (em != null) {
                    em.close();
        public void edit(Customer customer) throws NonexistentEntityException, Exception {
            EntityManager em = null;
            try {
                em = getEntityManager();
                em.getTransaction().begin();
                Customer persistentCustomer = em.find(Customer.class, customer.getCustomerId());
                DiscountCode discountCodeOld = persistentCustomer.getDiscountCode();
                DiscountCode discountCodeNew = customer.getDiscountCode();
                if (discountCodeNew != null) {
                    discountCodeNew = em.getReference(discountCodeNew.getClass(), discountCodeNew.getDiscountCode());
                    customer.setDiscountCode(discountCodeNew);
                customer = em.merge(customer);
                if (discountCodeOld != null && !discountCodeOld.equals(discountCodeNew)) {
                    discountCodeOld.getCustomerList().remove(customer);
                    discountCodeOld = em.merge(discountCodeOld);
                if (discountCodeNew != null && !discountCodeNew.equals(discountCodeOld)) {
                    discountCodeNew.getCustomerList().add(customer);
                    discountCodeNew = em.merge(discountCodeNew);
                em.getTransaction().commit();
            } catch (Exception ex) {
                String msg = ex.getLocalizedMessage();
                if (msg == null || msg.length() == 0) {
                    Integer id = customer.getCustomerId();
                    if (findCustomer(id) == null) {
                        throw new NonexistentEntityException("The customer with id " + id + " no longer exists.");
                throw ex;
            } finally {
                if (em != null) {
                    em.close();
        public void destroy(Integer id) throws NonexistentEntityException {
            EntityManager em = null;
            try {
                em = getEntityManager();
                em.getTransaction().begin();
                Customer customer;
                try {
                    customer = em.getReference(Customer.class, id);
                    customer.getCustomerId();
                } catch (EntityNotFoundException enfe) {
                    throw new NonexistentEntityException("The customer with id " + id + " no longer exists.", enfe);
                DiscountCode discountCode = customer.getDiscountCode();
                if (discountCode != null) {
                    discountCode.getCustomerList().remove(customer);
                    discountCode = em.merge(discountCode);
                em.remove(customer);
                em.getTransaction().commit();
            } finally {
                if (em != null) {
                    em.close();
        public List<Customer> findCustomerEntities() {
            return findCustomerEntities(true, -1, -1);
        public List<Customer> findCustomerEntities(int maxResults, int firstResult) {
            return findCustomerEntities(false, maxResults, firstResult);
        private List<Customer> findCustomerEntities(boolean all, int maxResults, int firstResult) {
            EntityManager em = getEntityManager();
            try {
                CriteriaQuery cq = em.getCriteriaBuilder().createQuery();
                cq.select(cq.from(Customer.class));
                Query q = em.createQuery(cq);
                if (!all) {
                    q.setMaxResults(maxResults);
                    q.setFirstResult(firstResult);
                return q.getResultList();
            } finally {
                em.close();
        public Customer findCustomer(Integer id) {
            EntityManager em = getEntityManager();
            try {
                return em.find(Customer.class, id);
            } finally {
                em.close();
        public int getCustomerCount() {
            EntityManager em = getEntityManager();
            try {
                CriteriaQuery cq = em.getCriteriaBuilder().createQuery();
                Root<Customer> rt = cq.from(Customer.class);
                cq.select(em.getCriteriaBuilder().count(rt));
                Query q = em.createQuery(cq);
                return ((Long) q.getSingleResult()).intValue();
            } finally {
                em.close();
    }How can I integrate my EJB with my JPA controller? Please help

    CustomerSessionBean:
    package com.customerapp.ejb;
    import java.util.logging.Level;
    import java.util.logging.Logger;
    import javax.annotation.Resource;
    import javax.ejb.Stateless;
    import javax.ejb.LocalBean;
    import javax.annotation.PostConstruct;
    import javax.annotation.PreDestroy;
    import javax.jms.Connection;
    import javax.jms.ConnectionFactory;
    import javax.jms.JMSException;
    import javax.jms.Message;
    import javax.jms.MessageProducer;
    import javax.jms.Queue;
    import javax.jms.Session;
    import javax.jms.TextMessage;
    import java.util.List;
    import com.customerapp.entity.Customer;
    import com.customerapp.entity.DiscountCode;
    import com.customerapp.jpa.CustomerJpaController;
    import com.customerapp.jpa.DiscountCodeJpaController;
    @Stateless
    @LocalBean
    public class CustomerSessionBean {
        @Resource(name = "jms/NotificationQueue")
        private Queue notificationQueue;
        @Resource(name = "jms/NotificationQueueFactory")
        private ConnectionFactory notificationQueueFactory;
        CustomerJpaController customerJpa;
        DiscountCodeJpaController discountCodeJpa;
        @PostConstruct
        public void initJpa(){
            customerJpa = new CustomerJpaController();
            discountCodeJpa = new DiscountCodeJpaController();
        @PreDestroy
        public void removeJpa() {
            customerJpa = null;
            discountCodeJpa = null;
        public void create(Customer customer) {
            try {
                customerJpa.create(customer);
            } catch (Exception ex) {
                Logger.getLogger(CustomerSessionBean.class.getName()).log(Level.SEVERE, null, ex);
        public List<Customer> retrieve() {       
            return customerJpa.findCustomerEntities();
        public Customer update(Customer customer) {
            Customer updatedCustomer;
            try {
                Integer customerId = customer.getCustomerId();
                customerJpa.edit(customer);
                updatedCustomer = customerJpa.findCustomer(customerId);
                sendJMSMessageToNotificationQueue(updatedCustomer);
                System.out.println("Customer updated in CustomerSessionBean!");
                return updatedCustomer;
            } catch (JMSException ex) {
                Logger.getLogger(CustomerSessionBean.class.getName()).log(Level.SEVERE, null, ex);
            } catch (Exception ex) {
                Logger.getLogger(CustomerSessionBean.class.getName()).log(Level.SEVERE, null, ex);
            return customer;
        public List<DiscountCode> getDiscountCodes() {
            return discountCodeJpa.findDiscountCodeEntities();
        private Message createJMSMessageForjmsNotificationQueue(Session session, Object messageData) throws JMSException {
            TextMessage tm = session.createTextMessage();
            tm.setText(messageData.toString());
            return tm;
        private void sendJMSMessageToNotificationQueue(Object messageData) throws JMSException {
            Connection connection = null;
            Session session = null;
            try {
                connection = notificationQueueFactory.createConnection();
                session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
                MessageProducer messageProducer = session.createProducer(notificationQueue);
                messageProducer.send(createJMSMessageForjmsNotificationQueue(session, messageData));
            } finally {
                if (session != null) {
                    try {
                        session.close();
                    } catch (JMSException e) {
                        Logger.getLogger(this.getClass().getName()).log(Level.WARNING, "Cannot close session", e);
                if (connection != null) {
                    connection.close();
    }ERROR:
    Caused by: java.lang.IllegalArgumentException: The type [null] is not the expected [EntityType] for the key class [class com.customerapp.entity.Customer].
            at org.eclipse.persistence.internal.jpa.metamodel.MetamodelImpl.entity(MetamodelImpl.java:152)
            at org.eclipse.persistence.internal.jpa.querydef.AbstractQueryImpl.from(AbstractQueryImpl.java:97)
            at com.customerapp.jpa.CustomerJpaController.findCustomerEntities(CustomerJpaController.java:140)
            at com.customerapp.jpa.CustomerJpaController.findCustomerEntities(CustomerJpaController.java:129)
            at com.customerapp.ejb.CustomerSessionBean.retrieve(CustomerSessionBean.java:64)

  • Error while deploying the EJB - JPA - Hibernate application

    Hi guys,
    i got following exception while deploying my application into the server. can anyone suggest me.
    Failure occurred in the execution of deployment request with ID '1243505041748' for task '0'. Error is: 'java.lang.ClassNotFoundException: org.jboss.util.file.ArchiveBrowser$Filter' java.lang.ClassNotFoundException: org.jboss.util.file.ArchiveBrowser$Filter at java.net.URLClassLoader$1.run(URLClassLoader.java:200) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:188) at java.lang.ClassLoader.loadClass(ClassLoader.java:306) at java.lang.ClassLoader.loadClass(ClassLoader.java:251) at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319) at java.lang.ClassLoader.defineClass1(Native Method) at java.lang.ClassLoader.defineClass(ClassLoader.java:620) at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:124) at java.net.URLClassLoader.defineClass(URLClassLoader.java:260) at java.net.URLClassLoader.access$000(URLClassLoader.java:56) at java.net.URLClassLoader$1.run(URLClassLoader.java:195) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:188) at java.lang.ClassLoader.loadClass(ClassLoader.java:306) at java.lang.ClassLoader.loadClass(ClassLoader.java:251) at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319) at org.hibernate.ejb.Ejb3Configuration.scanForClasses(Ejb3Configuration.java:626) at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:350) at org.hibernate.ejb.HibernatePersistence.createContainerEntityManagerFactory(HibernatePersistence.java:126) at weblogic.deployment.PersistenceUnitInfoImpl.createEntityManagerFactory(PersistenceUnitInfoImpl.java:330) at weblogic.deployment.PersistenceUnitInfoImpl.<init>(PersistenceUnitInfoImpl.java:123) at weblogic.deployment.AbstractPersistenceUnitRegistry.storeDescriptors(AbstractPersistenceUnitRegistry.java:331) at weblogic.deployment.AbstractPersistenceUnitRegistry.loadPersistenceDescriptor(AbstractPersistenceUnitRegistry.java:245) at weblogic.deployment.ModulePersistenceUnitRegistry.<init>(ModulePersistenceUnitRegistry.java:63) at weblogic.ejb.container.deployer.EJBModule.setupPersistenceUnitRegistry(EJBModule.java:209) at weblogic.ejb.container.deployer.EJBModule$1.execute(EJBModule.java:310) at weblogic.deployment.PersistenceUnitRegistryInitializer.setupPersistenceUnitRegistries(PersistenceUnitRegistryInitializer.java:62) at weblogic.servlet.internal.WebAppModule.prepare(WebAppModule.java:381) at weblogic.application.internal.flow.ScopedModuleDriver.prepare(ScopedModuleDriver.java:176) at weblogic.application.internal.flow.ModuleListenerInvoker.prepare(ModuleListenerInvoker.java:93) at weblogic.application.internal.flow.DeploymentCallbackFlow$1.next(DeploymentCallbackFlow.java:387) at weblogic.application.utils.StateMachineDriver.nextState(StateMachineDriver.java:37) at weblogic.application.internal.flow.DeploymentCallbackFlow.prepare(DeploymentCallbackFlow.java:58) at weblogic.application.internal.flow.DeploymentCallbackFlow.prepare(DeploymentCallbackFlow.java:42) at weblogic.application.internal.BaseDeployment$1.next(BaseDeployment.java:615) at weblogic.application.utils.StateMachineDriver.nextState(StateMachineDriver.java:37) at weblogic.application.internal.BaseDeployment.prepare(BaseDeployment.java:191) at weblogic.application.internal.EarDeployment.prepare(EarDeployment.java:16) at weblogic.application.internal.DeploymentStateChecker.prepare(DeploymentStateChecker.java:155) at weblogic.deploy.internal.targetserver.AppContainerInvoker.prepare(AppContainerInvoker.java:60) at weblogic.deploy.internal.targetserver.operations.ActivateOperation.createAndPrepareContainer(ActivateOperation.java:197) at weblogic.deploy.internal.targetserver.operations.ActivateOperation.doPrepare(ActivateOperation.java:89) at weblogic.deploy.internal.targetserver.operations.AbstractOperation.prepare(AbstractOperation.java:217) at weblogic.deploy.internal.targetserver.DeploymentManager.handleDeploymentPrepare(DeploymentManager.java:723) at weblogic.deploy.internal.targetserver.DeploymentManager.prepareDeploymentList(DeploymentManager.java:1190) at weblogic.deploy.internal.targetserver.DeploymentManager.handlePrepare(DeploymentManager.java:248) at weblogic.deploy.internal.targetserver.DeploymentServiceDispatcher.prepare(DeploymentServiceDispatcher.java:159) at weblogic.deploy.service.internal.targetserver.DeploymentReceiverCallbackDeliverer.doPrepareCallback(DeploymentReceiverCallbackDeliverer.java:157) at weblogic.deploy.service.internal.targetserver.DeploymentReceiverCallbackDeliverer.access$000(DeploymentReceiverCallbackDeliverer.java:12) at weblogic.deploy.service.internal.targetserver.DeploymentReceiverCallbackDeliverer$1.run(DeploymentReceiverCallbackDeliverer.java:45) at weblogic.work.SelfTuningWorkManagerImpl$WorkAdapterImpl.run(SelfTuningWorkManagerImpl.java:516) at weblogic.work.ExecuteThread.execute(ExecuteThread.java:201) at weblogic.work.ExecuteThread.run(ExecuteThread.java:173) java.lang.ClassNotFoundException: org.jboss.util.file.ArchiveBrowser$Filter at java.net.URLClassLoader$1.run(URLClassLoader.java:200) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:188) at java.lang.ClassLoader.loadClass(ClassLoader.java:306) at java.lang.ClassLoader.loadClass(ClassLoader.java:251) at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319) at java.lang.ClassLoader.defineClass1(Native Method) at java.lang.ClassLoader.defineClass(ClassLoader.java:620) at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:124) at java.net.URLClassLoader.defineClass(URLClassLoader.java:260) at java.net.URLClassLoader.access$000(URLClassLoader.java:56) at java.net.URLClassLoader$1.run(URLClassLoader.java:195) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:188) at java.lang.ClassLoader.loadClass(ClassLoader.java:306) at java.lang.ClassLoader.loadClass(ClassLoader.java:251) at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319) at org.hibernate.ejb.Ejb3Configuration.scanForClasses(Ejb3Configuration.java:626) at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:350) at org.hibernate.ejb.HibernatePersistence.createContainerEntityManagerFactory(HibernatePersistence.java:126) at weblogic.deployment.PersistenceUnitInfoImpl.createEntityManagerFactory(PersistenceUnitInfoImpl.java:330) at weblogic.deployment.PersistenceUnitInfoImpl.<init>(PersistenceUnitInfoImpl.java:123) at weblogic.deployment.AbstractPersistenceUnitRegistry.storeDescriptors(AbstractPersistenceUnitRegistry.java:331) at weblogic.deployment.AbstractPersistenceUnitRegistry.loadPersistenceDescriptor(AbstractPersistenceUnitRegistry.java:245) at weblogic.deployment.ModulePersistenceUnitRegistry.<init>(ModulePersistenceUnitRegistry.java:63) at weblogic.ejb.container.deployer.EJBModule.setupPersistenceUnitRegistry(EJBModule.java:209) at weblogic.ejb.container.deployer.EJBModule$1.execute(EJBModule.java:310) at weblogic.deployment.PersistenceUnitRegistryInitializer.setupPersistenceUnitRegistries(PersistenceUnitRegistryInitializer.java:62) at weblogic.servlet.internal.WebAppModule.prepare(WebAppModule.java:381) at weblogic.application.internal.flow.ScopedModuleDriver.prepare(ScopedModuleDriver.java:176) at weblogic.application.internal.flow.ModuleListenerInvoker.prepare(ModuleListenerInvoker.java:93) at weblogic.application.internal.flow.DeploymentCallbackFlow$1.next(DeploymentCallbackFlow.java:387) at weblogic.application.utils.StateMachineDriver.nextState(StateMachineDriver.java:37) at weblogic.application.internal.flow.DeploymentCallbackFlow.prepare(DeploymentCallbackFlow.java:58) at weblogic.application.internal.flow.DeploymentCallbackFlow.prepare(DeploymentCallbackFlow.java:42) at weblogic.application.internal.BaseDeployment$1.next(BaseDeployment.java:615) at weblogic.application.utils.StateMachineDriver.nextState(StateMachineDriver.java:37) at weblogic.application.internal.BaseDeployment.prepare(BaseDeployment.java:191) at weblogic.application.internal.EarDeployment.prepare(EarDeployment.java:16) at weblogic.application.internal.DeploymentStateChecker.prepare(DeploymentStateChecker.java:155) at weblogic.deploy.internal.targetserver.AppContainerInvoker.prepare(AppContainerInvoker.java:60) at weblogic.deploy.internal.targetserver.operations.ActivateOperation.createAndPrepareContainer(ActivateOperation.java:197) at weblogic.deploy.internal.targetserver.operations.ActivateOperation.doPrepare(ActivateOperation.java:89) at weblogic.deploy.internal.targetserver.operations.AbstractOperation.prepare(AbstractOperation.java:217) at weblogic.deploy.internal.targetserver.DeploymentManager.handleDeploymentPrepare(DeploymentManager.java:723) at weblogic.deploy.internal.targetserver.DeploymentManager.prepareDeploymentList(DeploymentManager.java:1190) at weblogic.deploy.internal.targetserver.DeploymentManager.handlePrepare(DeploymentManager.java:248) at weblogic.deploy.internal.targetserver.DeploymentServiceDispatcher.prepare(DeploymentServiceDispatcher.java:159) at weblogic.deploy.service.internal.targetserver.DeploymentReceiverCallbackDeliverer.doPrepareCallback(DeploymentReceiverCallbackDeliverer.java:157) at weblogic.deploy.service.internal.targetserver.DeploymentReceiverCallbackDeliverer.access$000(DeploymentReceiverCallbackDeliverer.java:12) at weblogic.deploy.service.internal.targetserver.DeploymentReceiverCallbackDeliverer$1.run(DeploymentReceiverCallbackDeliverer.java:45) at weblogic.work.SelfTuningWorkManagerImpl$WorkAdapterImpl.run(SelfTuningWorkManagerImpl.java:516) at weblogic.work.ExecuteThread.execute(ExecuteThread.java:201) at weblogic.work.ExecuteThread.run(ExecuteThread.java:17
    I am using
    Hibernate 3.2
    EJB 3
    WebLogic 10.3
    MyEclipse 6.6

    I think I've seen this before and I believe that it might the way Hibernate 3.2 loads classes. I seem to remember actually patching this myself using a fix someone made at one point and getting it to work, but that used to be documented on a dev2dev blog comment that is no longer around :(
    Here are some hints on similar errors:
    https://jira.jboss.org/jira/browse/EJBTHREE-719
    http://forums.java.net/jive/thread.jspa?threadID=16472
    Some Hibernate issues with ANTLR can be resolved if you can put all of the relevant classes in your web-inf/lib or app-inf/lib and use the appropriate deployment descriptors to "prefer" your classes.
    http://download.oracle.com/docs/cd/E12839_01/wls/docs103/webapp/weblogic_xml.html#wp1059286
    There are other similar errors that you might encounter
    http://maniezhilan.blogspot.com/2008/02/hibernate-antlrjar-with-weblogic-server.html

  • JPA: trouble removing a 1:M cascade ALL relationship from entity

    I have an entity A, with a OneToMany relationship to entity B, and cascade set to ALL.  Entity B has a ManyToOne relationship to A.  In my scenario I create a new instance of B to a detached instance of A, and I add it to the 1:M of A and set the M:1 on B.
    Then I'd like to merge the changes on A using EntityManager.merge(A).  However, before I do that I need to remove a different (old) instance of B from A, and then merge my changes so that my new instance of B is persisted.
    I've tried a couple different scenarios and get different results (none favorable):
    1.  First lookup the instance of B I want to remove via EntityManager.find(id), and then call EM.remove(B).  And then I call EM.merge(A) on the instance of A with my new B.  I get the following IllegalArgumentException during the merge:
    java.lang.IllegalArgumentException: Cannot fulfill merge operation: Relationship >>outputElementInstances<< of the target entity {com.sap.eventus.wire.entity.EvtWireInstance(id=85e83543-45d1-49cd-bb90-8688699ca0d4)} has been modified
    The relationship it's talking about is actually a different (but related) one that was affected when the old instance of B was removed.  It seems reasonable that JPA has determined that my instance of A with the new B is no longer in sync with the database and is complaining that a relationship has been changed.
    Any ways around that?
    2. I also tried simply removing B from A's 1:M, and setting B's M:1 to null, and then merging in hopes that would trigger a delete on the old B.  However the old B is not removed.
    I was expecting this to trigger a delete, however, I realize that there are other relationships from B to other objects (such as a 1:M cascade ALL) that I did not remove which I suspect might cause JPA to not delete the old B.  Is this true?
    3. And finally I tried 1 & 2 together, first calling EM.remove(old B), and then removing the old B from A and then merging, which yields the following IllegalStateException:
    java.lang.IllegalStateException: Relationship >>wireInstance<< of entity {com.sap.eventus.wire.entity.EvtElementInstance(id=08ca6253-1385-45dd-9173-978ee298b55f)} contains the new entity {com.sap.eventus.wire.entity.EvtWireInstance(id=c9fbd4e7-5575-4cc9-9b7d-2a8549c43574)}
    Which is another different (but related) relationship off of object B.
    Basically, after all this, my question is: what is the correct way to remove a 1:M relationship and add a new one?  Simple enough, however I do not want to remove the old 1:M, re-query to get the new updated parent object and then add the new 1:M, as it's a fairly involved in creating and adding the new 1:M and it must be done BEFORE removing the old 1:M.
    Thanks!

    Hi Derek,
    I understand your task as follows:
    You are having three entities A, B_old and B_new. Within one transaction you want to do the following:
    - remove B_old from the database
    - remove B_old from the 1:n relationship A.bs
    - persist the B_new
    - add B_new to the 1:n relationship A.bs
    - set the n:1 relationship B_new.a to refer to A
    well, I suggest that you do this without a merge:
    - em.remove(B_old)  // you have to do this explicitly as JPA 1 does not have automatic orphan removal
    - A.bs.remove(B_old)
    - em.persist(B_new) // also, you have to make sure that the entities related to B_new are managed upon commit
    - A.bs.add(B_new)
    - B_new.a = A
    I hope this works.
    Regarding your observations:
    1. The error message is not self-explaining. We have got to improve it ;-).
    2. You have to remove the B_old explicitly as JPA 1 does not have automatic orphan removal. 
    3. This message should be self-explaining. Maybe there is one of the relationships EvtOutputElementInstance.wireInstance or EvtInputElementInstance.wireInstance still referring B_new. You'll surely find out.
    Regards,
    Adrian

  • EJB/JPA Related: Objects are not going to delete from a Collection

    Hi All,
    I am developing a WebDynpro application using EJB3 model with JPA as a persistence tool. I have mapped using Annotations.
    All other works run fine but If I deleted a record through view It will not delete from database.
    I have two entities : First : OperationDayWorkingCapitalPlan in which following relation is defined:
         @OneToMany(mappedBy="operationDayWorkingCapitalPlan",targetEntity=BranchPartyCollectionsPlan.class,
           fetch=FetchType.EAGER, cascade=CascadeType.ALL)
         private Collection<BranchPartyCollectionsPlan> branchPartyCollectionsPlans = new  
           ArrayList<BranchPartyCollectionsPlan>();
    related methods:
         public Collection<BranchPartyCollectionsPlan> getBranchPartyCollectionsPlans() {
              return branchPartyCollectionsPlans;
         public void setBranchPartyCollectionsPlans(
                   Collection<BranchPartyCollectionsPlan> branchPartyCollectionsPlans) {
              this.branchPartyCollectionsPlans = branchPartyCollectionsPlans;
         public void addBranchPartyCollectionsPlan(BranchPartyCollectionsPlan branchPartyCollectionsPlan) {
            this.branchPartyCollectionsPlans.add(branchPartyCollectionsPlan);
            if (branchPartyCollectionsPlan.getOperationDayWorkingCapitalPlan() == null || branchPartyCollectionsPlan.getOperationDayWorkingCapitalPlan() != this) {       
                 branchPartyCollectionsPlan.setOperationDayWorkingCapitalPlan(this);
         public void removeBranchPartyCollectionsPlan(BranchPartyCollectionsPlan branchPartyCollectionsPlan) {
              if (branchPartyCollectionsPlan == null)
                   return;
              if (this.branchPartyCollectionsPlans != null)
                   if (this.branchPartyCollectionsPlans.remove(branchPartyCollectionsPlan)) {
                        branchPartyCollectionsPlan.setOperationDayWorkingCapitalPlan((OperationDayWorkingCapitalPlan)null);
    and Second one is : BranchPartyCollectionsPlan in which the following relation(inverse) is defined:
    @ManyToOne(fetch=FetchType.EAGER)
         @JoinColumn(name="OPERATIONDAYWORKINGCAPITALPLANID")
         OperationDayWorkingCapitalPlan operationDayWorkingCapitalPlan
      related getter and setter:
         public OperationDayWorkingCapitalPlan getOperationDayWorkingCapitalPlan() {
              return operationDayWorkingCapitalPlan;
         public void setOperationDayWorkingCapitalPlan(
                   OperationDayWorkingCapitalPlan operationDayWorkingCapitalPlan) {
              OperationDayWorkingCapitalPlan oldOperationDayWorkingCapitalPlan = this.operationDayWorkingCapitalPlan;
              if (oldOperationDayWorkingCapitalPlan != null){
                   oldOperationDayWorkingCapitalPlan.removeBranchPartyCollectionsPlan(this);
              this.operationDayWorkingCapitalPlan = operationDayWorkingCapitalPlan;
              if (operationDayWorkingCapitalPlan != null){
                   operationDayWorkingCapitalPlan.addBranchPartyCollectionsPlan(this);
    Plz help me where am I wrong. Why objects(BranchPartyCollectionsPlan) from collection not delete when I merge the main object (OperationDayWorkingCapitalPlan).
    Edited by: kapitsu on Oct 27, 2009 10:24 AM

    Hi Mayank,
    You can check the below Link.
    PSA Not Deleting, error : DDL time(___1):.....0 milliseconds
    Regards
    Rahul

  • What data binding framework to use for EJB(JPA) - Swing desktop application

    Hi!
    I am developing EJB server application which mostly uses the same entities and session EJB's both for web and for desktop user interface. While JSF is working nicely, I am stuck with necessity to make decision with data binding framework to use for desktop application - I investigated:
    - JSR295 reference impementation at java.net (beans binding)
    - Eclipse JFace
    - JSR295 implementation at kenai.com (better beans binding)
    - JGoodies binding
    At present I like JGoodies, but I am not sure whether I am not missing something - I guess - large enterprises should develop a lot of desktop applications as well and what binding framework they are using?

    user454720 wrote:
    At present I like JGoodies, but I am not sure whether I am not missing something - I guess - large enterprises should develop a lot of desktop applications as well and what binding framework they are using?No, not really. I create them sometimes but they are service tools, not part of the main application framework. Generally you keep everything on the server, web based - this keeps it secure, accessible and contained. With all the web 2.0 javascript toolkits available nowadays you can go quite far creating a desktop experience in a browser, with limitations.

  • EJB/JPA Session/Entity Bean: Back Reference Id not set

    Hello All,
    I m using JPA as a persist tool. I have an entity Account and in Account there is a collection of entity AccountDetail. In Account entity relation for AccountDetail is One-To-Many and in AccountDetail the relation for Account is Many-To-One. When i save the Account, object of Account and AccountDetail are saved correctly. But the problem is that in AccountDetail the Id of Account is not saved in Database table. I have AccountId in AccountDetail table. plz help me??
    Second thing is that how to generate automatically primary keys when entity saved in database ???

    define the column you want to auto increment as an Integer with Identity attribute set to True (using the sql server management tool for example) and then put
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    in front of the ID declaration in the mapping file, it should generate the IDs automatically.

  • EJB, JPA E MANAGED BEAN WITHOUT DATA CONTROL

    How do I build a simple crud with no EJB without data controls. Exposing the methods of my bean class.
    Who can help me thanks.
    Edited by: 941064 on 15/06/2012 14:48

    You'll write managed beans that access your EJB service facade.
    You can use @EJB injection to get this working.
    http://biemond.blogspot.co.uk/2010/04/ejb-injection-in-jsf-managed-bean.html

  • JDeveloper 11g Using EJB, JPA AND ADF DOES NOT WORK IN VERSION 11.1.1.1.0

    Hi all,
    I'm facing serious problems after the migration from jdev 11.1.1.0 version to new release 11.1.1.1.0, as i published with a sample at
    Problems with create new record o in JDev 11 R1
    is this a big bug in the ide? Should i return to previous version?
    Thanks in advance
    Enrique

    Hi,
    my best recommendation is to work with customer supports in this testcase.
    Frank

  • Toplink, EJB, JPA, and GlassFish

    Hi, I need call a stored procedure from a SessionBean using de toplink:
    I need obtain a toplink Session object to call de stored procedure, ¿How can I obtain this from the EntityManager object?

    Why don't you try native queries?

Maybe you are looking for

  • ITunes Match used for 2 computers?

    I am interested in iTunes Match. I am a DJ and I use a Macbook pro for my my primary computer  and a Macbook for a back up. I do not like having to  constantly update my back up computer.  I do not have Lion yet either, so I know I will have to upgra

  • CD Burn Failure

    Using my Intel MacBook Pro running 10.5.5, I got this message when I tried to burn a Sony RW CD. "This disc could not be verified and might be unreliable. Try again using a new, blank disc. (Error code 0x80020063)" Tried erasing the CD with Disk util

  • Pivot table - calculate difference between 2 data points

    I have a pivot table that shows Q1 2008 revenue, and Q1 2009 revenue, by account. How do I create a summary column on the right that shows the difference between these 2 values? 2009 value minus 2008 value. example: 2008 2009 Account Q1 Q1 Revenue Gr

  • Hardware monitor error

    have any of you experienced spontaneous system shut downs followed by bios reports of 'hardware monitor error' press delete to enter setup etc.  My system has been brought to its knees by this and the good people at samsung have told me that it is pr

  • Display error message on jsp if there is an exception during pdf generation

    I am displaying pdf from my application and when the pdf document is found, it is displaying properly. Only problem is when the document is not found i want to display the jsp with an error message to the user. I am using IE and IE has a bug that it