Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

could not read mapping from resource

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
Hi guys,

Im fairly new to Hibernate so will not be surprised if this problem is the result of something stupid I have done, and hopefully really easy to fix.

I have two tables Routine and Skill, and Routine has a List of skills. When I try to get the current session, it maps Routine fine and then stops at Skill, saying it could not read mapping from resource: Skill.hbm.xml.

If you want me to post any code let me know.
Any suggestions or help would be greatly appreciated.

Thanks Kazza
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
Is Skill.hbm.xml on the classpath? Is it configured in hibernate.cfg.xml?
 
Kazza Summers
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator

Originally posted by Paul Sturrock:
Is Skill.hbm.xml on the classpath? Is it configured in hibernate.cfg.xml?



Yeah its in the same path as the Routine.hbm.xml and the java files so has to be on classpath. By configured in the hibernate.cfg.xml do you jut mean the file is added at the bottom, like:
<mapping resource="Routine.hbm.xml"/>
<mapping resource="Skill.hbm.xml"/>
or is there something else I need to add?
 
Paul Sturrock
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
Hmm. If both these things are true you won't see this error. Best to double check I think. Look for spelling mistakes in your mapping files, make sure the hbm.xml files are in the packages you expect them to be and they are packaged with your classes correctly.

Also remember, your SessionFactory must be configured somewhere. If you are using hibernate.cfg.xml to do this every mapping file must by included. If your mapping files (and classes) are in the default package the two lines your posted should be fine.
 
Kazza Summers
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator

Originally posted by Paul Sturrock:
Hmm. If both these things are true you won't see this error. Best to double check I think. Look for spelling mistakes in your mapping files, make sure the hbm.xml files are in the packages you expect them to be and they are packaged with your classes correctly.

Also remember, your SessionFactory must be configured somewhere. If you are using hibernate.cfg.xml to do this every mapping file must by included. If your mapping files (and classes) are in the default package the two lines your posted should be fine.



I have checked and checked for spelling mistakes or any little extra things. Im configuring it with the hibernate.cfg.xml and all mapping files are included. Could it be anything to do with this:
<list name="skills" cascade="all-delete-orphans">
<key column="routine_id" not-null="true"/>
<list-index column="skill_index"/>
<one-to-many class="Skill"/>
</list>
This is in the Routine.hbm.xml to represent my list of skills. Do I need anything in Skill.hbm to match this. I want it to be unidirectional.
 
Paul Sturrock
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator


Do I need anything in Skill.hbm to match this. I want it to be unidirectional.


If your relationship is unidirectional, then no.

One thing I notice is all your mappings so far don't include any package information. Are all your mapping files in the default package?
 
Kazza Summers
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
Yeah, I have only the default package and then seperate folders inside this. I got started on the project before I really understood the IDE enough to think about packages.
 
Paul Sturrock
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
Hmm. You are running this in an IDE? Is your IDE configured to build hbm.xml files to the same directory as your class files?

There is one other thing that could cause this I believe. You might want to check your DOCTYPE declaration: is it pointing at the right DTD (for the version of Hibernate you are using) and is that DTD accessable?
 
Kazza Summers
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
The DTD and all that top stuff is exactly the same in Skill as it is in Routine.
Plus the Routine.hbm.xml is in the same folder as Skill.hbm.xml and they are both being added to the bin folder with the class files when project is built. Routine is being mapped without a problem.
 
Paul Sturrock
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
Its got to be a typo then. Can you write code to access Skill directly (i.e. not as part of the list)?
 
Kazza Summers
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
Not sure I understand what you mean. Skill is just a normal object, it is only used by the Routine list. A skill object gets created and then added to Routine's list.
 
Paul Sturrock
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
I mean, can you do this:

where a Skill exists in your database with an ID of 1.
 
Kazza Summers
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
This is the line of code it cant get past:

Session session = HibernateUtil.getSessionFactory().getCurrentSession();

so I cant even get to the part where i can load the object.
Not sure if this will help but here is the HibernateUtil class:
public class HibernateUtil {

private static final SessionFactory sessionFactory;

static {
try {
// Create the SessionFactory from hibernate.cfg.xml
sessionFactory = new Configuration().configure().buildSessionFactory();
} catch (Throwable ex) {
// Make sure you log the exception, as it might be swallowed
System.err.println("Initial SessionFactory creation failed." + ex);
throw new ExceptionInInitializerError(ex);
}
}

public static SessionFactory getSessionFactory() {
return sessionFactory;
}

}


