WFLYEJB0034: EJB Invocation failed on component - interface

Module 1 Server Side
public interface BaseInterface{
Customer createCustomer(Profile profile);
}
public interface InterfaceA extends BaseInterface{
}
public class ServiceProducer {
#EJB(lookup = "java:global/path/ClassA")
#Produces
private InterfaceA interfaceA;
}
#Remote(ClassA.class)
public class ClassA implements InterfaceA{
BaseInterface base;
#Inject
public ClassA(#Named BaseInterface base){
this.base = base;
}
#Override
createCustomer implementation ...
}
Module 2 Client
public class Api{
#Inject
InterfaceA intA;
#Override
Customer createCustomer(arg){
intA.createCustomer
}
}
Hi I am getting the below error when running the above
StatelessEJBLocator for "ClassA", view is interface InterfaceA, affinity is Local
WFLYEJB0034: EJB Invocation failed on component WorkflowManager for method public abstract Customer BaseInterface.createCustomer(Profile): javax.ejb.EJBTransactionRolledbackException: WFLYEE0042: Failed to construct component instance

Related

#Inject - UserTransaction throws weld error

Error:
Exception 1 :
org.jboss.weld.exceptions.DefinitionException: WELD-001451: javax.transaction.UserTransaction cannot be injected into an enterprise bean with container-managed transactions: [BackedAnnotatedField] #Inject com.evry.integrator.snow.model.dao.impl.GenericDaoImpl.userTransaction
at com.evry.integrator.snow.model.dao.impl.GenericDaoImpl.userTransaction(GenericDaoImpl.java:0)
StackTrace
at org.jboss.weld.module.ejb.WeldEjbValidator.validateInjectionPointForDefinitionErrors(WeldEjbValidator.java:40)
at org.jboss.weld.bootstrap.Validator.validateInjectionPointForDefinitionErrors(Validator.java:336)
Code:
public abstract class GenericDaoImpl<T, PK> implements GenericDao<T, PK> {
private static final Logger LOG = Logger.getLogger(GenericDaoImpl.class.getName());
#PersistenceContext(unitName = "IntegratorMasterdataDS")
protected EntityManager em;
#Inject
UserTransaction userTransaction
Scrutiny Class
#Stateless
public class Scrutiny {
private static final Logger log = Logger.getLogger(Scrutiny.class.getName());
public Scrutiny() {
System.out.println("Scrutiny");
}
#Inject
StatusDao statusDao;
public JobStatus insertNewRecord(JobName jName) {
log.info("insertNewRecord:" + jName);
try {
statusDao.beginUserTransaction(); <--- Here i want to begin
statusDao.create(js);
statusDao.flush();
statusDao.commitUserTransaction(); <--- Here i want to Commit
} catch (Exception e) {
log.warning("insertNewRecord:" + e);
}
Status Dao:
public interface StatusDao extends GenericDao<JobStatus, String> {
List<JobStatus> checkExistingRecordToday(JobName jName);
}
Job Status Dao:
#Stateless
public class JobStatusDaoImpl extends GenericDaoImpl<JobStatus, String> implements StatusDao {
private static final Logger LOG = Logger.getLogger(JobStatusDaoImpl.class.getName());
#Override
public List<JobStatus> checkExistingRecordToday(JobName jName) {
As of now whole process is handled by JTA but i want to commit Scrutiny class instantantly which suggest job has just started and at end want to update the same.
You should remove the UserTransaction injection from your DAO generic object and handle the transaction within Scrutiny bean, annotating it with TransactionManagement.
Your bean code should become this:
#Stateless
#TransactionManagement(value=TransactionManagementType.BEAN)
public class Scrutiny {
private static final Logger log = Logger.getLogger(Scrutiny.class.getName());
#Inject
private UserTransaction utx;
public Scrutiny() {
System.out.println("Scrutiny");
}
#Inject
StatusDao statusDao;
public JobStatus insertNewRecord(JobName jName) {
log.info("insertNewRecord:" + jName);
try {
utx.begin(); <--- Here i want to begin
statusDao.create(js);
utx.flush();
utxcommit(); <--- Here i want to Commit
} catch (Exception e) {
log.warning("insertNewRecord:" + e);
}
}
With these changes, your DAO should continue to work using container managed transactions, while your specific bean can control the transaction as desired.

How to implement database inheritance in Spring Data JPA with MapperSuperClass?

I'm trying out database inheritance of type JOINED in Spring Data JPA, referring to this article. This worked fine. But I've to implement MappedSuperClass in my project. I've implemented in the following way:
Base.java
#MappedSuperclass
public abstract class Base {
public abstract Long getId();
public abstract void setId(Long id);
public abstract String getFirstName();
public abstract void setFirstName(String firstName);
}
BaseImpl.java
#Entity
#Inheritance(strategy = InheritanceType.JOINED)
public class BaseImpl extends Base {
#Id
#GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
private String firstName;
...
}
Super1.java
#MappedSuperclass
public abstract class Super1 extends BaseImpl {
public abstract String getSuperName();
public abstract void setSuperName(String guideName);
}
Super1Impl.java
#Entity
public class Super1Impl extends Super1 {
private String superName;
...
}
BaseBaseRepository.java
#NoRepositoryBean
public interface BaseBaseRepository<T extends Base> extends JpaRepository<T, Long> { }
BaseRepository.java
#NoRepositoryBean
public interface BaseRepository<T extends Base> extends BaseBaseRepository<Base> { }
BaseRepositoryImpl.java
#Transactional
public interface BaseRepositoryImpl extends BaseRepository<BaseImpl> { }
Super1Repository.java
#NoRepositoryBean
public interface Super1Repository<T extends Super1> extends BaseBaseRepository<Super1> { }
Super1RepositoryImpl.java
#Transactional
public interface Super1RepositoryImpl extends Super1Repository<Super1Impl> { }
I'm trying to save a Super1 object in a test case:
#Test
public void contextLoads() {
Super1 super1 = new Super1Impl();
super1.setSuperName("guide1");
super1.setFirstName("Mamatha");
super1.setEmail("jhhj");
super1.setLastName("kkjkjhjk");
super1.setPassword("jhjjh");
super1.setPhoneNumber("76876876");
System.out.println(super1Repository.save(super1));
}
But I'm getting the following error:
Caused by: org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'baseRepositoryImpl':
Invocation of init method failed; nested exception is java.lang.IllegalArgumentException:
This class [class com.example.entity.Base] does not define an IdClass
.....
Caused by: java.lang.IllegalArgumentException: This class [class com.example.entity.Base] does not define an IdClass
.......
Tried out #PrimaryKeyJoinColumn(name = "id", referencedColumnName = "id") in Super1Impl, but still getting the same error.
The error is caused by incorrect repository interface declarations.
BaseRepository<T extends Base> extends BaseBaseRepository<Base>
should be
BaseRepository<T extends Base> extends BaseBaseRepository<T>
and
Super1Repository<T extends Super1> extends BaseBaseRepository<Super1>
should be
Super1Repository<T extends Super1> extends BaseBaseRepository<T>
As currently declared, BaseBaseRepository<Base> means a repository of Base objects and Base does not have an #Id field, hence the error.

Injection EJB into Java Class

How can i inject an EJB (3.0) in simple java class ?
When inject an EJB in my Java class, on execution i get a NullPointerException.
My Java Class test :
public class test {
#EJB MyEjb myEjb;
public test(){
myEjb.getUserbyId(2); // myEjb = null
}
}
My EJB
#Stateless
#LocalBean
public class MyEjb {
#PersistenceContext(unitName="jpa")
EntityManager EM;
public User getUserbyId(Integer id){
....
}
You should use InitialContext#lookup method to obtain EJB reference from an application server.
For example:
#Stateless(name="myEJB")
public class MyEJB {
public void ejbMethod() {
// business logic
}
}
public class TestEJB {
public static void main() {
MyEJB ejbRef = (MyEJB) new InitialContext().lookup("java:comp/env/myEJB");
ejbRef.ejbMethod();
}
}

How to use provider in Errai IOC?

I have a problem with #IocProvider (), annotation does not work.
The code is very similar to https://docs.jboss.org/author/display/ERRAI/Container+Wiring
public interface Test {
String getGreeting();
}
#ApplicationScoped
public class TestImpl implements Test {
public String getGreeting() {
return "Hello:)";
}
}
#IOCProvider
#Singleton
public class TestProvider implements Provider<Test> {
#Override
public Test get() {
return new TestImpl();
}
}
Then I want use DI in my broadcast service (errai-bus).
#Service
public class BroadcastService implements MessageCallback {
#Inject
Test test;
#Inject
MessageBus bus;
#Inject
public BroadcastService(MessageBus bus) {
this.bus = bus;
}
public void callback(Message message) {
MessageBuilder.createMessage()
.toSubject("BroadcastReceiver")
.with("BroadcastText", test.getGreeting()).errorsHandledBy(new ErrorCallback() {
#Override
public boolean error(Message message, Throwable throwable) {
return true;
}
}).sendNowWith(bus);
}
}
I get a error:
1) No implementation for com.gwtplatform.samples.basic.server.Test was bound.
while locating com.gwtplatform.samples.basic.server.Test
for field at com.gwtplatform.samples.basic.server.BroadcastService.test(BroadcastService.java:32)
at org.jboss.errai.bus.server.service.ServiceProcessor$1.configure(ServiceProcessor.java:118)
If I change the code to
#Inject
TestImpl test;
It works, but I need the provider. Do you have some idea?
Because you're trying to use #IOCProvider in server-side code. Errai IOC is completely client-side.

RF 'Unfrozen bean with null RequestContext' when using a ValueProxy param with JsonRpc dialect

When i try to send a request that uses a ValueProxy params i'm getting this 'Unforzen bean' exception. I don't know if this exception is because a bug with RF using JsonDialect or i'm doing something wrong... ¿Some help?
java.lang.AssertionError: Unfrozen bean with null RequestContext
at com.google.web.bindery.requestfactory.shared.impl.AbstractRequestContext.checkStreamsNotCrossed(AbstractRequestContext.java:981)
at com.google.web.bindery.requestfactory.shared.impl.AbstractRequestContext.editProxy(AbstractRequestContext.java:509)
at com.google.web.bindery.requestfactory.shared.impl.AbstractRequestContext.edit(AbstractRequestContext.java:502)
at com.google.web.bindery.requestfactory.shared.impl.AbstractRequestContext.retainArg(AbstractRequestContext.java:1230)
at com.google.web.bindery.requestfactory.shared.impl.AbstractRequestContext.access$2(AbstractRequestContext.java:1223)
at com.google.web.bindery.requestfactory.shared.impl.AbstractRequestContext$JsonRpcPayloadDialect.addInvocation(AbstractRequestContext.java:202)
at com.google.web.bindery.requestfactory.shared.impl.AbstractRequestContext.addInvocation(AbstractRequestContext.java:661)
at es.xxxx.taller.client.Taller_SomeRequestContextImpl.SomeCall(Taller_SomeRequestContextImpl.java:29)
at es.xxxx.taller.client.Taller.onModuleLoad(Taller.java:417)
public class SomeEntryPoint implements EntryPoint {
#JsonRpcProxy
public interface SomeProxy extends ValueProxy {
String getSomeProperty();
void setSomeProperty(String value);
}
#JsonRpcProxy
public interface VoidProxy extends ValueProxy {
}
public interface SomeAutoBeanFactory extends AutoBeanFactory {
SomeAutoBeanFactory INSTANCE = GWT.create(SomeAutoBeanFactory.class);
AutoBean<SomeProxy> someProxy();
}
public interface SomeRequestFactory extends RequestFactory {
SomeRequestFactory INSTANCE = GWT.create(SomeRequestFactory.class);
SomeRequestContext context();
}
#JsonRpcService
public interface SomeRequestContext extends RequestContext {
SomeCall SomeCall(SomeProxy proxy);
#JsonRpcWireName(value = "SomeCall")
public interface SomeCall extends Request<VoidProxy> {
}
}
public void onModuleLoad() {
SomeProxy someProxy = SomeAutoBeanFactory.INSTANCE.someProxy().as();
someProxy.setSomeProperty("someValue");
SomeRequestFactory.INSTANCE.context().SomeCall(someProxy).fire();
}
}
Proxies should be created by a RequestContext, not an AutoBeanFactory! Using the JsonRpc dialect doesn't change how you use RequestFactory.
public void onModuleLoad() {
SomeRequestContext ctx = SomeRequestFactory.INSTANCE.context();
SomeProxy someProxy = ctx.create(SomeProxy.class);
someProxy.setSomeProperty("someValue");
ctx.SomeCall(someProxy).fire();
}