Re: UserTransaction injection

2008-11-11 Thread Carlos MacLeod
2008/11/11, David Blevins <[EMAIL PROTECTED]>:
>
> On Nov 11, 2008, at 11:00 AM, Carlos MacLeod wrote:
>
>> Hi,
>>
>> Is there a way to inject the UserTransaction without a JNDI lookup ?
>> In Glassfish i simple di:
>>
>> @Resource
>> private UserTransaction utx;
>>
>>
>> And the transaction is injected. How can i configure the openejb so it
>> can work ?
>
> Hi Carlos,
>
> That style of injection should work just fine for any servlet or ejb.
> If it's an ejb the ejb should be annotated with
> @TransactionManagement(BEAN).
>

Hi David,

I never used this annotation before ( Since Sun's Glassfish does not
require it in order to do the injection ), but i tried and still not
working.

> If you have any details on which kind of component you are using it in
> and what Tomcat version, that'd be great.
>
> -David
>
>


I am using
- apache-tomcat-6.0.16 ( bundled in netbeans, with the java agent
loaded by -javaagent option in jvm options )
- OpenEJB 3.1 ( downloaded as .war )
- JSF 1.2
- OpenJPA ( Bundled in openejb )
- JavaDB
- Java 1.6.0_04 64 bits
- Suse Linux 10.2 X86_64


My controller bean relevant code( From Netbeans JSF CRUDE )

@TransactionManagement(TransactionManagementType.BEAN)
public class CategoriaController {

@Resource
private UserTransaction utx = null;

@PersistenceUnit(unitName = "BundaPU")
private EntityManagerFactory emf = null;

public EntityManager getEntityManager() {
return emf.createEntityManager();
}

  ...
  ...

}

The persistence Unit:


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_1_0.xsd";>
  
org.apache.openjpa.persistence.PersistenceProviderImpl
java:openejb/Resource/BundaDS

  

  



The JNDI binding in openejb.xml


JdbcDriver org.apache.derby.jdbc.ClientDriver
JdbcUrl jdbc:derby://localhost:1527/testedb
UserName X
Password XX
JtaManaged true





When OpenEJB deploys the application i get the following error ( The
database works fine, the problem only occours when i use
@Resource private Usertransaction utx;
, no matter if i use
@TransactionManagement(TransactionManagementType.BEAN) or not )


2008-11-12 00:40:54,454 - INFO  - Configuring enterprise application:
/windows/D/NetBeansProjects/Bunda/build/web
2008-11-12 00:40:54,491 - INFO  - Configuring
PersistenceUnit(name=BundaPU,
provider=org.apache.openjpa.persistence.PersistenceProviderImpl)
2008-11-12 00:40:54,492 - INFO  - Auto-creating a Resource with id
'BundaDSNonJta' of type 'DataSource for 'BundaPU'.
2008-11-12 00:40:54,492 - INFO  - Configuring
Service(id=BundaDSNonJta, type=Resource, provider-id=BundaDS)
2008-11-12 00:40:54,492 - INFO  - Creating Resource(id=BundaDSNonJta)
2008-11-12 00:40:54,697 - INFO  - Adjusting BundaPU 
to 'BundaDS'
2008-11-12 00:40:54,697 - INFO  - Adjusting BundaPU
 to 'BundaDSNonJta'
