| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1155 人关注过本帖
标题:hibernate插入SQLSERVER表的问题
只看楼主 加入收藏
zhangyongbo
Rank: 1
等 级:新手上路
帖 子:35
专家分:0
注 册:2007-6-18
收藏
 问题点数:0 回复次数:8 
hibernate插入SQLSERVER表的问题
那位知道如何让myeclispe hibernateDemo读 Microsoft SQL Server user表(自己建的)
那位知道如何让myeclispe hibernateDemo读 Microsoft SQL Server user表(自己建的)

今天我建了一个user表,一运行到 getSession().save(transientInstance);
就报错

log4j:WARN No appenders could be found for logger (dao.UserDAO).
log4j:WARN Please initialize the log4j system properly.
Exception in thread "main" org.hibernate.exception.GenericJDBCException: could not insert: [entity.User]
at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:103)
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:91)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:1986)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2405)
at org.hibernate.action.EntityIdentityInsertAction.execute(EntityIdentityInsertAction.java:37)
at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:248)
at org.hibernate.event.def.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:269)
at org.hibernate.event.def.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:167)
at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:101)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:186)
at org.hibernate.event.def.DefaultSaveEventListener.saveWithGeneratedOrRequestedId(DefaultSaveEventListener.java:33)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:175)
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:530)
at org.hibernate.impl.SessionImpl.save(SessionImpl.java:518)
at org.hibernate.impl.SessionImpl.save(SessionImpl.java:514)
at dao.UserDAO.save(UserDAO.java:33)
at ceshi.asdf.main(asdf.java:16)
Caused by: java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC][SQLServer]在关键字 'user' 附近有语法错误。
at com.microsoft.jdbc.base.BaseExceptions.createException(Unknown Source)
at com.microsoft.jdbc.base.BaseExceptions.getException(Unknown Source)
at com.microsoft.jdbc.sqlserver.tds.TDSRequest.processErrorToken(Unknown Source)
at com.microsoft.jdbc.sqlserver.tds.TDSRequest.processReplyToken(Unknown Source)
at com.microsoft.jdbc.sqlserver.tds.TDSRPCRequest.processReplyToken(Unknown Source)
at com.microsoft.jdbc.sqlserver.tds.TDSRequest.processReply(Unknown Source)
at com.microsoft.jdbc.sqlserver.SQLServerImplStatement.getNextResultType(Unknown Source)
at com.microsoft.jdbc.base.BaseStatement.commonTransitionToState(Unknown Source)
at com.microsoft.jdbc.base.BaseStatement.postImplExecute(Unknown Source)
at com.microsoft.jdbc.base.BasePreparedStatement.postImplExecute(Unknown Source)
at com.microsoft.jdbc.base.BaseStatement.commonExecute(Unknown Source)
at com.microsoft.jdbc.base.BaseStatement.executeInternal(Unknown Source)
at com.microsoft.jdbc.base.BasePreparedStatement.execute(Unknown Source)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:1953)
搜索更多相关主题的帖子: SQLSERVER hibernate 
2007-09-21 11:21
lgdcky
Rank: 2
等 级:论坛游民
威 望:5
帖 子:576
专家分:18
注 册:2006-8-5
收藏
得分:0 

你那个hibernate的配置文件发上来看一下!


2007-09-21 13:41
Gramary
Rank: 4
等 级:贵宾
威 望:13
帖 子:769
专家分:0
注 册:2007-7-9
收藏
得分:0 

Caused by: java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC][SQLServer]在关键字 'user' 附近有语法错误。
这个应该是你配置文件写错了


学编程不能急,要慢慢来。
2007-09-21 15:26
zhangyongbo
Rank: 1
等 级:新手上路
帖 子:35
专家分:0
注 册:2007-6-18
收藏
得分:0 
配置文件
<?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">
<!--
Mapping file autogenerated by MyEclipse Persistence Tools
-->
<hibernate-mapping>
<class name="com.zyb.User" table="User" schema="dbo" catalog="tempdb">
<id name="id" type="java.lang.String">
<column name="ID" length="50" />
<generator class="assigned" />
</id>
<property name="useName" type="java.lang.String">
<column name="useName" length="50" not-null="true" unique="true" />
</property>
<property name="passWord" type="java.lang.String">
<column name="passWord" length="50" not-null="true" />
</property>
<property name="moQuest" type="java.lang.String">
<column name="moQuest" length="50" not-null="true" />
</property>
<property name="noQuest" type="java.lang.String">
<column name="noQuest" length="50" not-null="true" />
</property>
<property name="email" type="java.lang.String">
<column name="email" length="50" not-null="true" />
</property>
</class>
</hibernate-mapping>
2007-09-21 18:44
zhangyongbo
Rank: 1
等 级:新手上路
帖 子:35
专家分:0
注 册:2007-6-18
收藏
得分:0 

POJO 类
package com.zyb;

import java.io.Serializable;

public class User implements Serializable {
private String id;
private String useName;
private String passWord;
private String moQuest;
private String noQuest;
private String email;


public User(){}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getMoQuest() {
return moQuest;
}
public void setMoQuest(String moQuest) {
this.moQuest = moQuest;
}

public String getNoQuest() {
return noQuest;
}
public void setNoQuest(String noQuest) {
this.noQuest = noQuest;
}
public String getPassWord() {
return passWord;
}
public void setPassWord(String passWord) {
this.passWord = passWord;
}
public String getUseName() {
return useName;
}
public void setUseName(String useName) {
this.useName = useName;
}

}

2007-09-21 18:45
lgdcky
Rank: 2
等 级:论坛游民
威 望:5
帖 子:576
专家分:18
注 册:2006-8-5
收藏
得分:0 
把schema="dbo"和catalog="tempdb"删掉看看!

2007-09-21 21:44
zhangyongbo
Rank: 1
等 级:新手上路
帖 子:35
专家分:0
注 册:2007-6-18
收藏
得分:0 
还不行啊
大家没有遇到过这样的问题吗
帮帮我啊
2007-09-22 10:50
lgdcky
Rank: 2
等 级:论坛游民
威 望:5
帖 子:576
专家分:18
注 册:2006-8-5
收藏
得分:0 

你把table=User 改成table=user


2007-09-22 11:30
atsjun
Rank: 1
等 级:新手上路
帖 子:34
专家分:0
注 册:2007-9-8
收藏
得分:0 
可能是表名的问题吧 user是sqlserver的关键字

2007-09-22 13:09
快速回复:hibernate插入SQLSERVER表的问题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.040503 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved