-->
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: Using hibernate annotations I get a MappingNotFoundException
PostPosted: Sat Dec 30, 2006 3:29 pm 
Newbie

Joined: Sat Dec 30, 2006 3:07 pm
Posts: 16
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

When I looked online it said that this was because I had the wrong
hibernate version, but I have the latest 3.2 release.

I can generate a database schema fine, So I assume that something else
is wrong



Hibernate version: 3.2.0.cr5

[b]Mapping documents:I use annotations

[b]Code between sessionFactory.openSession() and session.close():


public static Session getSession() {
Session s = threadSession.get();
// Open a new Session, if this thread has none yet
try {
if (s == null) {
if (sessionFactory==null) {
try {
cfg.configure(CONFIG_FILE_LOCATION);
sessionFactory = cfg.buildSessionFactory();
} catch (Exception e) {
System.err
.println("%%%% Error Creating SessionFactory %%%%");
e.printStackTrace();
}
}
s = sessionFactory.openSession();
threadSession.set(s);
}
} catch (HibernateException ex) {
throw new RuntimeException(ex);
}
return s;
}

/**
* closes the Hibernate Session associated with this thread.
* if the session is not open, or has not been created this
* method has no effect.
*/
public static void closeSession() {
try {
Session s = threadSession.get();
threadSession.set(null);
if (s != null && s.isOpen())
s.close();
} catch (HibernateException ex) {
throw new RuntimeException(ex);
}
}


Full stack trace of any exception that occurs:

Here is the error I get and my Configuration file
Dec 30, 2006 10:25:17 AM org.hibernate.cfg.Environment <clinit>
INFO: Hibernate 3.2.0.cr5
Dec 30, 2006 10:25:17 AM org.hibernate.cfg.Environment <clinit>
INFO: hibernate.properties not found
Dec 30, 2006 10:25:17 AM org.hibernate.cfg.Environment
buildBytecodeProvider
INFO: Bytecode provider name : cglib
Dec 30, 2006 10:25:17 AM org.hibernate.cfg.Environment <clinit>
INFO: using JDK 1.4 java.sql.Timestamp handling
Dec 30, 2006 10:25:17 AM org.hibernate.cfg.Configuration configure
INFO: configuring from resource: /hibernate.cfg.xml
Dec 30, 2006 10:25:17 AM org.hibernate.cfg.Configuration
getConfigurationInputStream
INFO: Configuration resource: /hibernate.cfg.xml
Dec 30, 2006 10:25:18 AM org.hibernate.cfg.Configuration addResource
INFO: Reading mappings from resource:
com/stevens/server/domainmodel/Avalibility.java
%%%% Error Creating SessionFactory %%%%
org.hibernate.MappingNotFoundException: resource:
com/stevens/server/domainmodel/Avalibility.java not found
at org.hibernate.cfg.Configuration.addResource(Configuration.java:517)
at
org.hibernate.cfg.Configuration.parseMappingElement(Configuration.java:1511)
at
org.hibernate.cfg.Configuration.parseSessionFactory(Configuration.java:1479)
at
org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1458)
at
org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1432)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1352)
at
com.stevens.server.commons.HibernateUtil.getSession(HibernateUtil.java:59)
at com.stevens.server.MemberManager.addMember(MemberManager.java:27)
at
com.stevens.server.test.MemberManagerTest.testAddMember(MemberManagerTest.java:17)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at junit.framework.TestCase.runTest(TestCase.java:164)
at junit.framework.TestCase.runBare(TestCase.java:130)
at junit.framework.TestResult$1.protect(TestResult.java:110)
at junit.framework.TestResult.runProtected(TestResult.java:128)
at junit.framework.TestResult.run(TestResult.java:113)
at junit.framework.TestCase.run(TestCase.java:120)
at junit.textui.TestRunner.doRun(TestRunner.java:115)
at
com.intellij.rt.execution.junit.IdeaTestRunner.doRun(IdeaTestRunner.java:69)
at junit.textui.TestRunner.doRun(TestRunner.java:108)
at
com.intellij.rt.execution.junit.IdeaTestRunner.startRunnerWithArgs(IdeaTestRunner.java:24)
at
com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:118)
at
com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:40)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:90)

java.lang.NullPointerException
at
com.stevens.server.commons.HibernateUtil.getSession(HibernateUtil.java:67)
at com.stevens.server.MemberManager.addMember(MemberManager.java:27)
at
com.stevens.server.test.MemberManagerTest.testAddMember(MemberManagerTest.java:17)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at
com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:40)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:90)

Process finished with exit code -1


Name and version of the database you are using:

MySQL 5



Problems with Session and transaction handling?

Read this: http://hibernate.org/42.html


And here is my configuration file persistence.xml
<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="workshift">

<!-- A managed datasource provided by the application server, in
this
case the microcontainer, see caveatemptor-beans.xml
definition.
-->

<jta-data-source>java:/caveatemptorTestingDatasource</jta-data-source>

<jar-file>file:///E:/development/perforce/projects/server/workshifts/domainmodel/build/classes</jar-file>

<properties>
<!-- Only scan and detect annotated entities -->
<property name="hibernate.archive.autodetection"
value="class"/>

<!-- Only scan and detect hbm.xml files
<property name="hibernate.archive.autodetection"
value="hbm"/>
-->

<!-- SQL stdout logging
-->
<property name="hibernate.show_sql" value="false"/>
<property name="hibernate.format_sql" value="true"/>
<property name="use_sql_comments" value="true"/>

<!-- We have a JTA data source...
<property name="hibernate.connection.driver_class"
value="org.hsqldb.jdbcDriver"/>
<property name="hibernate.connection.url"
value="jdbc:hsqldb:hsql://localhost"/>
<property name="hibernate.connection.username"
value="sa"/>

<property name="hibernate.c3p0.min_size"
value="5"/>
<property name="hibernate.c3p0.max_size"
value="20"/>
<property name="hibernate.c3p0.timeout"
value="300"/>
<property name="hibernate.c3p0.max_statements"
value="50"/>
<property name="hibernate.c3p0.idle_test_period"
value="3000"/>
-->

<property name="hibernate.dialect"
value="org.hibernate.dialect.MySQL5InnoDBDialect"/>

<!-- Put the EntityManagerFactory into JNDI so we can use it
manually in tests -->
<property name="jboss.entity.manager.factory.jndi.name"

value="java:/EntityManagerFactories/caveatEmptorEMF"/>

<!-- Create the database schema when this test.persistence
unit is deployed, drop
it (clean the database) when it is undeployed
-->
<property name="hibernate.hbm2ddl.auto"
value="create-drop"/>

</properties>
</persistence-unit>

</persistence>


Top
 Profile  
 
 Post subject:
PostPosted: Sun Dec 31, 2006 8:06 am 
Senior
Senior

Joined: Tue Aug 23, 2005 8:52 am
Posts: 181
The resource element in hibernate.cfg.xml should point to a hbm.xml file, Looks like you are using that to load a java file with annotations. Try this instead.
<mapping class="com.stevens.server.domainmodel.Avalibility" />


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.