EclipseLink can't find my Entity "IllegalArgumentException" - gwt

I'm trying to do a simple persistence test using:
IntelliJ IDEA,
Maven,
Google Guice,
GWT,
EclipseLink and JPA 2.0.
My persistence.xml:
<persistence-unit name="guiceTest" transaction-type="RESOURCE_LOCAL">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<class>utfpr.edu.br.server.model.Contato</class>
<properties>
<property name="javax.persistence.jdbc.url"
value="jdbc:postgresql://127.0.0.1:5432/gwt"/>
<property name="javax.persistence.jdbc.password" value="postgres"/>
<property name="javax.persistence.jdbc.driver" value="org.postgresql.Driver"/>
<property name="javax.persistence.jdbc.user" value="postgres"/>
<property name="eclipselink.ddl-generation" value="create-tables"/>
<property name="eclipselink.logging.level" value="INFO"/>
</properties>
</persistence-unit>
The exception:
[EL Warning]: 2012-06-21 10:18:32.846--The collection of metamodel types is empty. Model classes may not have been found during entity search for Java SE and some Java EE container managed persistence units. Please verify that your entity classes are referenced in persistence.xml using either <class> elements or a global <exclude-unlisted-classes>false</exclude-unlisted-classes> element
java.lang.IllegalArgumentException: Object: Contato{dataNascimento=Thu Jun 21 10:18:31 BRT 2012, id=null, nome='abcd', sobrenome='adsada', numero='12313123', email='lololol#gmail.com'} is not a known entity type.
The test class:
Injector i = PersistenceTestModule.getInjector();
private ContatoDao dao = i.getInstance(ContatoDao.class);
#Test
public void testSave() throws Exception {
Contato cont = new Contato("abcd","adsada","12313123","lollollo#gmail.com",new Date());
dao.save(cont);
assertNotNull(cont.getId());
}
My persistence.xml is corrected placed in resources/META-INF.
I read that is a eclipselink bug here: https://bugs.eclipse.org/bugs/show_bug.cgi?id=338837
They said:
Solution:
There are two ways into this problem.
1) We specify no entities at all and also do not specify
false
- the result of this is a completely empty metamodel
2) We specify only part of the entities via 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".
I already tried this two solutions but I still got this error.
Please someone help me!

Related

Object: com.test.ActualEntity is not a known entity type + EclipseLink and Wildfly 10.1.0

I am getting this exception mentioned below while persisiting an entity in eclipselink. App Server used is Wildfly 10.1.0 Final
java.lang.IllegalArgumentException: Object: com.test.ActualEntity#7338353f is not a known entity type.
Persistence.xml contains the fully qualified class name
<persistence-unit name="TestDomain">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<jta-data-source>java:/TEST_DB_SAMPLE</jta-data-source>
<class>com.test.ActualEntity</class>
<properties>
<property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver"/>
<property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/testdb"/>
<property name="javax.persistence.jdbc.user" value="username"/>
<property name="javax.persistence.jdbc.password" value="xxxxxx"/>
<property name="eclipselink.logging.logger" value="DefaultLogger"/>
<property name="eclipselink.logging.level" value="FINEST" />
</properties>
</persistence-unit>
#Entity is mentioned at class level
#Id is GeneratedType.IDENTITY
DB : MySQL
Error log as below
java.lang.IllegalArgumentException: Object: com.test.ActualEntity#7338353f is not a known entity type.
2018-07-14 00:31:38,200 ERROR [stderr] (default task-2) at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.registerNewObjectForPersist(UnitOfWorkImpl.java:4228)
This happens only after login is successful.
if I disable login all other entities are recognized.
Any help will be apprciated
Regards,
Dwaipayan

EclipseLink Configuration in Wildfly-10.1.0.Final not reflecting the PersistenceProvider

