Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7011285
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T22:06:27+00:00 2026-05-27T22:06:27+00:00

I’m using GlassFish 3.1.1. and NetBeans 6.9.1. In NetBeans, I created web application and

  • 0

I’m using GlassFish 3.1.1. and NetBeans 6.9.1.
In NetBeans, I created web application and generated an entity class. Only thing I added is the @GeneratedValue annotation. Here is the code:

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package entities.worker;

import java.io.Serializable;
import java.util.Date;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

/**
 *
 * @author pzielins
 */
@Entity
@Table(name = "cdrconfig", catalog = "cdrworker_db", schema = "public")
@NamedQueries({
    @NamedQuery(name = "CdrConfig.findAll", query = "SELECT c FROM CdrConfig c"),
    @NamedQuery(name = "CdrConfig.findById", query = "SELECT c FROM CdrConfig c WHERE c.id = :id"),
    @NamedQuery(name = "CdrConfig.findByCdrpath", query = "SELECT c FROM CdrConfig c WHERE c.cdrpath = :cdrpath"),
    @NamedQuery(name = "CdrConfig.findByWorkerinterval", query = "SELECT c FROM CdrConfig c WHERE c.workerinterval = :workerinterval"),
    @NamedQuery(name = "CdrConfig.findByMakebackup", query = "SELECT c FROM CdrConfig c WHERE c.makebackup = :makebackup"),
    @NamedQuery(name = "CdrConfig.findByBackuppath", query = "SELECT c FROM CdrConfig c WHERE c.backuppath = :backuppath"),
    @NamedQuery(name = "CdrConfig.findByLastsyncdate", query = "SELECT c FROM CdrConfig c WHERE c.lastsyncdate = :lastsyncdate"),
    @NamedQuery(name = "CdrConfig.findByWaslastsyncmanual", query = "SELECT c FROM CdrConfig c WHERE c.waslastsyncmanual = :waslastsyncmanual")})
public class CdrConfig implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy=GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "id", nullable = false)
    private Integer id;
    @Column(name = "cdrpath", length = 10485760)
    private String cdrpath;
    @Column(name = "workerinterval")
    private Integer workerinterval;
    @Column(name = "makebackup")
    private Boolean makebackup;
    @Column(name = "backuppath", length = 10485760)
    private String backuppath;
    @Column(name = "lastsyncdate")
    @Temporal(TemporalType.TIMESTAMP)
    private Date lastsyncdate;
    @Column(name = "waslastsyncmanual")
    private Boolean waslastsyncmanual;

    public CdrConfig() {
    }

    public CdrConfig(Integer id) {
        this.id = id;
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getCdrpath() {
        return cdrpath;
    }

    public void setCdrpath(String cdrpath) {
        this.cdrpath = cdrpath;
    }

    public Integer getWorkerinterval() {
        return workerinterval;
    }

    public void setWorkerinterval(Integer workerinterval) {
        this.workerinterval = workerinterval;
    }

    public Boolean getMakebackup() {
        return makebackup;
    }

    public void setMakebackup(Boolean makebackup) {
        this.makebackup = makebackup;
    }

    public String getBackuppath() {
        return backuppath;
    }

    public void setBackuppath(String backuppath) {
        this.backuppath = backuppath;
    }

    public Date getLastsyncdate() {
        return lastsyncdate;
    }

    public void setLastsyncdate(Date lastsyncdate) {
        this.lastsyncdate = lastsyncdate;
    }

    public Boolean getWaslastsyncmanual() {
        return waslastsyncmanual;
    }

    public void setWaslastsyncmanual(Boolean waslastsyncmanual) {
        this.waslastsyncmanual = waslastsyncmanual;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        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 CdrConfig)) {
            return false;
        }
        CdrConfig other = (CdrConfig) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

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

}

Then, I’ve generated a JPAController class for Entity class. Here is the code:

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package jpa.worker;

import entities.worker.CdrConfig;
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 jpa.exceptions.NonexistentEntityException;
import jpa.exceptions.PreexistingEntityException;

/**
 *
 * @author pzielins
 */
public class CdrConfigJpaController {

    public CdrConfigJpaController() {
        emf = Persistence.createEntityManagerFactory("CDRFileWorkerPU");
    }
    private EntityManagerFactory emf = null;

    public EntityManager getEntityManager() {
        return emf.createEntityManager();
    }

    public void create(CdrConfig cdrConfig) throws PreexistingEntityException, Exception {
        EntityManager em = null;
        try {
            em = getEntityManager();
            em.getTransaction().begin();
            em.persist(cdrConfig);
            em.getTransaction().commit();
        } catch (Exception ex) {
            if (findCdrConfig(cdrConfig.getId()) != null) {
                throw new PreexistingEntityException("CdrConfig " + cdrConfig + " already exists.", ex);
            }
            throw ex;
        } finally {
            if (em != null) {
                em.close();
            }
        }
    }