It is screwing up on the try catch block and throwin the exception.
 
Paul Sturrock
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
Ok. So now you know that it is your SessionFactory configuration that is to blame. What Hibernate does when you call configure().buildSessionFactory() is steps through all the hbm.xml mapping files you have defined in your configuration file (hibernate.cfg.xml), tries to parse the mapping then "bind" the class named in that mapping. I've already mentioned the two likely (and one less likely) reasons why this could be failing. I can't offer you any more advice than checking these things very carefully.
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
Dear Kazza,
Were u able to solve your problem ?
I am getting the same error as yours.
I re-checked everything as Mr.Paul said.But still the same error.See the trace below:
-------------------------------------------------------------------------
INFO: Reading mappings from resource: Message.hbm.xml
Jun 11, 2006 12:41:29 PM org.hibernate.util.XMLHelper$ErrorLogger error
SEVERE: Error parsing XML: XML InputStream(5) Element type "hibernate-mapping"
s not declared.
org.hibernate.MappingException: Could not read mappings from resource: Message.h
bm.xml
at org.hibernate.cfg.Configuration.addResource(Configuration.java:485)
at org.hibernate.cfg.Configuration.parseMappingElement(Configuration.jav
a:1465)
at org.hibernate.cfg.Configuration.parseSessionFactory(Configuration.jav
a:1433)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1414)
-------------------------------------------------------------------------
 
Paul Sturrock
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
Manju Viswam, please don't hijack someone elses topic. The error you have is different:


SEVERE: Error parsing XML: XML InputStream(5) Element type "hibernate-mapping"
s not declared


You seem to have an invalid hbm.xml file. Check Message.hbm.xml against the DTD. Are all the mandatory elements there (in particular hibernate-mapping?)
 
Manju Viswam
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
Dear Mr. Paul,

You were exactly right.I had given the DTD declaration of the cfg.xml file inside hbm.xml. I corrected the DTD of hbm.xml to
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

Its working fine now.
Thank you so much !
Alongside,this new javarancher, apologise for replying to Mr.Kazza's post.I thought this is a conversation thread

Thanks & cheers,
Manju Viswam
 
Paul Sturrock
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator


Alongside,this new javarancher, apologise for replying to Mr.Kazza's post.I thought this is a conversation thread


No need to apologise . We prefer one problem to one topic thats all; makes it much easier for others to follow. Glad you resolved your problem.
 
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
hi Kazza Summers,
i encountered the same problem as yours.But even though this exception is displayed,if you look at the the weblogic prompt,few lines below this exception there is another exception being thrown basically NoClassDefFoundError,this could be that hibernate3.jar is not accessible.

regards,
kumari
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator

Originally posted by kumari Jain:
...if you look ...few lines below this exception there is another exception being thrown basically NoClassDefFoundError,this could be that hibernate3.jar is not accessible.

regards,
kumari



Another cause of the NoClassDefFoundError/ClassNotFoundException is that the class that is referenced by the <class name=Foo ...> attribute in the hbm file can't be found in the classpath. The class name could be misspelled (e.g., foo vs. Foo) or missing altogether (which was the cause in my case).

Cheers,
Rich
 
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator

Originally posted by Rich Youngkin:


Another cause of the NoClassDefFoundError/ClassNotFoundException is that the class that is referenced by the <class name=Foo ...> attribute in the hbm file can't be found in the classpath. The class name could be misspelled (e.g., foo vs. Foo) or missing altogether (which was the cause in my case).

Cheers,
Rich



Hi Rich, please note the dates on the original thread, they are about 8 months old.

Mark
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
In case anyone else get this error:
I got this error and the reason was that a property name that existed in the hbm.xml file was missing as a field in the java file.
Good luck
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
I was getting this error because the mappings in hibernate.cfg.xml were in the wrong order.
 
Mark Spritzler
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
I am going to close this resurrected thread. This thread is two years old.

Thanks

Mark
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
    Bookmark Topic Watch Topic
  • New Topic