-->
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.  [ 3 posts ] 
Author Message
 Post subject: Best practice for including mapping file fragments?
PostPosted: Mon Mar 12, 2007 5:49 pm 
Newbie

Joined: Tue Oct 26, 2004 4:47 pm
Posts: 7
Using Hibernate 3, and am running into a code duplication problem. I've got a couple of concrete classes which all share a common set of scalars defined in a superclass:

MetadataDomainObject (abstract)
createdDate
modifiedDate

I want to keep these scalars defined in each table for performance reasons, but don't want to duplicate code in each .hbm.xml mapping file.

I tried to include XML fragments in the mapping files to bring in these metadata fields, but I am limited in the way that I can bring them in (either a jar, http, or file mapping) -- they don't work in both the development and deployment environment.

For example,

User.hbm.xml:

Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD//END" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" [
   <!ENTITY metadata SYSTEM "src/config/hibernate/metadata.fragment">
]>
<hibernate-mapping>
   <class name="com.hannonhill.paces.dom.User" table="USERS">
      <id name="id" column="id" type="long" unsaved-value="0">
         <generator class="native"/>
      </id>

      &metadata;
   </class>
</hibernate-mapping>


This works when running my integration tests from eclipse, because then the "src/config/hibernate/metadata.fragment" relative path resolves correctly. This breaks when I deploy, because there is no "src/config/hibernate" path in my deployed WAR environment. I think that ideally I would be able to use classpath:// as a protocol for defining these external entities -- unfortunately, that protocol is not supported by the default Java 1.5 xerces parser.

Any recommendations on a better way to go about approaching this?

thanks
Collin


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 20, 2007 4:44 am 
Newbie

Joined: Fri Jul 20, 2007 6:02 pm
Posts: 12
Check CLASSPATH


Top
 Profile  
 
 Post subject: Re: Best practice for including mapping file fragments?
PostPosted: Mon Aug 20, 2007 5:18 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
cvandyck wrote:
classpath:// as a protocol for defining these external entities -- unfortunately, that protocol is not supported by the default Java 1.5 xerces parser.


It is supported by the Hibernate entity resolver. It's also in the documentation.

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.