• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Non matching type for inject of field

 
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So, anybody can give me some pointers to check or any ideas please?

-Thanks,
James.
 
Sheriff
Posts: 10445
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Jaikiran Pai
Sheriff
Posts: 10445
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And which version of Java do you use at the client and on the server?
 
James Hannoy
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Also I'm using JDK5 E:\jdk1.5.0_03... for the project.
-Thanks,
James.
 
James Hannoy
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 10445
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks a lot Jaikiran.


This explains all of these!

-Regards,
James.
 
reply
    Bookmark Topic Watch Topic
  • New Topic