I have a simple Object I am trying to persist to a simple table.
This is my DDL,
CREATE TABLE "message"
(
"message_id" integer NOT NULL DEFAULT autoincrement,
"message_text" varchar(50) NOT NULL,
PRIMARY KEY ("message_id"),
)
this is my mapping file named message.hbm.xml,
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>
<class name="com.duneorbit.test.Message" table="message">
<id name="id" column="message_id">
<generator class="increment"/>
</id>
<property name="text" column="message_text"/>
</class>
</hibernate-mapping>
this is my domain object named Message.java,
Code:
package com.duneorbit.test;
public class Message {
private int messageId;
private String messageText;
public Message(){}
public Message(int messageId, String messageText){
this.messageId=messageId;
this.messageText=messageText;
}
public int getId(){
return this.messageId;
}
public void setId(int messageId){
this.messageId=messageId;
}
public String getText(){
return this.messageText;
}
public void setText(String messageText){
this.messageText=messageText;
}
}
this is my hibernate.cfg.xml file,
Code:
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-2.0.dtd">
<hibernate-configuration>
<!--properties-->
<session-factory>
<property name="connection.driver_class">com.sybase.jdbc2.jdbc.SybDriver</property>
<property name="dialect">net.sf.hibernate.dialect.SybaseAywhereDialect</property>
<property name="connection.url">jdbc:sybase:Tds:localhost:2638?ServiceName=stuffed</property>
<property name="connection.username">DBA</property>
<property name="connection.password">SQL</property>
<property name="show_sql">true</property>
<property name="use_outer_join">true</property>
<!--mapping files-->
<mapping resource='com/duneorbit/test/message.hbm.xml'/>
</session-factory>
</hibernate-configuration>
I have a simple HibernateUtil helper class,
Code:
package com.duneorbit.util;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import net.sf.hibernate.HibernateException;
import net.sf.hibernate.Session;
import net.sf.hibernate.SessionFactory;
import net.sf.hibernate.cfg.Configuration;
public class HibernateUtil {
private static Log log = LogFactory.getLog(HibernateUtil.class);
private static final SessionFactory sessionFactory;
static {
Configuration cfg = new Configuration();
try{
sessionFactory = cfg.configure().buildSessionFactory();
}catch(Throwable ex){
log.error(ex);
throw new ExceptionInInitializerError(ex);
}
}
public static Session getSession() throws HibernateException{
return sessionFactory.openSession();
}
}
I run my simple junit test method,
Code:
public void testMessageObject(){
Session session = null;
try{
log.info("Starting HibernateUtil class");
session = HibernateUtil.getSession();
Transaction tx = session.beginTransaction();
Message message = new Message(1,"Test");
session.save(message);
tx.commit();
log.info("Done");
}catch(HibernateException he){
log.error(he);
fail("Test Failed");
}
}
and this error message
09-Sep-2005 15:02:29 net.sf.hibernate.util.JDBCExceptionReporter logExceptions
WARNING: SQL Error: 102, SQLState: 42W04
09-Sep-2005 15:02:29 net.sf.hibernate.util.JDBCExceptionReporter logExceptions
SEVERE: ASA Error -131: Syntax error near 'message' on line 1
09-Sep-2005 15:02:29 test.com.duneorbit.TestMessage testMessageObject
SEVERE: net.sf.hibernate.exception.SQLGrammarException: Could not save object
can anyone help me, I need help.
Thanks inadvance.