aspose file tools*
The moose likes JBoss/WildFly and the fly likes Non matching type for inject of field Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » JBoss/WildFly
Bookmark "Non matching type for inject of field" Watch "Non matching type for inject of field" New topic
Author

Non matching type for inject of field

James Hannoy
Greenhorn

Joined: Dec 26, 2007
Posts: 24
Hi,

I am playing with EJB3 and using the following configuration:

JBoss 4.2.2 GA, EJB3/JPA, Oracle.

Here follows a simple session bean and its remote interface that I've been using:



The PU named "StateMonitor" is mentioned and the same is also mentioned in
my persistence.xml file:



Finally here follows a typical test client:



All these are very similar like any other simple project. The deployment shows no error and the table also get created in the DB.

But, whenever I try to run this simple client, I get the following error:



Could someone guide me in here?
Any help would be greatly appreciated.

-Thanks,
James.
James Hannoy
Greenhorn

Joined: Dec 26, 2007
Posts: 24
So, anybody can give me some pointers to check or any ideas please?

-Thanks,
James.
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 10102
    
165

James,

I don't see any obvious reasons why this should fail. I looked up a similar issue in JBoss JIRA and the comments there seemed to point to classloading issues. Maybe you too are running into a similar issue. What classes have you packaged in your client application? Do you have the MonitorBean packaged in your client application? If so, i would suggest removing that and having only the Monitor interface in the client application. See if that change helps. Let us know if it still doesn't work, we'll see what else might be the cause of this exception.


[My Blog] [JavaRanch Journal]
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 10102
    
165

And which version of Java do you use at the client and on the server?
James Hannoy
Greenhorn

Joined: Dec 26, 2007
Posts: 24
Hi,

Thanks a lot for the reply. Yes I have also seen the Jira posts and was trying a lot of options. Surprisingly the following worked!!!

In my session bean code I have changed PersistenceUnit to PersistenceContext:



And it started working, but with some limitations.
Here follows my client code:



And here follows the output:



As you can see, the create works ( or may be, since toad shows no data in the table though!), but when I try to search the same with the same ID, it throws a null pointer!!

Do I have to use transactions??

Also the @PersistenceUnit and @PersistenceContext things are confusing



Could you please explain?

-Thanks,
James.
James Hannoy
Greenhorn

Joined: Dec 26, 2007
Posts: 24
Also I'm using JDK5 E:\jdk1.5.0_03... for the project.
-Thanks,
James.
James Hannoy
Greenhorn

Joined: Dec 26, 2007
Posts: 24
Hi Jaikiran,

Once more, to answer your original question, these are the imports in my TestClient:



So there is no reference of the MonitorBean session directly.

-Thanks
Pranabesh.
James Hannoy
Greenhorn

Joined: Dec 26, 2007
Posts: 24
Hi,

I have resolved the NullPointer issue. Actually, I changed the <jta-data-source>java:/OracleDS</jta-data-source> to <non-jta-data-source>java:/OracleDS</non-jta-data-source>, which created the problem.

Once I reverted back to <jta-data-source>java:/OracleDS</jta-data-source> in persistence.xml, everything worked fine.

However, I'd be grateful if you can answer my other queries/confusions.

Thanks!
James.
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 10102
    
165

Good to know, you were able to get it working

As for your questions:

Also the @PersistenceUnit and @PersistenceContext things are confusing


The PersistenceUnit and the PersistenceContext inject different 'types' of resources. The @PersistenceUnit is used to inject an EntityManagerFactory whereas the @PersistenceContext is used to inject an EntityManager. In one of the online documentation that i read, they had this detailed explanation:

The @PersistenceContext and @PersistenceUnit annotations perform a similar function: inject persistence context information into a variable; the main difference is the data type of the instance into which you inject the information. If you prefer to have full control over the lifecycle of the EntityManager in your session bean, then use @PersistenceUnit to inject into an EntityManagerFactory instance, and then write the code to manually create an EntityManager and later destroy when you are done, to release resources. If you prefer that the EJB container manage the lifecycle of the EntityManager, then use the @PersistenceContext annotation to inject directly into an EntityManager.


Your other question:

Do I have to use transactions??


It depends on what you are doing. EJBs let you define transactions on each method of the bean. Moreover, if you are using a EntityManager, then you will have to have a transaction.
[ December 27, 2007: Message edited by: Jaikiran Pai ]
James Hannoy
Greenhorn

Joined: Dec 26, 2007
Posts: 24
Thanks a lot Jaikiran.


This explains all of these!

-Regards,
James.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Non matching type for inject of field