tomee-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From David Blevins <david.blev...@visi.com>
Subject Re: OpenEJB - Missing required persistence.xml
Date Thu, 14 Feb 2008 01:05:22 GMT

On Feb 13, 2008, at 6:26 AM, <Karsten.Ohme@t-systems.com> <Karsten.Ohme@t-systems.com

 > wrote:

> I get:
>
> Apache OpenEJB 3.0-beta-2    build: 20080131-03:38
> http://openejb.apache.org/
> - openejb.home = C:\workspace\TestFacade\target
> - openejb.base = C:\workspace\TestFacade\target
> - Configuring Service(id=Default Security Service,  
> type=SecurityService, provider-id=Default Security Service)
> - Configuring Service(id=Default Transaction Manager,  
> type=TransactionManager, provider-id=Default Transaction Manager)
> - Configuring Service(id=My DataSource, type=Resource, provider- 
> id=Default JDBC Database)
> - Configuring Service(id=My Unmanaged DataSource, type=Resource,  
> provider-id=Default JDBC Database)
> - Configuring Service(id=My JMS Resource Adapter, type=Resource,  
> provider-id=Default JMS Resource Adapter)
> - Configuring Service(id=My JMS Connection Factory, type=Resource,  
> provider-id=Default JMS Connection Factory)
> - Configuring Service(id=Default JDK 1.3 ProxyFactory,  
> type=ProxyFactory, provider-id=Default JDK 1.3 ProxyFactory)
> - Configuring Service(id=My CMP Container, type=Container, provider- 
> id=Default CMP Container)
> - Configuring Service(id=My BMP Container, type=Container, provider- 
> id=Default BMP Container)
> - Configuring Service(id=My Stateful Container, type=Container,  
> provider-id=Default Stateful Container)
> - Configuring Service(id=My Stateless Container, type=Container,  
> provider-id=Default Stateless Container)
> - Configuring Service(id=My MDB Container , type=Container, provider- 
> id=Default MDB Container)
[...]
>
> For some strange reason when I was editing and using the openejb.xml  
> the error was different; the tables in the database were not created.
>

Based on that output, it looks like you've got a 'conf' directory  
under 'C:\workspace\TestFacade\target'.  When we see one of those, we  
unpack a complete setup of security, logging, and an openejb.xml  
file.  You can either delete the conf directory or simply put an  
openejb.xml file in there containing nothing more than "<openejb/>" as  
openejb will never overwrite it if it sees one is there (same with all  
the files in conf/).  If you delete the conf/ directory we try and  
tailor things a bit more for embedded testing; mostly shorter log  
lines with no date/time, as well we try and stop activemq and hsqldb  
from writing files to your disk that would have to be cleaned up  
manually.

>    @Before
>    public void initContext() throws Exception {
>        Properties properties = new Properties();
>        properties.setProperty(Context.INITIAL_CONTEXT_FACTORY,
>                 
> "org.apache.openejb.client.LocalInitialContextFactory");
>
>        if (DB_MODE == MYSQL) {
>            properties.setProperty("Default\\ JDBC\\  
> Database.Password", "tpg");
>            properties.setProperty("Default\\ JDBC\\ Database.JdbcUrl",
>                    "jdbc:mysql://localhost:3306/tpg-server");
>            properties.setProperty("Default\\ JDBC\\  
> Database.JdbcDriver",
>                    "com.mysql.jdbc.Driver");
>            properties.setProperty("Default\\ JDBC\\  
> Database.UserName", "tpg");
>            properties.setProperty(
>                    "Default\\ JDBC\\ Database.ConnectionInterface",
>                    "javax.sql.DataSource");
>        }
>        if (DB_MODE == DERBY) {
>            properties.setProperty("Default\\ JDBC\\ Database.JdbcUrl",
>                    "jdbc:derby:derbyDB;create=true");
>            properties.setProperty("Default\\ JDBC\\  
> Database.JdbcDriver",
>                    "org.apache.derby.jdbc.EmbeddedDriver");
>            properties.setProperty(
>                    "Default\\ JDBC\\ Database.ConnectionInterface",
>                    "javax.sql.DataSource");
>        }
>
>        InitialContext initialContext = new InitialContext(properties);
>        Object ref =  
> initialContext.lookup(TestFacadeImpl.class.getSimpleName()
>                + "Remote");
>        service = (TestFacade) ref;
>    }

That's a cool trick.  I never thought of doing that.  You need to  
remove the '\\' as java.util.Properties won't do any escaping on  
setProperties.  The escaping only happens when properties data is read  
from a text file or an xml -- and in each situation the escaping rules  
are different.

I'd definitely use the 'new://Resource' syntax i showed you and shy  
away from using "Default JDBC Database" as the resource name.  Reason  
being is that it will be much easier to see if your setup is working  
or not.  You could use the same name for your DERBY and MYSQL  
Resources, but I'd use different, more descriptive names so that it's  
easier to see with certainty via the log output which is getting used.

Something like this would be most reliable:

        if (DB_MODE == MYSQL) {
            properties.setProperty("MySqlDatabase", "new://Resource? 
type=DataSource");
            properties.setProperty("MySqlDatabase.JdbcUrl",  
"jdbc:mysql://localhost:3306/tpg-server");
            properties.setProperty("MySqlDatabase.JdbcDriver",  
"com.mysql.jdbc.Driver");
            properties.setProperty("MySqlDatabase.UserName", "tpg");
            properties.setProperty("MySqlDatabase.Password", "tpg");
        } else if (DB_MODE == DERBY) {
            properties.setProperty("DerbyDatabase", "new://Resource? 
type=DataSource");
            properties.setProperty("DerbyDatabase.JdbcUrl",  
"jdbc:derby:derbyDB;create=true");
            properties.setProperty("DerbyDatabase.JdbcDriver",  
"org.apache.derby.jdbc.EmbeddedDriver");
        }

That would give you the clearest log output and the most immediate  
feedback on what's going on.  We did have some issues in 3.0-beta-1  
that resulted in difficulty when people didn't use 'Default JDBC  
Database' as the name, but those were all fixed 3.0-beta-2.  Now it's  
highly encouraged not to use that name.

Note, I cut out the ConnectionInterface=javax.sql.DataSource property  
because that's the default for any <Resource> or <Connector> of  
type=DataSource.

On a similar note, the above syntax that goes "new://Resource? 
type=DataSource" could also be specified as "new://Resource? 
type=javax.sql.DataSource", or "new://Connector?type=DataSource", or  
"new://Connector?type=javax.DataSource".  It's fine to use whichever  
you like best.  Connector is an alias for Resource, and for the "type"  
attribute "DataSource" is an alias for "javax.sql.DataSource".

-David


Mime
View raw message