-->
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 in Extremely Simple Annotations Example
PostPosted: Fri Sep 07, 2007 8:39 am 
Newbie

Joined: Fri Sep 07, 2007 8:20 am
Posts: 1
I am at my wit's end trying to use latest Annotations+Core GA -- Why does it give me the following error?
[java] Error: Session Factory Creation Failed: org.hibernate.MappingNotFoundException: resource: learn/MyBean.hbm.xml not found

There is a probably related problem - earlier it was simply not picking up configuration information from src/hibernate.cfg.xml -- i had to finally put it in src/hibernate.properties

all information below
------------------------------------------------------------------------------

[yn@hiba]$ cat hibernate.log
07:39:30,868 INFO Version:15 - Hibernate Annotations 3.3.0.GA
07:39:30,895 INFO Environment:514 - Hibernate 3.2.5
07:39:30,905 INFO Environment:532 - loaded properties from resource hibernate.properties: {hibernate.connection.password=****, hibernate.dialect=org.hibernate.dialect.MySQL5Dialect, hibernate.connection.autoReconnect=true, hibernate.connection.user=yn, hibernate.connection.url=jdbc:mysql://localhost:3306/yn, hibernate.bytecode.use_reflection_optimizer=false, hibernate.connection.driver_class=com.mysql.jdbc.Driver, hibernate.current_session_context_class=thread}
07:39:30,907 INFO Environment:681 - Bytecode provider name : cglib
07:39:30,916 INFO Environment:598 - using JDK 1.4 java.sql.Timestamp handling
07:39:31,033 INFO Configuration:585 - Reading mappings from resource: learn/MyBean.hbm.xml
07:39:31,033 INFO Configuration:530 - Reading mappings from resource: learn/MyBean.hbm.xml

[yn@hiba]$ ls -lR
.:
total 12
-rw-rw-r-- 1 yn yn 1101 Sep 7 07:33 build.xml
drwxrwxr-x 2 yn yn 4096 Sep 7 07:27 lib
drwxrwxr-x 3 yn yn 4096 Sep 7 07:30 src

./lib:
total 4924
-rw-r--r-- 1 yn yn 443432 Sep 7 07:27 antlr-2.7.6.jar
-rw-r--r-- 1 yn yn 16777 Sep 7 07:27 asm-attrs.jar
-rw-r--r-- 1 yn yn 26360 Sep 7 07:27 asm.jar
-rw-r--r-- 1 yn yn 282338 Sep 7 07:27 cglib-2.1.3.jar
-rw-r--r-- 1 yn yn 175426 Sep 7 07:27 commons-collections-2.1.1.jar
-rw-r--r-- 1 yn yn 38015 Sep 7 07:27 commons-logging-1.0.4.jar
-rw-r--r-- 1 yn yn 313898 Sep 7 07:27 dom4j-1.6.1.jar
-rw-r--r-- 1 yn yn 50574 Sep 7 07:27 ejb3-persistence.jar
-rw-r--r-- 1 yn yn 2255753 Sep 7 07:27 hibernate3.jar
-rw-r--r-- 1 yn yn 265130 Sep 7 07:27 hibernate-annotations.jar
-rw-r--r-- 1 yn yn 66426 Sep 7 07:27 hibernate-commons-annotations.jar
-rw-r--r-- 1 yn yn 6727 Sep 7 07:27 jdbc2_0-stdext.jar
-rw-r--r-- 1 yn yn 8812 Sep 7 07:27 jta.jar
-rw-r--r-- 1 yn yn 350627 Sep 7 07:27 log4j-1.2.11.jar
-rw-r--r-- 1 yn yn 536609 Sep 7 07:27 mysql-connector-java-5.0.7-bin.jar
-rw-r--r-- 1 yn yn 123705 Sep 7 07:27 xml-apis.jar

./src:
total 12
-rw-rw-r-- 1 yn yn 329 Sep 7 07:27 hibernate.properties
drwxrwxr-x 2 yn yn 4096 Sep 7 07:32 learn
-rw-r--r-- 1 yn yn 1575 Sep 7 07:27 log4j.properties

./src/learn:
total 8
-rw-rw-r-- 1 yn yn 1056 Sep 7 07:32 Main.java
-rw-rw-r-- 1 yn yn 378 Sep 7 07:32 MyBean.java

[yn@hiba]$ cat src/hibernate.properties
hibernate.connection.driver_class = com.mysql.jdbc.Driver
hibernate.connection.url = jdbc:mysql://localhost:3306/yn
hibernate.connection.user = yn
hibernate.connection.password = *********
hibernate.connection.autoReconnect = true
hibernate.dialect = org.hibernate.dialect.MySQL5Dialect
hibernate.current_session_context_class = thread

[yn@hiba]$ cat src/learn/Main.java
package learn;

import java.util.Date;

public class Main {

public static void main (String argv []) {

org.hibernate.SessionFactory session_factory;
org.hibernate.Session session;
try {
session_factory = new org.hibernate.cfg.AnnotationConfiguration()
.addClass(learn.MyBean.class)
.buildSessionFactory();
} catch (Throwable ex) {
System.err.println("Error: Session Factory Creation Failed: " + ex);
return;
}


MyBean my_bean;

my_bean = new MyBean();
my_bean.setName("Foo");

session = session_factory.openSession();
session.beginTransaction();
session.save(my_bean);
session.getTransaction().commit();

}

}

[yn@hiba]$ cat src/learn/MyBean.java
package learn;

import javax.persistence.*;

@Entity
public class MyBean {

private Long id;
private String name;

public void setId (Long id) {
this.id = id;
}

@Id
public Long getId () {
return this.id;
}

public void setName (String Name) {
this.name = Name;
}

public String getName () {
return this.name;
}

}


[yn@hiba]$ cat build.xml
<project name="hibernate-tutorial" default="compile">

<property name="sourcedir" value="${basedir}/src"/>
<property name="targetdir" value="${basedir}/bin"/>
<property name="librarydir" value="${basedir}/lib"/>

<path id="libraries">
<fileset dir="${librarydir}">
<include name="*.jar"/>
</fileset>
</path>

<target name="clean">
<delete dir="${targetdir}"/>
<delete file="hibernate.log"/>
<mkdir dir="${targetdir}"/>
</target>

<target name="compile" depends="clean, copy-resources">
<javac srcdir="${sourcedir}"
destdir="${targetdir}"
classpathref="libraries"/>
</target>

<target name="copy-resources">
<copy todir="${targetdir}">
<fileset dir="${sourcedir}">
<exclude name="**/*.java"/>
</fileset>
</copy>
</target>

<target name="run" depends="compile">
<java fork="true" classname="learn.Main" classpathref="libraries">
<classpath path="${targetdir}"/>
</java>
</target>

</project>


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 11, 2007 4:21 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Use addAnnotatedClass instead of addClass

_________________
Emmanuel


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.