    public void edit(CdrConfig cdrConfig) throws NonexistentEntityException, Exception {
        EntityManager em = null;
        try {
            em = getEntityManager();
            em.getTransaction().begin();
            cdrConfig = em.merge(cdrConfig);
            em.getTransaction().commit();
        } catch (Exception ex) {
            String msg = ex.getLocalizedMessage();
            if (msg == null || msg.length() == 0) {
                Integer id = cdrConfig.getId();
                if (findCdrConfig(id) == null) {
                    throw new NonexistentEntityException("The cdrConfig 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();
            CdrConfig cdrConfig;
            try {
                cdrConfig = em.getReference(CdrConfig.class, id);
                cdrConfig.getId();
            } catch (EntityNotFoundException enfe) {
                throw new NonexistentEntityException("The cdrConfig with id " + id + " no longer exists.", enfe);
            }
            em.remove(cdrConfig);
            em.getTransaction().commit();
        } finally {
            if (em != null) {
                em.close();
            }
        }
    }

    public List<CdrConfig> findCdrConfigEntities() {
        return findCdrConfigEntities(true, -1, -1);
    }

    public List<CdrConfig> findCdrConfigEntities(int maxResults, int firstResult) {
        return findCdrConfigEntities(false, maxResults, firstResult);
    }

    private List<CdrConfig> findCdrConfigEntities(boolean all, int maxResults, int firstResult) {
        EntityManager em = getEntityManager();
        try {
            CriteriaQuery cq = em.getCriteriaBuilder().createQuery();
            cq.select(cq.from(CdrConfig.class));
            Query q = em.createQuery(cq);
            if (!all) {
                q.setMaxResults(maxResults);
                q.setFirstResult(firstResult);
            }
            return q.getResultList();
        } finally {
            em.close();
        }
    }

    public CdrConfig findCdrConfig(Integer id) {
        EntityManager em = getEntityManager();
        try {
            return em.find(CdrConfig.class, id);
        } finally {
            em.close();
        }
    }

    public int getCdrConfigCount() {
        EntityManager em = getEntityManager();
        try {
            CriteriaQuery cq = em.getCriteriaBuilder().createQuery();
            Root<CdrConfig> rt = cq.from(CdrConfig.class);
            cq.select(em.getCriteriaBuilder().count(rt));
            Query q = em.createQuery(cq);
            return ((Long) q.getSingleResult()).intValue();
        } finally {
            em.close();
        }
    }

}

Because my application needs to work with two databases, I’ve edited generated by NetBeans Persistence Unit and now I have sth like this:

<?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="CDRFileWorkerPU" transaction-type="JTA">
    <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
    <jta-data-source>jdbc/cdrworkerdb</jta-data-source>
    <class>entities.config.CdrConfig</class>
    <exclude-unlisted-classes>true</exclude-unlisted-classes>
    <properties>
      <property name="eclipselink.ddl-generation" value="create-tables"/>
    </properties>
  </persistence-unit>
  <persistence-unit name="CDRDataStorePU" transaction-type="JTA">
    <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
    <jta-data-source>jdbc/cdrdb</jta-data-source>
    <class>entities.cdr.CallRecord</class>
    <class>entities.cdr.RecordColumn</class>
    <exclude-unlisted-classes>true</exclude-unlisted-classes>
    <properties>
      <property name="eclipselink.ddl-generation" value="create-tables"/>
    </properties>
  </persistence-unit>
</persistence>

Everything is fine until now, but when I try to use this method in my JSF Managed Bean:

public void test() {
        try {
            CdrConfig cfg = new CdrConfig();
            cfg.setBackuppath("foo");
            CdrConfigJpaController cjc = new CdrConfigJpaController();
            cjc.create(cfg);
            Record rec = new Record();
            RecordJpaController rjc = new RecordJpaController();
            rjc.create(rec);
            RecordColumn col = new RecordColumn();
            col.setColumnname("foo1");
            col.setRecord(rec);
            RecordColumnJpaController rcjc = new RecordColumnJpaController();
            rcjc.create(col);
        } catch (Exception ex) {
            Logger.getLogger(FileWorkerBackup.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

I get following error:

java.lang.IllegalArgumentException: Unknown entity bean class: class entities.worker.CdrConfig, please verify that this class has been marked with the @Entity annotation.
        at org.eclipse.persistence.internal.jpa.EntityManagerImpl.find(EntityManagerImpl.java:576)
        at org.eclipse.persistence.internal.jpa.EntityManagerImpl.find(EntityManagerImpl.java:460)
        at jpa.worker.CdrConfigJpaController.findCdrConfig(CdrConfigJpaController.java:125)
        at jpa.worker.CdrConfigJpaController.create(CdrConfigJpaController.java:43)
        at web.FileWorkerBackup.test(FileWorkerBackup.java:52)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at...

From Google I know, that it is sometimes helpful to tick “Include all Entity classes in module” in Persistence Unit editor, but then it gives me error about some cross-db references between tables (I’m sure that I’m not trying to do this).
I also found on Google, that restarting glassfish helps (because of unclosed persistence sessions), but it doesn’t help as well.
Please, point me to the right direction.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T22:06:27+00:00Added an answer on May 27, 2026 at 10:06 pm

    Maybe this line in the xml

    <class>entities.config.CdrConfig</class>
    

    should be

    <class>entities.worker.CdrConfig</class>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am reading a book about Javascript and jQuery and using one of the
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I want use html5's new tag to play a wav file (currently only supported
I am doing a simple coin flipping experiment for class that involves flipping a
We're building an app, our first using Rails 3, and we're having to build
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.