You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomee.apache.org by quizzical <qu...@gmail.com> on 2008/09/01 14:54:06 UTC
RE: Configuring hibernate properties in unit tests
Marcin Kwapisz-2 wrote:
>
> I think that blog entry can be useful.
> http://qbeukes.blogspot.com/2008/08/toplink-as-your-openejb-persistence.html
>
>
Thanks for the link, this post doesn't look to be able to help me with
runtime configuration of hibernate properties though, looks like its not
possible so I will settle for seperate persistence.xml files.
Cheers
--
View this message in context: http://www.nabble.com/Configuring-hibernate-properties-in-unit-tests-tp19167232p19254275.html
Sent from the OpenEJB User mailing list archive at Nabble.com.
Re: Configuring hibernate properties in unit tests
Posted by quizzical <qu...@gmail.com>.
David Blevins wrote:
>
>
> I went ahead and hacked something up here. Now you can override
> properties on the persistence-units just as you can override the
> properties of <Resource> and <Container> objects.
>
> So with a unit like so:
>
> <persistence-unit name="movie-unit">
> <provider>org.hibernate.ejb.HibernatePersistence</provider>
> <jta-data-source>movieDatabase</jta-data-source>
> <non-jta-data-source>movieDatabaseUnmanaged</non-jta-data-source>
>
> <properties>
> <property name="hibernate.hbm2ddl.auto" value="create-drop"/>
> <property name="hibernate.dialect" value="mysql"/>
> </properties>
> </persistence-unit>
>
>
> You can override it in your test case like so:
>
> Properties p = new Properties();
> p.put(Context.INITIAL_CONTEXT_FACTORY,
> "org.apache.openejb.client.LocalInitialContextFactory");
>
> p.put("movie-unit.hibernate.dialect", "hsql");
>
> Context context = new InitialContext(p);
>
> So the override format is "<unitName>.<propertyName>=<valueName>"
>
> I've uploaded new 3.1-SNAPSHOTs to the apache snapshot repo [1]. Give
> them a try and let us know how it goes.
>
> -David
>
> [1]
> http://people.apache.org/repo/m2-snapshot-repository/org/apache/openejb/
>
>
>
That looks good, i'll give it a try this evening.
--
View this message in context: http://www.nabble.com/Configuring-hibernate-properties-in-unit-tests-tp19167232p19290840.html
Sent from the OpenEJB User mailing list archive at Nabble.com.
Re: Configuring hibernate properties in unit tests
Posted by David Blevins <da...@visi.com>.
On Sep 2, 2008, at 11:35 AM, Marcin Kwapisz wrote:
>> Thanks for the link, this post doesn't look to be able to help me
>> with
>> runtime configuration of hibernate properties though, looks like its
>> not
>> possible so I will settle for seperate persistence.xml files.
>>
> [Marcin Kwapisz]
> Maybe I misunderstood something. You want to set persistent.xml
> properties in your test code. Look carefully at setUpClass method.
> There are properties set for toplink JPA, but I think you can
> replace them with properties for hibernate easily.
> The only thing I don't know is which properties are more important:
> those placed in persistent.xml or in test code.
I think that's TopLink specific. But it's a good idea and one we've
talked about in the past.
I went ahead and hacked something up here. Now you can override
properties on the persistence-units just as you can override the
properties of <Resource> and <Container> objects.
So with a unit like so:
<persistence-unit name="movie-unit">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<jta-data-source>movieDatabase</jta-data-source>
<non-jta-data-source>movieDatabaseUnmanaged</non-jta-data-source>
<properties>
<property name="hibernate.hbm2ddl.auto" value="create-drop"/>
<property name="hibernate.dialect" value="mysql"/>
</properties>
</persistence-unit>
You can override it in your test case like so:
Properties p = new Properties();
p.put(Context.INITIAL_CONTEXT_FACTORY,
"org.apache.openejb.client.LocalInitialContextFactory");
p.put("movie-unit.hibernate.dialect", "hsql");
Context context = new InitialContext(p);
So the override format is "<unitName>.<propertyName>=<valueName>"
I've uploaded new 3.1-SNAPSHOTs to the apache snapshot repo [1]. Give
them a try and let us know how it goes.
-David
[1] http://people.apache.org/repo/m2-snapshot-repository/org/apache/openejb/
RE: Configuring hibernate properties in unit tests
Posted by Marcin Kwapisz <mk...@zsk.p.lodz.pl>.
> Thanks for the link, this post doesn't look to be able to help me with
> runtime configuration of hibernate properties though, looks like its
> not
> possible so I will settle for seperate persistence.xml files.
>
[Marcin Kwapisz]
Maybe I misunderstood something. You want to set persistent.xml properties in your test code. Look carefully at setUpClass method. There are properties set for toplink JPA, but I think you can replace them with properties for hibernate easily.
The only thing I don't know is which properties are more important: those placed in persistent.xml or in test code.
Regards
--
Marcin Kwapisz
Division of Computer Networks
Technical Univeristy of Lodz, Poland