I am using EclipseLink as a JPA Implementation. While deploying in Wildfly-10.1.0.Final, I always get the error No Persistence provider for EntityManager named <the persistence unit name>. I have followed the step in the links:
https://docs.jboss.org/author/display/WFLY10/JPA+Reference+Guide#JPAReferenceGuide-UsingEclipseLink
https://developer.jboss.org/thread/273134
The steps and the module.xml exactly matches mine.In standalone.xml I have enabled the system property as stated in the first link mentioned above
I enabled the trace logging and found that the below :
[org.hibernate.jpa.HibernatePersistenceProvider] (default task-4) Excluding from consideration due to name mis-match
Persistence Provider :org.eclipse.persistence.jpa.PersistenceProvider
JDK Version :1.8
Request if someone can shed some light where I am going wrong.
Added the trace as
Caused by: javax.persistence.PersistenceException: No Persistence provider for EntityManager named AAAAA_BBBB
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:61)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:39)
Other trace of Mismatch
2017-02-23 17:47:09,276 DEBUG [org.hibernate.jpa.HibernatePersistenceProvider] (default task-55) Checking persistence-unit [name=AAAAA_BBBB, explicit-provider=org.eclipse.persistence.jpa.PersistenceProvider] against incoming persistence unit name [AAAAA_BBBB]
2017-02-23 17:47:09,276 DEBUG [org.hibernate.jpa.HibernatePersistenceProvider] (default task-56) Checking persistence-unit [name=AAAAA_BBBB, explicit-provider=org.eclipse.persistence.jpa.PersistenceProvider] against incoming persistence unit name [AAAAA_BBBB]
2017-02-23 17:47:09,277 DEBUG [org.hibernate.jpa.HibernatePersistenceProvider] (default task-56) Excluding from consideration due to name mis-match
Additional Traces
2017-02-24 05:32:49,031 TRACE [org.hibernate.jpa.boot.spi.ProviderChecker] (default task-7) Checking requested PersistenceProvider name [org.eclipse.persistence.jpa.PersistenceProvider] against Hibernate provider names
2017-02-24 05:32:49,031 DEBUG [org.hibernate.jpa.HibernatePersistenceProvider] (default task-11) Excluding from consideration due to provider mis-match
2017-02-24 05:32:49,031 TRACE [org.hibernate.jpa.boot.spi.ProviderChecker] (default task-7) Found no match against Hibernate provider names
The persistence.xml
<persistence-unit name="AAA_BBB" transaction-type="JTA">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<jta-data-source>java:/<jndi-Name in standalone</jta-data-source>
<class>...</class>
<properties>
<property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver"/>
<property name="javax.persistence.jdbc.url" value="<url>"/>
<property name="javax.persistence.jdbc.user" value="<username>"/>
<property name="javax.persistence.jdbc.password" value="<pwd>"/>
</properties>
</persistence-unit>
<persistence-unit name="CCC_DDD" transaction-type="RESOURCE_LOCAL">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<jta-data-source>java:/<jndi-Name in standalone</jta-data-source>
<class>...</class>
<properties>
<property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver"/>
<property name="javax.persistence.jdbc.url" value="<url>"/>
<property name="javax.persistence.jdbc.user" value="<username>"/>
<property name="javax.persistence.jdbc.password" value="<pwd>"/>
</properties>
</persistence-unit>
Was finally able to resolve the issue in a little weird way (probably)
Step 1 : created a module directory under the name (com.abc.persistence:main)
Step 2 copied all the related jars of eclipselink and jipijapa into the same module and referred it.
Step 2. Removed the system property "eclipselink.archive.factory"
It works clean.
What I analysed was if one of the system property is put then others like the target server are never added to the properties map (I checked somewhere in the code). Once I removed I think all the others also gets added and hence it works, because I will be little surprised if creating the above directory in the module (Step 1 above ) made it work.

ServiceMix / Blueprint / JPA Integration

