论坛首页 Java企业应用论坛

hibernate 的insert异常

浏览 1893 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
作者 正文
   发表时间:2013-03-22  
测试类主要如下:
开用的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.executeUpdate(Unknown Source)
at org.hibernate.jdbc.NonBatchingBatcher.addToBatch(NonBatchingBatcher.java:46)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2265)
... 11 more
   发表时间:2013-03-23  
   insert
    into
        BBS2.1.dbo.tgroup
        (groupName, groupId)
    values
        (?, ?)

BBS2.1 错了,,你看看你的db 名字
1 请登录后投票
论坛首页 Java企业应用版

跳转论坛:
Global site tag (gtag.js) - Google Analytics