2008-11-12 00:40:54,700 - INFO  - Enterprise application
"/windows/D/NetBeansProjects/Bunda/build/web" loaded.
2008-11-12 00:40:54,700 - INFO  - Assembling app:
/windows/D/NetBeansProjects/Bunda/build/web
2008-11-12 00:40:54,730 - INFO  - PersistenceUnit(name=BundaPU,
provider=org.apache.openjpa.persistence.PersistenceProviderImpl)
2008-11-12 00:40:55,147 - INFO  - Deployed
Application(path=/windows/D/NetBeansProjects/Bunda/build/web)
2008-11-12 00:40:55,155 - ERROR - Error merging OpenEJB JNDI entries
in to war /Bunda: Exception: null
java.lang.NullPointerException
at java.util.Hashtable.put(Hashtable.java:394)
at 
org.apache.catalina.deploy.NamingResources.addResourceEnvRef(NamingResources.java:320)
at 
org.apache.openejb.tomcat.catalina.TomcatJndiBuilder.mergeRef(TomcatJndiBuilder.java:416)
at 
org.apache.openejb.tomcat.catalina.TomcatJndiBuilder.mergeJndi(TomcatJndiBuilder.java:140)
at 
org.apache.openejb.tomcat.catalina.TomcatWebAppBuilder.start(TomcatWebAppBuilder.java:270)
at 
org.apache.openejb.tomcat.catalina.GlobalListenerSupport.lifecycleEvent(GlobalListenerSupport.java:58)
at 
org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:117)
at 
org.apache.catalina.core.StandardContext.start(StandardContext.java:4252)
at 
org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:791)
at 
org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:771)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:525)
at 
org.apache.catalina.startup.HostConfig.deployDescriptor(HostConfig.java:626)
at 
org.apache.catalina.startup.HostConfig.deployDescriptors(HostConfig.java:553)
at 
org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:488)
at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1147)
at 
org.apache.catalina

Re: UserTransaction injection

2008-11-11 Thread David Blevins


On Nov 11, 2008, at 11:00 AM, Carlos MacLeod wrote:


Hi,

Is there a way to inject the UserTransaction without a JNDI lookup ?
In Glassfish i simple di:

@Resource
private UserTransaction utx;


And the transaction is injected. How can i configure the openejb so it
can work ?


Hi Carlos,

That style of injection should work just fine for any servlet or ejb.   
If it's an ejb the ejb should be annotated with  
@TransactionManagement(BEAN).


If you have any details on which kind of component you are using it in  
and what Tomcat version, that'd be great.


-David



Re: ServiceProvider Id in openejb.xml

2008-11-11 Thread David Blevins


On Nov 10, 2008, at 6:02 PM, ebmm_axis wrote:



So,I've been playing around witht his a little bit more, but I still  
can't

get it to work...


On the OpenEJB site it states the following:


The service-jar.xml should be placed not in the META-INF but  
somewhere in
your package hierarchy (ours is in /org/apache/openejb/service- 
jar.xml)
which allows the services in your service-jar.xml to be referenced  
by name
(such as DefaultStatefulContainer) or more specifically by package  
and id

(such as org.apache.openejb#DefaultStatefulContainer).

I have a jar that I have copied to the lib subdirectory with a file  
called

service-jar.xml.

I don'tknow if the syntax of the service-jar.xml is right or not,  
but this

is what I've found around the net...




In my openejb-jar.xml config file I have the following:

provider="myId">




This is really close, you just need to add the package part to the  
'provider' attribute.  So if you put it at META-INF/com.foo/service- 
jar.xml, the provider id would be "com.foo#myId".


That said, there might be a simpler way to do what you want overall.   
The service-jar.xml stuff is really geared towards plugging in  
something that needs to be configurable.  If you simply want an  
instance of a specific class injected you can create a property editor  
for it as described here:  http://openejb.apache.org/3.0/custom-injection.html 
.


Let us know if that helps.  Also, feel free to go into detail on the  
kind of thing you're looking to add to the system as we definitely use  
that feedback to drive features.  We've talked about enhancements to  
the service-jar.xml/openejb.xml functionality as well as specific  
enhancements for j2ee connector configuration and more.


-David



UserTransaction injection

2008-11-11 Thread Carlos MacLeod
Hi,

Is there a way to inject the UserTransaction without a JNDI lookup ?
In Glassfish i simple di:

@Resource
private UserTransaction utx;


And the transaction is injected. How can i configure the openejb so it
can work ?


( I use JTA enabled datasource, openJPA andt Tomcat )


-- 
Best regards,
Carlos MacLeod

"Java is like violence: if it doesn's solve your problem, you aren't
using enough of it"