This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.
Andrey, I assume that you updated AbstractFacade to use Criteria API instead of SQL string which is great and thanks for that but it does not work - generate JPA and EJB Facade and call count() on the facade EJB and you will get attached exception.
Created attachment 94215 [details] exception
I see Caused by: java.lang.IllegalArgumentException: The type [null] is not the expected [EntityType] for the key class [class cust.DiscountCode]. Do you have DiscountCode generated properly? Do you have exclude unlisted classes in persistence.xml?
DC class is generated and persistence.xml contains <persistence-unit name="WebApp1PU" transaction-type="JTA"> <jta-data-source>jdbc/sample</jta-data-source> <properties/> </persistence-unit> Test it yourself and let me know if it works for you.
Created attachment 94220 [details] TestCase_10810
I have the same exception when testing the scenario described in 180764: Scenario: - created JPA classes in java application (JavaApp1): - created new web application(WebApp1) and added JavaApp1 dependency - created session bean from entity class in WebApp1 See the attached projects above.
Note: this happens not only when calling count() method, but any business method from AbstractFacade class.
David I can't reproduce the problem you mentioned using the following steps: - Create WebApp - Generate Entity - Generate Session facade. - Call facade's count() from the servlet. But I can reproduce it using the project which Milan attached. So as far as I see the problem is the entities are not in the persistence context. If include the entity classes into the WebApp's persistence.xml everything works fine. In other words you just need to changed the persistence.xml with the following: <persistence-unit name="WebApp1PU" transaction-type="JTA"> <jta-data-source>jdbc/sample</jta-data-source> <class>cust.Customer</class> <class>cust.DiscountCode</class> <exclude-unlisted-classes>true</exclude-unlisted-classes> <properties/> </persistence-unit> Or as alternative you can change the generated facades to use persistence unit "JavaLib1PU" and change it with the following: <persistence-unit name="JavaLib1PU" transaction-type="JTA"> <jta-data-source>jdbc/sample</jta-data-source> <class>cust.Customer</class> <class>cust.DiscountCode</class> <exclude-unlisted-classes>true</exclude-unlisted-classes> <properties/> </persistence-unit>
It's the same as issue 181068, in case of issue #181068 I was sure something is wrong with user created code, but may be I miss something. In this issue I see no issue but some dependencies on #101556 and may be some issues on gf/eclipselink side with problems to create proper persistence context for second persistence.xml as it looks strange for me to have fix with explicit declaration for classes when it should work for containers because no <eclude-unlisted-classes/> is specified in my opinion, but jpa spec may need to be double checked. David, have you tried to update code to not use abstract facade? As this issues seems to be unrelated to abstract facade usage. Also was it initially filed for case attached later?
In general this exception "The type [null] is not the expected [EntityType]" is valid exception for number of cases, haven't tried yet but in my opinion it should be thrown in case if j2se have pu with <exclude-unlisted-classes>true</exclude-unlisted-classes> but entity isn't listed in this pu.
You are right guys. I filed this while working on different problem and it was based on Milan's usecase where entities are in different jar - I cannot reproduce it if entities are defined directly within the WAR. Sorry for false alarm. If persistence.xml is defined in WAR's WEB-INF/classes then JPA scans only WEB-INF/classes for available entities. If entities are placed in a JAR file which is packaged in WAR's WEB-INF/lib folder then: * as was mentioned, entities has to be enumerated in persistence.xml; or * persistence.xml can be instructed to scan additional jars for entities via <jar-file> tag, eg. <jar-file>lib/JavaLib1.jar</jar-file> in Milan's case. (JPA spec chapters 8.2, 8.2.1.6.3, 8.2.2)
I am now also getting this error in Java EE 5 project with Tomcat as the target server. My PU looks 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="WebApplication28PU" transaction-type="RESOURCE_LOCAL"> <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider> <properties> <property name="javax.persistence.jdbc.url" value="jdbc:derby://localhost:1527/sample"/> <property name="javax.persistence.jdbc.password" value="app"/> <property name="javax.persistence.jdbc.driver" value="org.apache.derby.jdbc.ClientDriver"/> <property name="javax.persistence.jdbc.user" value="app"/> </properties> </persistence-unit> </persistence> However, when I explicitly add: <exclude-unlisted-classes>false</exclude-unlisted-classes> then things start to work. I found the following: http://www.oracle.com/technology/products/ias/toplink/jpa/howto/java-se-usage.html Which says: "The default value for the exclude-unlisted-classes element is true in Java SE, and false in Java EE." What does it mean for Tomcat? Should we explicitly add the false value when running against Tomcat?
(In reply to comment #11) > What does it mean for Tomcat? Should we explicitly add the false value when > running against Tomcat? I would think that it is JPA provider which sets default value so EclipseLink JPA2 provider should behave the same regardless of a server, no?
I got same problem in NetBeans 6.9.1 and 6.10M1. For learning purpose, I followed JSF CRUD app in NB example. 1/ Created a web app + Tomcat6 + JSF2. 2/ Lets NB auto generated entities from database, project -> New -> Entity Classes from database 3/ NB auto generated jsf pages, New -> JSF pages from Entity classes 4/ Run --> clicked on a Address link for first time, and got this error: Caused by: java.lang.IllegalArgumentException: The type [null] is not the expected [EntityType] for the key class [class jpa.entities.Address]. 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 jpa.controllers.AddressJpaController.getAddressCount(AddressJpaController.java:143) public int getAddressCount() { EntityManager em = getEntityManager(); try { CriteriaQuery cq = em.getCriteriaBuilder().createQuery(); Root<Address> rt = cq.from(Address.class); <<--- this line caused error cq.select(em.getCriteriaBuilder().count(rt)); Query q = em.createQuery(cq); return ((Long) q.getSingleResult()).intValue(); } finally { em.close(); } } <?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="JSFExamplePU" transaction-type="RESOURCE_LOCAL"> <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider> <properties> <property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/exampledb"/> <property name="javax.persistence.jdbc.password" value="xyz"/> <property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver"/> <property name="javax.persistence.jdbc.user" value="root"/> </properties> </persistence-unit> </persistence> ----------------------------------------------- * Work around: <exclude-unlisted-classes>false</exclude-unlisted-classes>
It's not really initial issue, the same "missed entity" can be got a lot of ways. The only question here why generated entities wasn't included in persistence.xml with resource local transaction as for j2se projects it should be included and tomcat woks similar.
As I see the workaround is implemented in case of New PU wizard but if pu is created from entities wizard "<exclude..." isn't added, it need to be corrected.
old issue http://netbeans.org/bugzilla/show_bug.cgi?id=142575
http://hg.netbeans.org/web-main/rev/1371f2a0cfda sync most cases of pu creation (add "exclude") but all should work before fix(in 6.10) also as classes was added to persistence.xml when I tried entities from pu generation on tomcat.
Integrated into 'main-golden', will be available in build *201010120000* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress) Changeset: http://hg.netbeans.org/main/rev/1371f2a0cfda User: Sergey B. Petrov <sj-nb@netbeans.org> Log: fix #180810 - synch addition of "exclude" in all places, but may need to be reviewed as now classes are added also for tomcat
Serjey, We arrived at the same conclusion - we just had a very large issue around this IAE testing the upcoming PWP. After I figured out what the issue was - I did a quick google on the error in order to put the fix everywhere and came across this bug - I should have used google first. >The workaround for DI 101 and bug# 338837 to fix the IAE issue for Criteria/Metamodel users attempting to use an EntityType that is not found is to specify the location of the classes (usually not required for Java EE environments) This environment will exist in Java SE, Spring and certain implementations of Java EE 6 Web Profile. Exception in thread "main" java.lang.IllegalArgumentException: The type [null] is not the expected [EntityType] for the key class [class org.eclipse.persistence.example.distributed.collatz.model.UnitOfWork]. http://wiki.eclipse.org/EclipseLink/Development/JPA_2.0/metamodel_api#DI_101:_20100218:_Descriptor.javaClass_is_null_on_a_container_EM_for_a_specific_case >workaround is Global to all classes <exclude-unlisted-classes>false</exclude-unlisted-classes> or specific to a single class <class>org.eclipse.persistence.example.distributed.collatz.model.UnitOfWork</class> 20110303: We have reproduced this issue in bug# 338837 in a Java SE environment. We have two workarounds and will be modifying the code to warn about the actual cause - which is a not fully specified data model in persistence.xml. The following specification mandated JPA 2.0 IllegalArgumentException occurs because entity classes were not processed because they are missing from the search path or not specified. This usually occurs in Java SE environments only. This is the result of an incomplete specification of the entities in persistence.xml for Java SE RESOURCE_LOCAL environments and possibly Java EE 6 Web Profile JTA environments. Occurs when running JPA 2.0 Criteria or Metamodel code where we require an EntityType like the following EntityType unitOfWork_ = getEntityManager().getMetamodel().entity(UnitOfWork.class); Root<UnitOfWork> root = getEntityManager().getCriteriaBuilder().createQuery().from(UnitOfWork.class);DDLGenerationClient [Java Application] org.eclipse.persistence.example.jpa.server.common.DDLGenerationClient at localhost:4353 Thread [main] (Suspended) MetamodelImpl.entity(Class<X>) line: 160 CriteriaQueryImpl<T>(AbstractQueryImpl<T>).from(Class<X>) line: 97 DDLGenerationClient.checkMetamodel() line: 436 DDLGenerationClient.doQuery() line: 460 DDLGenerationClient.main(String[]) line: 445 in public <X> EntityType<X> entity(Class<X> clazz) { Object aType = this.entities.get(clazz); if(aType instanceof EntityType) { return (EntityType<X>) aType; } else { --> throw new IllegalArgumentException(ExceptionLocalization.buildMessage(We see the following exception - which is not very descriptive of the actual issue of missing metadata because of missing entity classes found during EntityManager predeploy [EL Finest]: 2011-03-03 12:14:36.141--ServerSession(11582167)--Thread(Thread[main,5,main])--End deploying Persistence Unit dao.create.tables.derby.client; session file:/C:/view_w36a/examples/org.eclipse.persistence.example.jpa.server.common.ddlgen/bin/_dao.create.tables.derby.client;state Deployed; factoryCount 1 Exception in thread "main" java.lang.IllegalArgumentException: The type [null] is not the expected [EntityType] for the key class [class org.eclipse.persistence.example.distributed.collatz.model.UnitOfWork]. at org.eclipse.persistence.internal.jpa.metamodel.MetamodelImpl.entity(MetamodelImpl.java:160) at org.eclipse.persistence.example.jpa.server.common.DDLGenerationClient.checkMetamodel(DDLGenerationClient.java:435) at org.eclipse.persistence.example.jpa.server.common.DDLGenerationClient.doQuery(DDLGenerationClient.java:459) at org.eclipse.persistence.example.jpa.server.common.DDLGenerationClient.main(DDLGenerationClient.java:444) using <persistence-unit name="dao.create.tables.derby.client" transaction-type="RESOURCE_LOCAL"> <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider> <!-- exclude-unlisted-classes> false</exclude-unlisted-classes--> <!-- class> org.eclipse.persistence.example.distributed.collatz.model.UnitOfWork</class--> <properties> <property name="javax.persistence.jdbc.driver" value="org.apache.derby.jdbc.ClientDriver"/> <property name="eclipselink.target-database" value="Derby"/> <property name="javax.persistence.jdbc.url" value="jdbc:derby://127.0.0.1:1527/dataparallel;create=true"/> <property name="javax.persistence.jdbc.user" value="APP"/> <property name="javax.persistence.jdbc.password" value="APP"/> <property name="eclipselink.logging.level" value="ALL"/> <!-- property name="eclipselink.ddl-generation" value="drop-and-create-tables"/> <property name="eclipselink.ddl-generation.output-mode" value="both"/--> </properties> </persistence-unit>workaround is <exclude-unlisted-classes>false</exclude-unlisted-classes> or <class>org.eclipse.persistence.example.distributed.collatz.model.UnitOfWork</class> Result is OK with either fix unitOfWork_ EntityType: EntityTypeImpl@672904:UnitOfWork [ javaType: class org.eclipse.persistence.example.distributed.collatz.model.UnitOfWork descriptor: RelationalDescriptor(org.eclipse.persistence.example.distributed.collatz.model.UnitOfWork--> [DatabaseTable(EL_UNITOFWORK)]), mappings: 7] Solution: There are two ways into this problem. 1) We specify no entities at all and also do not specify <exclude-unlisted-classes>false</exclude-unlisted-classes> - the result of this is a completely empty metamodel 2) We specify only part of the entities via <class> properties - the result of this is selective IllegalArgumentException errors thrown when we attempt to use the missing EntityType classes - likely in a Criteria API query We need to warn both for no (0) entities found and later that a specific type was not found - possibly as a result of a missing class reference 1) warn the user that no entities were found during the predeploy so the deploy iterates nothing during metamodel.initialize - actually nothing is done during initialize MetamodelImpl@21350241 [ 0 Types: , 0 ManagedTypes: , 0 EntityTypes: , 0 MappedSuperclassTypes: , 0 EmbeddableTypes: ] or in protected void initializeCanonicalMetamodel(Metamodel model) DDLGenerationClient [Java Application] org.eclipse.persistence.example.jpa.server.common.DDLGenerationClient at localhost:3057 Thread [main] (Suspended) MetamodelImpl.initialize() line: 363 MetamodelImpl.<init>(DatabaseSession) line: 109 MetamodelImpl.<init>(EntityManagerSetupImpl) line: 128 EntityManagerSetupImpl.getMetamodel() line: 2209 EntityManagerSetupImpl.deploy(ClassLoader, Map) line: 413 EntityManagerFactoryImpl.getServerSession() line: 185 EntityManagerFactoryImpl.getMetamodel() line: 531 DDLGenerationClient.initialize(String) line: 137 DDLGenerationClient.doQuery() line: 453 DDLGenerationClient.main(String[]) line: 444 Descriptors map is empty - we need to warn the user about this this MetamodelImpl (id=37) session ServerSession (id=40) descriptors HashMap<K,V> (id=61) size 0 2) Change the IAE for a single missing entity to suggest that the entity class may not have been found or specified (it may be on purpose) Security note: A search for a non-existent entity class may come through a user-generated query and may be a way of testing the system for hidden classes - we may want to not print the name The error message needs to change from The type [null] is not the expected [EntityType] for the key class [class org.eclipse.persistence.example.jpa.server.business.Cell]. to something like No [EntityType] was found for the key class [class org.eclipse.persistence.example.distributed.collatz.model.UnitOfWork] in the Metamodel - please verify that the Entity class was referenced in persistence.xml using a specific <class>org.eclipse.persistence.example.distributed.collatz.model.UnitOfWork</class> property or a global <exclude-unlisted-classes>false</exclude-unlisted-classes> element. Just a note that the fix for 338837 will be to help the user figure out why they are missing entity classes during deployment (they were not found) - by adding more warnings only. The search path for entities will still be user or EJB-container (in the case of Java EE 5) controlled. The user may wish to split entities among persistence units - this is why control is at the user level and where we do not want the API to pick up everything (unless specified) - however it is the cause of this unfortunate situation where you attempt to use something that is not known. In the words of a certain public figure "it is unfortunate that we don't know what we don't know" see related http://www.netbeans.com/projects/javaee/lists/issues/archive/2010-02/message/627 http://netbeans.org/bugzilla/show_bug.cgi?id=181068 http://stackoverflow.com/questions/3559691/jsf-crud-application-and-entities/5185057#5185057 http://netbeans.org/bugzilla/show_bug.cgi?id=180810 http://old.nabble.com/Re%3A-problem-with-criteria-The-type--null--is-not-the-expected--EntityType--for-the-key-class--class-br.com.thinkit.db.Ativos----try-upgrade-past-8141.-p30219742.html http://dev.eclipse.org/mhonarc/lists/eclipselink-users/msg05508.html http://forums.devshed.com/java-help-9/jpa-controller-not-work-in-ejb-706551.html not http://forum.springsource.org/archive/index.php/t-32323.html http://comments.gmane.org/gmane.comp.java.tynamo.user/173 http://forums.netbeans.org/post-90076.html Michael O'Brien http://www.eclipselink.org
Hi Michael, thanks for update on these issues.