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.javaCode:
/**
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.javaCode:
/**
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.xmlCode:
<?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.xmlCode:
<?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