日期:2014-05-18  浏览次数:20654 次

hibernate的 insert异常
测试类主要如下:
开用的junit,后来直接用的main函数

public class TuserDAOTest {

private static SessionFactory sf;
private static Session session;

@BeforeClass
public static void beforeClass() {
try {
sf = new Configuration().configure().buildSessionFactory();
session = sf.getCurrentSession();
} catch (Exception e) {
// TODO: handle exception
}
}
@AfterClass
public static void afterClass() {
sf.close();
}

public static void main(String[] args) {
sf = new Configuration().configure().buildSessionFactory();
session = sf.getCurrentSession
Tgroup group = new Tgroup();
group.setGroupId(3);
group.setGroupName("group2");
session.beginTransaction();
session.save(group);
session.getTransaction().commit();
}

该配置的都配好了,结果一运行就报如下异常

Hibernate: 
    insert 
    into
        BBS2.1.dbo.tgroup
        (groupName, groupId) 
    values
        (?, ?)
Exception in thread "main" org.hibernate.exception.SQLGrammarException: could not insert: [com.sc.dao.model.Tgroup]
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:90)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2285)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2678)
at org.hibernate.action.EntityInsertAction.execute(EntityInsertAction.java:79)
at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:279)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:263)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:167)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:321)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:50)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1028)
at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:366)
at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:137)

at com.sc.dao.imp.TuserDAOTest.main(TuserDAOTest.java:74)
Caused by: com.microsoft.sqlserver.jdbc.SQLServerException: '.1' 附近有语法错误。
at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDatabaseError(Unknown Source)
at com.microsoft.sqlserver.jdbc.IOBuffer.processPackets(Unknown Source)
at com.microsoft.sqlserver.jdbc.SQLServerStatement.sendExecute(Unknown Source)
at com.microsoft.sqlserver.jdbc.SQLServerStatement.doExecuteUpdate(Unknown Source)
at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.exe