-->
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: Adding mapping resource dynamically in Config object
PostPosted: Thu Jun 08, 2006 12:54 pm 
Newbie

Joined: Wed Jun 07, 2006 3:21 pm
Posts: 13
hi ,
I have the persistent class Person.java in a package named com.foo.hibernate and the correspoding mapping resource is in directory called persistence-config ( mapping resource-Person.hbm.xml) . I am trying to configure the mapping resource dynamically using the Configuration.addClass() providing the fully qualified name of Persistence class .Since the corresponding mapping resource is not under the same package , I am getting an error "Mapping resource not available" .How should I proceed .


Hibernate version:
3.1.3

Mapping documents:

Code between sessionFactory.openSession() and session.close():

config.addClass(com.foo.hibernate.Person.class)
Full stack trace of any exception that occurs:
[INFO] Configuration - Reading mappings from resource: com/foo/hibernate/Person.hbm.xml
org.hibernate.MappingException: Resource: com/foo/hibernate/Person.hbm.xmlnot found

Name and version of the database you are using:

The generated SQL (show_sql=true):

Debug level Hibernate log excerpt:


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 08, 2006 1:34 pm 
Regular
Regular

Joined: Thu Sep 22, 2005 1:53 pm
Posts: 88
Location: Rio de Janeiro
the hibernate JavaDoc says this about readClass(..):

Quote:
Read a mapping from an application resource, using a convention. The class foo.bar.Foo is mapped by the file foo/bar/Foo.hbm.xml.


So if you want o read the mapping document from another location than the convention try to use this method:

Code:
    config.addFile(<path to file>)

Read mappings from a particular XML file

If all of your mapping documents are in the same diretory you can use:


Code:
    config.addDirectory(<Diretory with the mappings>)

Read all mapping documents from a directory tree. Assume that any file named *.hbm.xml is a mapping document.

Good Luck!

_________________
DonĀ“t forget to rate!


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.