I have been spending the week attempting to integrate JPA / ServiceMix 4.5.1 / camel-jpa 2.10.4 / Blueprint together. I'm currently using OpenJPA, but am not tied to it. The version of aries jpa used by servicemix is 0.3.0.
The stack trace I cannot get past is:
org.osgi.service.blueprint.container.ComponentDefinitionException: Error when instanciating bean workoutEntity of class class [...].WorkoutEntity
at org.apache.aries.blueprint.container.BeanRecipe.getInstance(BeanRecipe.java:271)[10:org.apache.aries.blueprint:0.3.2]
at org.apache.aries.blueprint.container.BeanRecipe.internalCreate(BeanRecipe.java:708)[10:org.apache.aries.blueprint:0.3.2]
at org.apache.aries.blueprint.di.AbstractRecipe.create(AbstractRecipe.java:64)[10:org.apache.aries.blueprint:0.3.2]
at org.apache.aries.blueprint.di.RefRecipe.internalCreate(RefRecipe.java:60)[10:org.apache.aries.blueprint:0.3.2]
at org.apache.aries.blueprint.di.AbstractRecipe.create(AbstractRecipe.java:64)[10:org.apache.aries.blueprint:0.3.2]
at org.apache.aries.blueprint.container.BlueprintRepository.createInstances(BlueprintRepository.java:219)[10:org.apache.aries.blueprint:0.3.2]
[...]
Caused by: <openjpa-2.2.0-r422266:1244990 nonfatal general error> org.apache.openjpa.persistence.PersistenceException: [javax.sql.DataSource]
at org.apache.openjpa.kernel.AbstractBrokerFactory.newBroker(AbstractBrokerFactory.java:218)
at org.apache.openjpa.kernel.DelegatingBrokerFactory.newBroker(DelegatingBrokerFactory.java:156)
at org.apache.openjpa.persistence.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:227)
[...]
Caused by: java.lang.IllegalArgumentException: [javax.sql.DataSource]
at org.apache.aries.jndi.services.ServiceHelper.proxyPriviledged(ServiceHelper.java:348)
at org.apache.aries.jndi.services.ServiceHelper.access$700(ServiceHelper.java:65)
at org.apache.aries.jndi.services.ServiceHelper$1.run(ServiceHelper.java:285)
at java.security.AccessController.doPrivileged(Native Method)[:1.6.0_43]
[...]
I've attempted several variations. Here is my current configuration:
persistence.xml:
<persistence-unit name="customer1" transaction-type="JTA">
<provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider>
<jta-data-source>osgi:service/javax.sql.DataSource/(osgi.jndi.service.name=jdbc/prototypedb)</jta-data-source>
<class>...</class>
</persistence-unit>
camel-context.xml
<service id="PrototypeDB" interface="javax.sql.DataSource">
<service-properties>
<entry key="osgi.jndi.service.name" value="jdbc/prototypedb"/>
</service-properties>
<bean class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver"/>
<property name="url" value="jdbc:mysql://localhost:3306/prototype"/>
<property name="username" value="root"/>
<property name="password" value="..."/>
</bean>
</service>
<service ref="workoutEntity" interface="..."/>
<bean id="workoutEntity" class="...">
<jpa:unit index="0" unitname="customer1" />
<tx:transaction method="*" value="Required"/>
</bean>
Entity Bean (written in groovy)
#Entity
#Table(name='customer1')
#Slf4j
class WorkoutEntity implements IWorkoutEntity{
private EntityManager entityManager
WorkoutEntity(final EntityManagerFactory entityManagerFactory) {
this.entityManager = entityManagerFactory.createEntityManager()
}
#Handler
void create( #Body final String input) {
// ...
}
}
I've attempted multiple different implementations of a DataSource, including the BasicDataSource, org.springframework.jdbc.datasource.SimpleDriverDataSource, and com.mysql.jdbc.jdbc2.optional.MysqlDataSource. All cause the IllegalArgumentException.
I've also attempted to forego using JNDI and instead define the data source directly in the persistence.xml. This causes ClassNotFoundException in the OpenJPA bundle, as it is not importing the mysql driver. I'd prefer to define this in my camel-context.xml and would prefer to not re-bundle the OpenJPA jar.
You probably also need the aries JNDI features installed. This helps to call OSGi services via JNDI lookups. This should be the missing piece.

Configuring EJB on JBoss AS 7 using JTA datasources: every statement is commited

