tomee-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From David Blevins <>
Subject Re: Configuring hibernate properties in unit tests
Date Tue, 02 Sep 2008 19:10:53 GMT

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">

       <property name="" value="create-drop"/>
       <property name="hibernate.dialect" value="mysql"/>

You can override it in your test case like so:

   Properties p = new Properties();

   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.



View raw message