Hi Tim,

Thanks for your response... I was having trouble getting the first scenario
to work, but that's because I took an approach of specifying two
configurations in my persistence.xml and then using a spring object to
dictate which one to load based on passing in a flag into my constructor in
my tests.  This has worked fine, other than the problem I've mentioned
below.  When I separated them into two different files, I started getting a
lot of complaining from hibernate.  I think because I must have parts in my
tests that aren't using the mocked out object and therefore causing
hibernate to try to load the one that is nonexistent...  All our other
projects use the database directly instead of mocking out the database
connection because I haven't found an acceptable way to do it.. just easier
to let everything modify the test database.

I find your second solution interesting.. and I think maybe a bit cleaner
... it's actually what I was hoping someone would point me to.  My confusion
is still the same though, how would maven know to load the file and
substitute the property?  And if it's hibernate that would do it, then how
would it get it at runtime?  Would I always have to pass in a system
property?  I guess I should look up properties and the persistence.xml ...
maybe there is something I'm just not understanding.

Ryan

On 7/13/07, Tim Kettler <[EMAIL PROTECTED]> wrote:

Hi,

you have a few options based on your concrete scenario:

If you just want to unit test a ejb project you can create two
'persistence.xml' files one in 'src/main/resources' for production use
and one in 'src/test/resources' for testing. The testing persistence.xml
should then shadow the production one.

An other option would be to enable filtering on the resource dir:

   <build>
     <resources>
       <resource>
         <directory>src/main/resources</directory>
         <filtering>true</filtering>
       </resource>
     </resources>
   </build>

and have profiles for the different environments:

   <profiles>
     <profile>
       <id>test</id>
       <activation>
         <activeByDefault>true</activeByDefault/>
       </activation>
       <properties>
         <connection>testconnection</nconnection>
       </properties>
     </profile>
     <profile>
       <id>production</id>
       <properties>
         <connection>prodconnection</nconnection>
       </properties>
     </profile>
   </profiles>

And put ${connection} in the persistence.xml.

Hope this helps
-Tim


Ryan Moquin schrieb:
> Hi, I know that in order to use different configuration files (such as a
> persistence.xml), such as test configurations vs. production
configurations
> I need to setup profiles to allow these different files to be used.
> What is
> the preferred way to indicate to maven how to find a configuration file
> that
> should be used?  Such as, I have a persistence.xml file, currently I
> have my
> test database definition in it as a separate entry from my production
> configuration.  This works fine in theory because I can mock out my
> persistence classes to use the test configuration for tests.  The
> problem is
> that hibernate loads BOTH definitions when it starts up, whether it's
used
> or not which causes problems with hot deploying, when my production
> environment is running (since my test config is loaded in production,
> and my
> tests are trying to use that configuration).  I'm also running into
> problems
> of needing persistence configurations that can use other database
servers
> other than assuming localhost.
>
> Does anyone have a strategy or know of a link that I can look at that
will
> help me implement an appropriate strategy to use/bundle differnet
> persistence.xml files based upon the loaded maven profile?  Thanks!
>
> Ryan
>


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


Reply via email to