-->
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.  [ 4 posts ] 
Author Message
 Post subject: org.hibernate.MappingException
PostPosted: Sun Jun 14, 2009 5:36 am 
Newbie

Joined: Sun Jun 14, 2009 3:17 am
Posts: 2
Hi,
I am a Hibernate newbei. I am trying to run the following simple PopulateMessages Program from Apress Book. But getting exception as

log4j:WARN No appenders could be found for logger (org.hibernate.cfg.Environment).
log4j:WARN Please initialize the log4j system properly.
Exception in thread "main" org.hibernate.MappingException: Could not determine type for: String, for columns: [org.hibernate.mapping.Column(m
sg)]
at org.hibernate.mapping.SimpleValue.getType(SimpleValue.java:266)
at org.hibernate.mapping.SimpleValue.isValid(SimpleValue.java:253)
at org.hibernate.mapping.Property.isValid(Property.java:185)
at org.hibernate.mapping.PersistentClass.validate(PersistentClass.java:395)
at org.hibernate.mapping.RootClass.validate(RootClass.java:192)
at org.hibernate.cfg.Configuration.validate(Configuration.java:1021)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1206)
at PopulateMessages.main(PopulateMessages.java:16)


Here is my programming code and xml file

The POJO Class
Message.java


Code:
/**
   The Message POJO Class
**/

public class Message
{
   private String message;
   
   public Message(String message)
   {
      this.message=message;
   }
   Message()
   {
   }
   public String getMessage()
   {
      return this.message;
   }
   public void setMessage(String message)
   {
      this.message=message;
   }
}



PopulateMessages.java
Code:
/**
   The code to create a sample message
**/


import java.util.Date;

import org.hibernate.cfg.Configuration;
import org.hibernate.SessionFactory;
import org.hibernate.Session;

public class PopulateMessages
{
   public static void main(String [] args)
   {
      SessionFactory sessionFactory=new Configuration().configure().buildSessionFactory();
      Session session=sessionFactory.openSession();
      session.beginTransaction();
      
      Message m1=new Message("Hibernated a message on "+new Date());

      session.save(m1);
      session.getTransaction().commit();
      session.close();
   }   
}


hibernate.cfg.xml
Code:
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
   "-//Hibernate/Hibernate Configuration DTD//EN"
   "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">

<hibernate-configuration>
   <session-factory>
      <property name="hibernate.connection.driver_class">
         sun.jdbc.odbc.JdbcOdbcDriver
      </property>
      <property name="hibernate.connection.url">
         jdbc:odbc:hibernate_dsn
      </property>
      <property name="hibernate.connection.pool_size">
         10
      </property>
      <property name="show_sql">
         true
      </property>
      <property name="dialect">
         org.hibernate.dialect.SQLServerDialect
      </property>

      <!--"Import" the Mapping Resources here-->
      <mapping resource="message.hbm.xml"/>
   </session-factory>
</hibernate-configuration>


message.hbm.xml

Code:
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-mapping PUBLIC
   "-//Hibernate/Hibernate-Mapping DTD 3.0//EN"
   "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping>
   <class name="sample.entity.Message" table="Message">
      <id type="int" column="mid">
         <generator class="native"/>
      </id>
      <property name="message" column="msg" type="String"/>
   </class>
</hibernate-mapping>


All these file are in the same folder

Please help

Bye

Arpit


Top
 Profile  
 
 Post subject: Re: org.hibernate.MappingException
PostPosted: Sun Jun 14, 2009 9:06 am 
Beginner
Beginner

Joined: Fri Feb 13, 2009 5:27 am
Posts: 36
Location: India
HI arpitgadle......namaste


write <property name="message" column="msg" type="string"/>
instead of

<property name="message" column="msg" type="String"/>


bye tc

_________________
parag


Top
 Profile  
 
 Post subject: Re: org.hibernate.MappingException
PostPosted: Sun Jun 14, 2009 12:57 pm 
Newbie

Joined: Sun Jun 14, 2009 3:17 am
Posts: 2
Namaste Parag,
Thanks 4 ur reply.
After changing type="String" to type="string" I am getting the following exception

log4j:WARN No appenders could be found for logger (org.hibernate.cfg.Environment).
log4j:WARN Please initialize the log4j system properly.
Exception in thread "main" java.lang.NoClassDefFoundError: net/sf/ehcache/CacheException
at java.lang.Class.getDeclaredConstructors0(Native Method)
at java.lang.Class.privateGetDeclaredConstructors(Unknown Source)
at java.lang.Class.getConstructor0(Unknown Source)
at java.lang.Class.newInstance0(Unknown Source)
at java.lang.Class.newInstance(Unknown Source)
at org.hibernate.cfg.SettingsFactory.createCacheProvider(SettingsFactory.java:346)
at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:220)
at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:1928)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1211)
at PopulateMessages.main(PopulateMessages.java:16)
Caused by: java.lang.ClassNotFoundException: net.sf.ehcache.CacheException
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)
... 10 more

Thanks
Arpit


Top
 Profile  
 
 Post subject: Re: org.hibernate.MappingException
PostPosted: Mon Jun 15, 2009 2:49 am 
Beginner
Beginner

Joined: Fri Feb 13, 2009 5:27 am
Posts: 36
Location: India
this is becoz may be hibernate does not find the path of ur class....(mapping resource...)

or may be jar issiue

include these jar to ur classpath.

"msbase.jar"
"msutil.jar"
"mysql-connector-java-5.1.6-bin.jar"
"antlr-2.7.6.jar"
"asm-all-2.1.jar"
"cglib-2.2_beta1.jar"
"commons-collections.jar"
"commons-logging-api.jar"
"dom4j-1.4.jar"
"hibernate3.jar"
"jta-spec1_0_1.jar"

_________________
parag


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.