Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [eclipselink-users] Object: [some.class@af683a] is not a known entity type

James, I'm using TOMCAT and Java SE. When I redeploy, I replace the entire application from the server and then deploy an entire new copy of it.

The persistence is as follows:

<?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="AMB_JPA" transaction-type="RESOURCE_LOCAL">
        <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
        <class>com.amb.entidades.Enquete</class>
        <class>com.amb.entidades.EnqueteResposta</class>
        <properties>
            <property name="eclipselink.target-database" value="MySQL"/>
            <property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/amb"/>
            <property name="javax.persistence.jdbc.user" value="root"/>
            <property name="javax.persistence.jdbc.password" value="mobview"/>
            <property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver"/>
        </properties>
    </persistence-unit>
</persistence>

2011/6/1 James Sutherland <jamesssss@xxxxxxxxx>

The error means the persistence unit has not defined the class.

Ensure your persistence.xml includes a <class> tag for the class (or it is
listed in your orm.xml, or you have unlisted classes as true and the class
is in the same jar file as your persistence.xml).

Include your persistence.xml, and the environment that you are using?

If the class is listed it may also be a class loader issue, as you using
redeployment, or have you deployed the same jar multiple times?


Wellington L.S. da Silva wrote:
>
> Hi all,
>
> My name is Wellington, I'm brazilian and I'm creating a poll application
> in
> pure JPA with Eclipselink, that has at the moment 2 entities in a quite
> trivial One-to-many relationship: Enquete holds the one question,
> EnqueteResposta holds one of the many possible answers. Here's the
> scenario:
>
> 1. I've setup a pure JPA project with Entities and Helper classes. The
> entities are created from pre-existant tables in a MySQL database by
> Eclipse
> Dali I wrote no code but a Cascade.ALL in the master class.
>
> 2. The main Helper class is a CRUDAdmin that takes whatever class through
> Java Generics and applies JPA operations on them coded as follows:
>
> package com.amb.ops;
>
> import java.util.List;
>
> import javax.persistence.EntityManager;
> import javax.persistence.EntityTransaction;
> import javax.persistence.Query;
>
> @SuppressWarnings("unchecked")
> public class CRUDAdm {
>
>         private static EntityManager getEntityManager() {
>             EntityManager em =
> EntityManagerFactoryHelper.getFactory().createEntityManager();
>             return em;
>         }
>
>         public static <T> T create(T entity) throws Exception {
>             EntityManager em = getEntityManager();
>             Exception e = null;
>             T retornoEntity = null;
>             EntityTransaction t = em.getTransaction();
>             try {
>                 t.begin();
>                 retornoEntity = em.merge(entity);
>                 t.commit();
>             } catch (Exception ex) {
>                 if (t.isActive()) {
>                     em.getTransaction().rollback();
>                 }
>                 e = ex;
>             }
>             em.close();
>             if (e != null) {
>                 throw e;
>             }
>             return retornoEntity;
>         }
>
>         public static <T> T update(T entity) throws Exception {
>             EntityManager em = getEntityManager();
>             Exception e = null;
>             T retornoEntity = null;
>             EntityTransaction t = em.getTransaction();
>             try {
>                 t.begin();
>                 retornoEntity = em.merge(entity);
>                 t.commit();
>             } catch (Exception ex) {
>                 if (t.isActive()) {
>                     t.rollback();
>                 }
>                 e = ex;
>             }
>             em.close();
>             if (e != null) {
>                 throw e;
>             }
>             return retornoEntity;
>         }
>
>         public static <T> void delete(T entity) throws Exception {
>             EntityManager em = getEntityManager();
>             Exception e = null;
>             EntityTransaction t = em.getTransaction();
>             try {
>                 t.begin();
>                 entity = em.merge(entity);
>                 em.remove(entity);
>                 t.commit();
>             } catch (Exception ex) {
>                 if (t.isActive()) {
>                     t.rollback();
>                 }
>                 e = ex;
>             }
>             em.close();
>             if (e != null) {
>                 throw e;
>             }
>         }
>
>         public static <T> T retrieve(Class<T> entityClass, Object id)
> throws
> Exception {
>             EntityManager em = getEntityManager();
>             Exception e = null;
>             T retorno = null;
>             EntityTransaction t = em.getTransaction();
>             try {
>                 t.begin();
>                 retorno = em.find(entityClass, id);
>                 t.commit();
>             } catch (Exception ex) {
>                 if (t.isActive()) {
>                     t.rollback();
>                 }
>                 e = ex;
>             }
>             em.close();
>             if (e != null) {
>                 throw e;
>             }
>             return retorno;
>         }
>
>         public static <T> List<T> listAll(Class<T> entityClass, String...
> orderbys) throws Exception {
>             EntityManager em = getEntityManager();
>             List<T> retorno = null;
>             try {
>                 String query = "select o from " +
> entityClass.getSimpleName() + "  o  order by ";
>
>                 for (String order : orderbys) {
>                     query += order + " , ";
>                 }
>                 query = query.substring(0, query.length() - 2);
>                 Query q = em.createQuery(query);
>                 retorno = q.getResultList();
>             } catch (Exception ex) {
>                 ex.printStackTrace();
>             }
>             em.close();
>             return retorno;
>         }
>
>         public static <T> List<T> listAll(Class<T> entityClass) throws
> Exception {
>             EntityManager em = getEntityManager();
>             List<T> retorno = null;
>             try {
>                 String query = "select o from " +
> entityClass.getSimpleName() + "  o ";
>                 Query q = em.createQuery(query);
>                 retorno = q.getResultList();
>             } catch (Exception ex) {
>                 ex.printStackTrace();
>             }
>             em.close();
>             return retorno;
>         }
>
>         public static <T> List<T> listByProperty(Class<T> entityClass,
> String propertyName, Object propertyValue) throws Exception {
>             EntityManager em = getEntityManager();
>             List<T> retorno = null;
>             try {
>                 String query = "select o from " +
> entityClass.getSimpleName() + "  o  where o." + propertyName + "  =
> :propertyValue ";
>                 Query q =
> em.createQuery(query).setParameter("propertyValue", propertyValue);
>
>                 retorno = q.getResultList();
>             } catch (Exception ex) {
>                 ex.printStackTrace();
>             }
>             em.close();
>             return retorno;
>         }
>
>
>
>         public static <T> List<T> listByProperty(Class<T> entityClass,
> String propertyName, Object propertyValue, String operador, String...
> orderbys) throws Exception {
>             EntityManager em = getEntityManager();
>             List<T> retorno = null;
>             try {
>                 String query = null;
>                 if (!operador.equalsIgnoreCase("like")) {
>                     query = "select o from " + entityClass.getSimpleName()
> +
> "  o  where o." + propertyName + "  " + operador + " :propertyValue ";
>                 } else {
>                     query = "select o from " + entityClass.getSimpleName()
> +
> "  o  where upper(o." + propertyName + ")  " + operador + "
> upper(:propertyValue) ";
>                 }
>
>                 if (orderbys != null && orderbys.length > 0) {
>                     query+= " order by ";
>                     for (String order : orderbys) {
>                         query += "o." + order + " , ";
>                     }
>                     query = query.substring(0, query.length() - 2);
>                 }
>
>                 Query q =
> em.createQuery(query).setParameter("propertyValue", propertyValue);
>
>                 retorno = q.getResultList();
>             } catch (Exception ex) {
>                 ex.printStackTrace();
>             }
>             em.close();
>             return retorno;
>         }
>
>         public static <T> List<T> listByProperty(Class<T> entityClass,
> String propertyName, Object propertyValue, String operador) throws
> Exception
> {
>             EntityManager em = getEntityManager();
>             List<T> retorno = null;
>             try {
>                 String query = "select o from " +
> entityClass.getSimpleName() + "  o  where o." + propertyName + "  " +
> operador + " :propertyValue ";
>                 Query q =
> em.createQuery(query).setParameter("propertyValue", propertyValue);
>
>                 retorno = q.getResultList();
>             } catch (Exception ex) {
>                 ex.printStackTrace();
>             }
>             em.close();
>             return retorno;
>         }
> }
>
> 3. The EntityManagerHelper class is a singleton coded as suggested in the
> EclipseLink docs somewhere, so, it's a singleton to the factory class.
>
> 4. Having that I packaged the classes in a jar file and used the jar file
> (now containing the full MODEL of the application with all db operations
> fully encapsulated) in the client Struts 2 app. The idea is to create the
> MODEL classes incrementally and adding actions as new MODEL jars arrive.
>
> 5. The struts app calls an action to update a value in the slave class
> EnqueteResposta, inside master class Enquete, as follows:
>
>     public String votarEnqueteAtiva() throws Exception {
>         System.out.println("inicio da votarEnqueteAtiva");
>         List<Enquete> le = CRUDAdm.listByProperty(Enquete.class, "ativa",
> new Integer(1));
>         if (le.size() == 1) {
>             Enquete e = le.get(0);
>             List<EnqueteResposta> resps = e.getEnqueteRespostas();
>             Iterator<EnqueteResposta> i = resps.iterator();
>             while (i.hasNext()) {
>                 EnqueteResposta er = i.next();
>                 if (er.getId() == voto) er.setTotal(er.getTotal() + 1);
>             }
>             CRUDAdm.update(le);
>             eab = new EnqueteAtivaBean();
>             eab.setPergunta(e.getQuestao());
>             List<String> re = new LinkedList<String>();
>             List<String> pe = new LinkedList<String>();
>             i = resps.iterator();
>             int totalGeral = 0;
>             while (i.hasNext()) {
>                 EnqueteResposta er = i.next();
>                 re.add(er.getResposta());
>                 totalGeral += er.getTotal();
>             }
>             eab.setRespostas(re);
>             i = resps.iterator();
>             while (i.hasNext()) {
>                 EnqueteResposta er = i.next();
>                 pe.add(""+er.getTotal()*100/totalGeral);
>             }
>             eab.setPercents(pe);
>             HttpServletRequest request =
> (HttpServletRequest)ActionContext.getContext().get(StrutsStatics.HTTP_REQUEST);
>             HttpSession session = request.getSession();
>             session.setAttribute("enqueteAtiva",eab);
>         }
>         System.out.println("fim da votarEnqueteAtiva");
>         return NONE;
>     }
>
> Then I get the StackTrace below:
>
> *java.lang.IllegalArgumentException: Object:
> [com.amb.entidades.Enquete@af683a] is not a known entity type.*
>
>
> org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.mergeCloneWithReferences(UnitOfWorkImpl.java:3456)
>
> org.eclipse.persistence.internal.sessions.RepeatableWriteUnitOfWork.mergeCloneWithReferences(RepeatableWriteUnitOfWork.java:363)
>
> org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.mergeCloneWithReferences(UnitOfWorkImpl.java:3427)
>
> org.eclipse.persistence.internal.jpa.EntityManagerImpl.mergeInternal(EntityManagerImpl.java:452)
>
> org.eclipse.persistence.internal.jpa.EntityManagerImpl.merge(EntityManagerImpl.java:429)
>     com.amb.ops.CRUDAdm.update(CRUDAdm.java:46)
>     com.hoog.acoes.EnqueteAtiva.votarEnqueteAtiva(EnqueteAtiva.java:59)
>     sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>
>
> Now WHAT CAN THAT BE? Do you guys need any other info to analyze this
> issue?
>
> The CRUDAdmin method to list the Enquete is working quite nicely.
>
> Any help will be appreciated.
>
> Cheers all,
>
> Wellington
>
>


-----
http://wiki.eclipse.org/User:James.sutherland.oracle.com James Sutherland
http://www.eclipse.org/eclipselink/
 EclipseLink ,  http://www.oracle.com/technology/products/ias/toplink/
TopLink
Wiki:  http://wiki.eclipse.org/EclipseLink EclipseLink ,
http://wiki.oracle.com/page/TopLink TopLink
Forums:  http://forums.oracle.com/forums/forum.jspa?forumID=48 TopLink ,
http://www.nabble.com/EclipseLink-f26430.html EclipseLink
Book:  http://en.wikibooks.org/wiki/Java_Persistence Java Persistence
Blog:  http://java-persistence-performance.blogspot.com/ Java Persistence
Performance
--
View this message in context: http://old.nabble.com/Object%3A--some.class%40af683a--is-not-a-known-entity-type-tp31744847p31748721.html
Sent from the EclipseLink - Users mailing list archive at Nabble.com.

_______________________________________________
eclipselink-users mailing list
eclipselink-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/eclipselink-users


Back to the top