If you are not using a (JPA) EntityManager or Tapestry's Hibernate
integration, you need to let Hibernate know about the entities
yourself. If you are really only testing the DAOs, you shouldn't need
to power up the IoC registry. Here's an excerpt of my persistence test
base class (with Mockito):

public abstract class PersistenceTest {
        protected Session session;
        protected Transaction transaction;
        protected static SessionFactory sessionFactory;
        protected HibernateSessionSource sessionSource;

        @BeforeClass
        public static void staticSetUp() {
                AnnotationConfiguration configuration = new 
AnnotationConfiguration();
                configuration.addAnnotatedClass(...);
                configuration.addAnnotatedClass(...);
                sessionFactory = configuration.buildSessionFactory();
        }

        @Before
        public void beforeTest() {
                session = sessionFactory.openSession();
                transaction = session.beginTransaction();
                sessionSource = mock(HibernateSessionSource.class);
                when(sessionSource.create()).thenReturn(session);
        }

        @After
        public void afterTest() {
                if (transaction != null) if (transaction.isActive()) 
transaction.rollback();
        }
}

Kalle


On Fri, Feb 4, 2011 at 2:26 PM, [email protected]
<[email protected]> wrote:
> On 2/4/11 1:49 PM, [email protected] wrote:
>>
>> On 2/4/11 1:45 PM, Thiago H. de Paula Figueiredo wrote:
>>>
>>> On Fri, 04 Feb 2011 19:37:03 -0200, [email protected]
>>> <[email protected]> wrote:
>>>
>>>> Hello,
>>>
>>> Hi!
>>>
>>>> org.hibernate.MappingException: Unknown entity:
>>>> com.mustardgrain.clientdailyupdate.entities.User
>>>> even though I'm using the import javax.persistence.Entity annotation.
>>>
>>> You'll probably need to add your AppModule to the list of modules before
>>> building the Registry.
>>>
>> I've actually tried adding the AppModule before building as well, and when
>> I added it I got this exception:
>> java.lang.IllegalArgumentException: Contribution
>> com.mustardgrain.clientdailyupdate.services.AppModule.contributeRequestHandler(OrderedConfiguration,
>> RequestFilter) (at AppModule.java:120) is for service 'RequestHandler',
>> which does not exist.
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: [email protected]
>> For additional commands, e-mail: [email protected]
>>
> Also when I created a MockModule class, which created an EasyMock
> RequestHandler I still ended up with  org.hibernate.MappingException:
> Unknown entity: com.mustardgrain.clientdailyupdate.entities.User
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to