everybody!
I've been trying to find the answer for some time but I didn't manage.
I try to configure my application and make it work under JBoss Application Server 7.1.1, using Enterprise Java Beans. My application is Web application, it uses servlets and injects other classes as EJBs. The problem is that every statement gets commited, so that means no transaction management is supported.
In my test example I have an entity with a collection of children (mapped with a relationship OneToMany with a property CascadeType.ALL). If a record in a collection has some problems (e.g. non-existing foreign key), it can't be inserted into table and throws exception. However, the parent entity gets inserted, so I assume the inserts are done in different separate transactions. This is strictly undesired behavior and I try to resolve it.
Technical parameters:
DBMS: Oracle EE 11g
AS: JBoss AS 7.1.1
my persistence.xml:
<?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/">
<persistence-unit name="OracleEntityManager">
<jta-data-source>java:jboss/CmaDevDS</jta-data-source>
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.Oracle9iDialect" />
<property name="hibernate.hbm2ddl.auto" value="none" />
<property name="hibernate.jdbc.batch_size" value="20" />
<property name="hibernate.show_sql" value="true" />
<property name="hibernate.format_sql" value="true" />
<property name="hibernate.use_sql_comments" value="true" />
</properties>
</persistence-unit>
</persistence>
my EJB:
#Stateless(name="EntityWriter")
#TransactionManagement(TransactionManagementType.CONTAINER)
public class EntityWriter {
#Resource
private SessionContext context;
/*#Resource
UserTransaction ut;*/
#PersistenceContext(unitName = "OracleEntityManager",type=PersistenceContextType.EXTENDED)
EntityManager em;
#TransactionAttribute(TransactionAttributeType.REQUIRED)
public EntityMarker insertEntity(EntityMarker entity)throws Exception
{
try
{
entity = em.merge(entity);
em.flush();
return entity;
}
catch (Exception e)
{
context.setRollbackOnly();
e.printStackTrace();
return null;
}
}
}
Actually I tried both EJB approaches: Container Management Transaction and Bean Management Transaction and neither works as I expect.
When I inject the bean into servlets I do it like this:
#EJB(name = "EntityWriter")
private EntityWriter entityWriter;
Now I think the bean is fine, probably something is missing in persistence.xml.
Would be grateful to any ideas. Thanks in advance!
Everything works correct after I edited Datasource configuration via JBoss Administration console and set a checkbox "Use JTA". It was unchecked by default.
You're right, Chris. Thanks!

How to use 2 PersistenceUnits in one Persistence.xml in a JavaEE application?

I am trying to access 2 different tables in my database.
Initially my persistence.xml was as follows:
<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence" version="2.0">
<persistence-unit name="Persistence">
<jta-data-source>jdbc/classicmodels</jta-data-source>
<class>com.tugay.maythirty.model.Customers</class>
<class>com.tugay.maythirty.model.Products</class>
<class>com.tugay.maythirty.model.Employee</class>
<class>com.tugay.maythirty.model.Office</class>
</persistence-unit>
</persistence>
So I defined a DataSource in Glassfish following this great artical and my application was working fine. I was using #PersistenceContext annotation in my DAO classes with name="Persistence"
This basically is connected to a table called "classicmodels".
Then I needed to fetch some data from a table called "sakila". I added these lines to my persistence.xml:
<persistence-unit name="sakila">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<class>com.tugay.maythirty.model.Actor</class>
<class>com.tugay.maythirty.model.Film</class>
<class>com.tugay.maythirty.model.FilmActor</class>
<properties>
<property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver"/>
<property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/sakila"/>
<property name="javax.persistence.jdbc.user" value="root"/>
<property name="javax.persistence.jdbc.password" value="password"/>
</properties>
</persistence-unit>
And I have used this code in my DAO:
public List<Actor> getAllActors(){
EntityManagerFactory emf = Persistence.createEntityManagerFactory("sakila");
EntityManager em = emf.createEntityManager();
TypedQuery<Actor> actorTypedQuery = em.createQuery("Select a from Actor a",Actor.class);
return actorTypedQuery.getResultList();
}
When I deploy my application to GlassFish however I started getting this Exception:
java.lang.RuntimeException: Could not resolve a persistence unit corresponding to the persistence-context-ref-name [Persistence] in the scope of the module called [may-thrity]. Please verify your application.
So it seems that now my Persistence Unit with name "Persistence" is gone.
What is it that I am doing wrong?
Have you tried explicitly declaring your persistence unit with
#PersistenceContext(unitName="Persistence")
instead of
#PersistenceContext(name="Persistence")
PersistenceContext doc