-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Problem with JPA and JUnit
PostPosted: Tue Jan 01, 2008 10:40 am 
Newbie

Joined: Tue Jan 01, 2008 10:14 am
Posts: 3
Location: Toronto
Hibernate version: 3.2.2.ga
Hibernate annotation/entity manager: 3.2.1.ga

Note: I have two projects; the common code in one jar file, and the project I am working on (a webapp), which contains the persistence.xml.

persistence.xml:
<?xml version='1.0'?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/ ... ce_1_0.xsd" version="1.0">
<persistence-unit name="default">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<jar-file>WEB-INF/lib/xware-common-2.0-SNAPSHOT.jar</jar-file>
</persistence-unit>
</persistence>

The problem(s):
The first problem, while annoying, is at least fixable. When using junit and Hibernate/JPA, I had to hardcode the link to the jar-file reference, otherwise it will not find it on the classpath. Is there a way to get that to work, so that I don't need to keep hacking the persistence file for use with JUnit, and then fixing it for deployment?

The second problem is the one I have not found a workaround for. When I do change the persistence.xml jar-file mapping to hardcode the link to the library, the entity manager no longer sees the annotated classes in the project with the unit tests. How can I fix that?

_________________
CodeOgre


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 01, 2008 1:48 pm 
Hibernate Team
Hibernate Team

Joined: Thu Apr 05, 2007 5:52 am
Posts: 1689
Location: Sweden
Have you considered filtering your persistence.xml during the build? I normally use maven as build tool and resources like persistence.xml or data source definitions I filter using maven's filter functionality (http://maven.apache.org/guides/getting-started/index.html#How_do_I_filter_resource_files). Depending on the environment I am building for different values get filtered into the resource files. Ant offers filtering as well of course.

When you are mentioning JUnit - how do you set your tests up? Do you use pure junit? If you for example also use Spring in your web application you could use abstractJpaTests ( http://static.springframework.org/spring/docs/2.5.x/api/org/springframework/test/jpa/AbstractJpaTests.html.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.