求教,Hibernate插入数据的问题
想往数据库里插数据,写了个bean配完hibernate.cfg.xml和hbm.xml后测试了下,一排错误,心都碎了。。。
求各位大侠帮小弟我找找哪里出了错,感激不尽啊
-----------------------------------------------
JavaBean-->User-->里面有id,username和password 内容我就复制了,就是些get和set方法
-----------------------------------------------
User.hbm.xml
<?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="pojo.User" table="hao">
<id name="id">
<generator class="native"></generator>
</id>
<property name="username">
<column name="Username"></column>
</property>
<property name="password">
<column name="Upassword"></column>
</property>
</class>
</hibernate-mapping>
-----------------------------------------------
测试类TestU
package test;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;
import org.junit.Test;
import pojo.User;
public class TestU{
@Test
public void Add(){
Configuration configuration=new Configuration().configure();
SessionFactory factory=configuration.buildSessionFactory();
Session session=factory.openSession();
Transaction tx=session.beginTransaction();
User u=new User();
u.setUsername("kasijia");
u.setPassword("1985119");
session.save(u);
tx.commit();
}
}
-----------------------------------------------
org.hibernate.exception.SQLGrammarException: could not insert: [pojo.User]
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:67)
at org.hibernate.exception.
JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.id.insert.AbstractReturningDelegate.performInsert(AbstractReturningDelegate.java:40)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2158)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2638)
at org.hibernate.action.EntityIdentityInsertAction.execute(EntityIdentityInsertAction.java:48)
at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:250)
at org.hibernate.event.def.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:298)
at org.hibernate.event.def.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:181)
at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:107)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:187)
at org.hibernate.event.def.DefaultSaveEventListener.saveWithGeneratedOrRequestedId(DefaultSaveEventListener.java:33)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:172)
at org.hibernate.event.def.DefaultSaveEventListener.performSaveOrUpdate(DefaultSaveEventListener.java:27)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:70)
at org.hibernate.impl.SessionImpl.fireSave(SessionImpl.java:535)
at org.hibernate.impl.SessionImpl.save(SessionImpl.java:523)
at org.hibernate.impl.SessionImpl.save(SessionImpl.java:519)
at test.TestU.Add(TestU.java:21)
at
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)