Hibernate save Exception [问题点数:20分,结帖人jlj493509534]

Bbs1
本版专家分:32
结帖率 78%
Bbs1
本版专家分:32
Bbs1
本版专家分:32
Bbs5
本版专家分:3938
Bbs1
本版专家分:32
Bbs1
本版专家分:32
Bbs5
本版专家分:3938
Bbs1
本版专家分:32
Bbs1
本版专家分:32
Bbs3
本版专家分:626
Bbs5
本版专家分:3938
Bbs2
本版专家分:405
Bbs3
本版专家分:555
Bbs3
本版专家分:657
Bbs2
本版专家分:298
hibernate executeUpdate 会引起save
代码方法如下rn[code=java]rn @Overridern @Transactionalrn public void <em>save</em>(T pojo) throws ServiceException rn if(pojo.getId() != null && pojo instanceof CmsResource) //对象已存在rn// PropertyFilter propertyFilter = new PropertyFilter();rn// propertyFilter.setCompareClass(CmsResourcePictureSnapshot.class);rn// propertyFilter.setCompareType(PropertyCompareType.EQ);rn// propertyFilter.setPropertyName("cmsResource.id");rn// propertyFilter.setPropertyValue(pojo.getId());rn// //删除旧的图片快照rn// delete(CmsResourcePictureSnapshot.class, propertyFilter);rn this.executeUpdate("delete from CmsResourcePictureSnapshot where cmsResource.id = " + pojo.getId());rn rn //super.<em>save</em>(pojo);rn rn[/code]rn就是一个简单的executeUpdate hql语句,从打印的sql上显示,竟然会引发<em>save</em>,而且打印出的sql是先insert,再delete,这是为什么?
关于hibernatesave问题
session.<em>save</em>(college);rn LogUtil.log.info("check:will to execute tx commit :<em>save</em> college");rn System.out.println("will execute commit");rn tx.commit();rn日志:rnHibernate: insert into COLLEGE (NO, NAME) values (?, ?)rn2008/02/22 16:57:42:671 CST [INFO] LogUitl :----- - check:will to execute tx commit :<em>save</em> collegern为会么在我提交事务前,insert into COLLEGE (NO, NAME) values (?, ?)语句就出来了?rn
Hibernate常用方法之save
Hibernate常用方法之<em>save</em> <em>save</em>方法常用来向数据库插入一条记录,此方法的需要注意的是主键的生成方式,不同的数据库主键的生成方式不能,例如Oracle数据库可以用序列,MySQL数据库用自增长。还需注意的是此方式需手动提交事务。 代码示例: public void <em>save</em>(Admin admin) { //获取Session Session sessi
Hibernate在save的时候出错!
我在SAVE()的时候,报了The user must supply a JDBC connection的EXCEPTION,不是知道是什么原因,都搞了一上午了!应该不是驱动的问题!请大家指教!
关于hibernatesave
我用myeclipse生成的dao类里面的<em>save</em>方法保存数据,为什么我查看数据库发现并没有数据被保存,但是我用findAll方法却可以查询到最后一次保存的数据??小弟初学<em>hibernate</em>相关代码如下rn Customers customer=new Customers();rn customer.setName("Tom");rn customer.setEmail("tom@yahoo.com");rn customer.setPassword("1234");rn customer.setPhone(new Integer(55556666));rn customer.setAddress("Shanghai");rn customer.setSex("M");rn customer.setDescription("I am very honest.");rnrn InputStream in=this.getClass().getResourceAsStream("photo.gif");rn byte[] buffer = new byte[in.available()];rn in.read(buffer);rn customer.setImage(buffer);rn customer.setBirthday(Date.valueOf("1980-05-06"));rn rn CustomersDAO dao= new CustomersDAO();rn dao.<em>save</em>(customer);rnrn List customers=dao.findAll();rn for (Iterator it = customers.iterator(); it.hasNext();) rn printCustomer(context,out,(Customers) it.next());rn
请帮助Hibernate exception
请看以下报错:rnorg.<em>hibernate</em>.MappingException: An association from the table device refers to an unmapped class: intrn at org.<em>hibernate</em>.cfg.Configuration.secondPassCompileForeignKeys(Configuration.java:1134)rn at org.<em>hibernate</em>.cfg.Configuration.secondPassCompile(Configuration.java:1052)rn at org.<em>hibernate</em>.cfg.Configuration.buildSessionFactory(Configuration.java:1168)rn at com.macroview.sztvip.PersistenceUtil.(PersistenceUtil.java:13)rn检查了好几次.sql,.hbm.xml和.java 实在不知道问题出在哪里,请帮忙指正,谢谢。rnDevice.hbm.xmlrnrnrnrn rn rn rn rn rn rn rn rn rn rn rn rn rn rnrnrnDevice.javarnpackage com.macroview.abt;rnpublic class Device rn private int officeId;rn private int deviceId;rn private String deviceName;rn private String deviceSite;rn private String deviceBrand;rn private String deviceType;rn private String deviceModel;rn private String deviceIp;rn private String snmpRo;rn private String snmpRw;rn private String showVer;rn rn public Device() rn rn rn rn public int getOfficeId() rn rn return officeId;rn rn public void setOfficeId(int officeId) rn rn this.officeId = officeId;rn rn public int getDeviceId() rn rn return deviceId;rn rn public void setDeviceId(int deviceId) rn rn this.deviceId = deviceId;rn rn public String getDeviceName() rn rn return deviceName;rn rn public void setDeviceName(String deviceName) rn rn this.deviceName = deviceName;rn rn public String getDeviceSite() rn rn return deviceSite;rn rn public void setDeviceSite(String deviceSite) rn rn this.deviceSite = deviceSite;rn rn public String getDeviceBrand() rn rn return deviceBrand;rn rn public void setDeviceBrand(String deviceBrand) rn rn this.deviceBrand = deviceBrand;rn rn public String getDeviceType() rn rn return deviceType;rn rn public void setDeviceType(String deviceType) rn rn this.deviceType = deviceType;rn rn public String getDeviceModel() rn rn return deviceModel;rn rn public void setDeviceModel(String deviceModel) rn rn this.deviceModel = deviceModel;rn rn public String getDeviceIp() rn rn return deviceIp;rn rn public void setDeviceIp(String deviceIp) rn rn this.deviceIp = deviceIp;rn rn public String getSnmpRo() rn rn return snmpRo;rn rn public void setSnmpRo(String snmpRo) rn rn this.snmpRo = snmpRo;rn rn public String getSnmpRw() rn rn return snmpRw;rn rn public void setSnmpRw(String snmpRw) rn rn this.snmpRw = snmpRw;rn rn public String getShowVer() rn rn return showVer;rn rn public void setShowVer(String showVer) rn rn this.showVer = showVer;rn rnrnrndevice.sqlrnDROP TABLE IF EXISTS `device`;rnCREATE TABLE `device` (rn `office_id` INT(10) UNSIGNED NOT NULL,rn `device_id` INT(10) UNSIGNED NOT NULL,rn `device_name` VARCHAR(45) NOT NULL default '',rn `device_site` VARCHAR(20) NOT NULL default '',rn `device_brand` VARCHAR(20) NOT NULL default '',rn `device_type` VARCHAR(20) NOT NULL default '',rn `device_model` VARCHAR(20) NOT NULL default '',rn `device_ip` VARCHAR(20) NOT NULL default '',rn `snmp_ro` VARCHAR(10) NOT NULL default '',rn `snmp_rw` VARCHAR(10) NOT NULL default '',rn `show_ver` TINYTEXT NOT NULL DEFAULT '',rn PRIMARY KEY (`device_id`),rn KEY `FK_office` (`office_id`),rn CONSTRAINT `FK_office` FOREIGN KEY (`office_id`) REFERENCES `office` (`office_id`) ON DELETE CASCADE ON UPDATE CASCADErn) ENGINE=InnoDB DEFAULT CHARSET=gb2312;
hibernate Date Exception
奇怪最近我用<em>hibernate</em>做项目的时候遇到了一个问题,我用<em>hibernate</em>来建表的时候如果类的属性有时间属性的时候就报错误!怎么回事啊。要怎么映射啊!rn比如rn private String zipCode;rn rn private String contactTel;rn rn private Date date;rnrnrn rn rn rn rnrn 或rn rnrn 也不行rn
one hibernate SQL exception ?
ERROR: org.<em>hibernate</em>.util.JDBCExceptionReporter - Lock wait timeout exceeded; try restarting transactionrnrnrn这种可能是什么情况?
hibernate exception , help me~
java.lang.ClassFormatError: com/mysql/jdbc/MysqlIO (Bad index in constant pool #916)rn java.lang.ClassLoader.defineClass0(Native Method)rn java.lang.ClassLoader.defineClass(ClassLoader.java:509)rn java.security.SecureClassLoader.defineClass(SecureClassLoader.java:123)rn org.apache.catalina.loader.WebappClassLoader.findClassInternal(WebappClassLoader.java:1653)rn org.apache.catalina.loader.WebappClassLoader.findClass(WebappClassLoader.java:883)rn org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1333)rn org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1213)rn java.lang.ClassLoader.loadClassInternal(ClassLoader.java:322)rn com.mysql.jdbc.Connection.createNewIO(Connection.java:1731)rn com.mysql.jdbc.Connection.(Connection.java:562)rn com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:361)rn java.sql.DriverManager.getConnection(DriverManager.java:512)rn java.sql.DriverManager.getConnection(DriverManager.java:140)rn net.sf.<em>hibernate</em>.connection.DriverManagerConnectionProvider.getConnection(DriverManagerConnectionProvider.java:95)rn net.sf.<em>hibernate</em>.cfg.SettingsFactory.buildSettings(SettingsFactory.java:71)rn net.sf.<em>hibernate</em>.cfg.Configuration.buildSettings(Configuration.java:1091)rn net.sf.<em>hibernate</em>.cfg.Configuration.buildSessionFactory(Configuration.java:737)rn cforum.DBTool.CFGetConnection.getSessionFactory(CFGetConnection.java:46)rn cforum.DBTool.UserDB.Reg(UserDB.java:34)rn cforum.struts.Action.user.registerAction.execute(registerAction.java:56)rn org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:484)rn org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:274)rn org.apache.struts.action.ActionServlet.process(ActionServlet.java:1482)rn org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:525)rn javax.servlet.http.HttpServlet.service(HttpServlet.java:763)rn javax.servlet.http.HttpServlet.service(HttpServlet.java:856)rnrn...rnrnwhy ???rn
Hibernate 级联查询 Exception
org.<em>hibernate</em>.persister.entity.AbstractEntityPersister.loadByUniqueKey
多线程调用hibernatesave方法
线程数为50的时候调用<em>save</em>方法执行插入数据库时,没有问题,每个执行时间大约在170毫秒左右rn但是当线程数为100的时候有的线程就会报请求超时,请问这是什么原因rnrn用的是ssh框架
Hibernate 连接 Mysql save()问题
spring_ioc.xmlrn[code=XML]rnrnrnrnrnrnrn rn rn rn rn rn rn rn rn rnrnrn[/code]rn<em>hibernate</em>.cfg.xmlrn[code=XML]rnrnrnrnrnrnrn rn rootrn rn jdbc:mysql://localhost:3306/testrn rn rn org.<em>hibernate</em>.dialect.MySQLDialectrn rn mysqlrn rootrn rn com.mysql.jdbc.Driverrn rn rnrn rnrnrn[/code]rnPOrn[code=Java]rnpackage com.po;rnrn/**rn * User generated by MyEclipse Persistence Toolsrn */rnrnpublic class User implements java.io.Serializable rnrn // Fieldsrnrn private Integer userId;rnrn private String userName;rnrn private String userSex;rnrn private Integer userAge;rnrn // Constructorsrnrn /** default constructor */rn public User() rn rnrn /** minimal constructor */rn public User(String userName) rn this.userName = userName;rn rnrn /** full constructor */rn public User(String userName, String userSex, Integer userAge) rn this.userName = userName;rn this.userSex = userSex;rn this.userAge = userAge;rn rnrn // Property accessorsrnrn public Integer getUserId() rn return this.userId;rn rnrn public void setUserId(Integer userId) rn this.userId = userId;rn rnrn public String getUserName() rn return this.userName;rn rnrn public void setUserName(String userName) rn this.userName = userName;rn rnrn public String getUserSex() rn return this.userSex;rn rnrn public void setUserSex(String userSex) rn this.userSex = userSex;rn rnrn public Integer getUserAge() rn return this.userAge;rn rnrn public void setUserAge(Integer userAge) rn this.userAge = userAge;rn rnrnrn[/code]rnDAO通过Hibernate反转过来的rn[code=Java]rnpackage com.po;rnrnimport java.util.List;rnimport org.apache.commons.logging.Log;rnimport org.apache.commons.logging.LogFactory;rnimport org.<em>hibernate</em>.LockMode;rnimport org.springframework.context.ApplicationContext;rnimport org.springframework.orm.<em>hibernate</em>3.support.HibernateDaoSupport;rnrn/**rn * Data access object (DAO) for domain model class User.rn * rn * @see com.po.Userrn * @author MyEclipse Persistence Toolsrn */rnrnpublic class UserDAO extends HibernateDaoSupport rn private static final Log log = LogFactory.getLog(UserDAO.class);rnrn protected void initDao() rn // do nothingrn rnrn public void <em>save</em>(User transientInstance) rn log.debug("saving User instance");rn try rn getHibernateTemplate().<em>save</em>(transientInstance);rn log.debug("<em>save</em> successful");rn catch (RuntimeException re) rn log.error("<em>save</em> failed", re);rn throw re;rn rn rnrn public void delete(User persistentInstance) rn log.debug("deleting User instance");rn try rn getHibernateTemplate().delete(persistentInstance);rn log.debug("delete successful");rn catch (RuntimeException re) rn log.error("delete failed", re);rn throw re;rn rn rnrn public User findById(java.lang.Integer id) rn log.debug("getting User instance with id: " + id);rn try rn User instance = (User) getHibernateTemplate()rn .get("com.po.User", id);rn return instance;rn catch (RuntimeException re) rn log.error("get failed", re);rn throw re;rn rn rnrn public List findByExample(User instance) rn log.debug("finding User instance by example");rn try rn List results = getHibernateTemplate().findByExample(instance);rn log.debug("find by example successful, result size: "rn + results.size());rn return results;rn catch (RuntimeException re) rn log.error("find by example failed", re);rn throw re;rn rn rnrn public List findByProperty(String propertyName, Object value) rn log.debug("finding User instance with property: " + propertyNamern + ", value: " + value);rn try rn String queryString = "from User as model where model."rn + propertyName + "= ?";rn return getHibernateTemplate().find(queryString, value);rn catch (RuntimeException re) rn log.error("find by property name failed", re);rn throw re;rn rn rnrn public List findAll() rn log.debug("finding all User instances");rn try rn String queryString = "from User";rn return getHibernateTemplate().find(queryString);rn catch (RuntimeException re) rn log.error("find all failed", re);rn throw re;rn rn rnrn public User merge(User detachedInstance) rn log.debug("merging User instance");rn try rn User result = (User) getHibernateTemplate().merge(detachedInstance);rn log.debug("merge successful");rn return result;rn catch (RuntimeException re) rn log.error("merge failed", re);rn throw re;rn rn rnrn public void attachDirty(User instance) rn log.debug("attaching dirty User instance");rn try rn getHibernateTemplate().<em>save</em>OrUpdate(instance);rn log.debug("attach successful");rn catch (RuntimeException re) rn log.error("attach failed", re);rn throw re;rn rn rnrn public void attachClean(User instance) rn log.debug("attaching clean User instance");rn try rn getHibernateTemplate().lock(instance, LockMode.NONE);rn log.debug("attach successful");rn catch (RuntimeException re) rn log.error("attach failed", re);rn throw re;rn rn rnrn public static UserDAO getFromApplicationContext(ApplicationContext ctx) rn return (UserDAO) ctx.getBean("UserDAO");rn rnrn[/code]rnrnrnTestrn[code=Java]rnpackage com.util;rnrnimport org.springframework.context.ApplicationContext;rnimport org.springframework.context.support.ClassPathXmlApplicationContext;rnrnimport com.po.User;rnimport com.po.UserDAO;rnrnpublic class Test rnrn /**rn * @param argsrn */rn public static void main(String[] args) rn rn ApplicationContext app = new ClassPathXmlApplicationContext("spring_ioc.xml");rn UserDAO dao = (UserDAO)app.getBean("UserDAO");rn User user = new User();rn user.setUserName("xiaomaha");rn user.setUserSex("男");rn user.setUserAge(24);rn dao.<em>save</em>(user);rn rnrnrnrn[/code]rnrn我认为我配置没错`用的DAO是通过Hibernate自动生成的看了下代码用的是getHibernateTemplate 所以不需要事物`它的DAO绝对没问题rnrn我运行的时候也不出异常!为什么数据库里没东西!!!!rnrn我Mysql 资料表类型为InnoDB 所以支持事物!rnrn找了半天没找到问题于是我在<em>hibernate</em>.cfg.xml配置文件中加了一句rn[code=XML]true[/code]rn数据库里面就有信息了``但是自动编号变成了6`!!刚好使用了5次`前面的数据去哪儿了?rn请帮我解决下这个问题`我不想用[code=XML]true[/code] rnrn[color=#FF00FF]期盼高手解答我的疑问!!![/color]rn
hibernate 调用save方法出错
public void <em>save</em>(Namecard transientInstance) rn try rn getHibernateTemplate().<em>save</em>(transientInstance);rn catch (RuntimeException re) rn throw re;rn rn rnrn系统不报错,会走到异常。如下:rn public InvocationTargetException(Throwable target) rn super((Throwable)null); // Disallow initCausern this.target = target;rn rn传过来的对象没有错误,就是保存不了是因为什么。
关于hibernatesave和persist方法
有人能说说<em>save</em>和persist的区别么?看了网上一些资料,有种说法是如果在事务边界外调用persist的话,不会执行insert语句。事务边界外具体是什么意思?是代码里面没有tx = session.beginTransaction();和tx.commit();么?我这样试过,但是试的结果是<em>save</em>和persist都不会执行insert语句。
hibernate save和update方法不起作用
rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rnrnrnrnpublic static void main(String[] args) rn // TODO 自动生成方法存根rn Admin admin= new Admin();rn //admin.setAdminId("123");rn rn admin.setPassWord("33");rn ...rn HibernateSessionFactory.currentSession().<em>save</em>(aa);rn HibernateSessionFactory.currentSession().close();rn rn rn 本人初学<em>hibernate</em> 做了个实验就失败了 admin类和映射文件都是myeclipse生成的rn 运行后不报错也不能保存 我还试过可以正常使用load方法 咋回事呢?
hibernate 执行save方法报错
WARN: HHH000409: Using org.<em>hibernate</em>.id.UUIDHexGenerator which does not generate IETF RFC 4122 compliant UUID values; consider using org.<em>hibernate</em>.id.UUIDGenerator instead Exception in thread "main"
关于hibernate的事务save的问题
简化代码是这样子的rnrnSession sess = 初始化session;rnTransaction tr = sess.beginTransaction();rnsess.<em>save</em>(电影类);rnsess.<em>save</em>(电影下面的子类);rnrn由于电影下面的子类需要电影类的id做外键,不过电影类新增的时候为了可以自增,类的id设置是0rnrn结果怎样可以获取新增后的电影类的id可以赋值给电影下面的子类的外键Id?
Hibernate save persist merge探究
NULL 博文链接:https://dreamzhong.iteye.com/blog/1218885
hibernate 中的save,不能保存
高手帮忙啊rn我的ACTION:rn String username=loginForm.getUsername();rn String password=loginForm.getPassword();rn String role=loginForm.getRole();rn String name=loginForm.getName();rn String tele=loginForm.getTele();rn XsxtUser xsxtuser=new XsxtUser();rn xsxtuser.setLogin_id(username);rn xsxtuser.setPsw(password);rn xsxtuser.setRole(role);rn xsxtuser.setName(name);rn xsxtuser.setTele(tele);rn XsxtUserDAO xsxtuserdao=new XsxtUserDAO();rn xsxtuserdao.insertUser(xsxtuser);rn我的xsxtuserdao:rn public class XsxtUserDAO extends BaseHibernateDAO rn public XsxtUserDAO()rn HibernateSessionFactory.beginTransaction();rn rn public void insertUser(XsxtUser xu)rn tryrn Session s=HibernateSessionFactory.getSession();rn s.<em>save</em>(xu);rn System.out.println(xu.getName());//这里能够得到ACTION传进的值rn catch(Exception e)rn System.out.println("aaaaaaa");rn e.printStackTrace();rn rn rnrn事务的提交用的是过滤器,工作正常rn不报错,都正常,就是没数据插进去,
hibernatesave和merg的区别
请问下<em>save</em>是局部更新还是merge是局部更新
Hibernate 使用save方法保存
创建 HibernateSessionFactory.java package cn.util; import org.<em>hibernate</em>.HibernateException; import org.<em>hibernate</em>.cfg.Configuration; import org.<em>hibernate</em>.classic.Session; public class Hiberna...
使用hibernatesave操作无效。
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;中午快吃饭的时候问小弟任务作的怎么样,小弟突然和我说他遇到一个郁闷问题。在使用POI做Excel数据批量导入程序编写的时候,<em>hibernate</em>的<em>save</em>方法无效。但是从Form表单中提取信息做单个保存有效。Eclipse的控制台没有报错信息。 &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp...
拓展-模拟Hibernate的save操作
JDBC(Java Data Base Connectivity,java数据库连接)是一种用于执行SQL语句的Java API,可以为多种关系数据库提供统一访问,它由一组用Java语言编写的类和接口组成。JDBC提供了一种基准,据此可以构建更的工具和接口,使数据库开发人员能够编写数据库应用程序。
关于hibernate最经典的exception
在一次简单的页面UPDATE之前 我想先查询一遍这个对象 结果出现了javax.servlet.ServletException: a different object with the same identifier value was already associated with the session异常 这个主要是因为在一个页面之中已经有一个持久化对象了,但我又去查了一遍,因此在提交...
Exception:Hibernate执行sql没有反应
所写的程序很简单就是搜索一张表中的所有信息。Hibernate也成功的产生了SQL语句,就是每次执行到这个语句程序就停止了。并且没有错误提示。        尝试多种方法未果之后。我就该方法单独提出来,放在在一个页面中。错误提示终于出现了(原来是我程序中的log4j的配置文件没写的原因)。提示数据不匹配。         经核查数据中(Mysql)一个字段为int为了省事没有设为非空。里面存的是...
关于hibernate session Exception的问题
系统给出这样的 Exception rnlog4j:WARN No appenders could be found for logger (org.<em>hibernate</em>.cfg.Environment).rnlog4j:WARN Please initialize the log4j system properly.rnorg.<em>hibernate</em>.InvalidMappingException: Could not parse mapping document from resource User.hbm.xmlrn at org.<em>hibernate</em>.cfg.Configuration.addResource(Configuration.java:616)rn at org.<em>hibernate</em>.cfg.Configuration.parseMappingElement(Configuration.java:1635)rn at org.<em>hibernate</em>.cfg.Configuration.parseSessionFactory(Configuration.java:1603)rn at org.<em>hibernate</em>.cfg.Configuration.doConfigure(Configuration.java:1582)rn at org.<em>hibernate</em>.cfg.Configuration.doConfigure(Configuration.java:1556)rn at org.<em>hibernate</em>.cfg.Configuration.configure(Configuration.java:1476)rn at org.<em>hibernate</em>.cfg.Configuration.configure(Configuration.java:1462)rn at com.action.Test.(Test.java:26)rnCaused by: org.<em>hibernate</em>.InvalidMappingException: Could not parse mapping document from input streamrn at org.<em>hibernate</em>.cfg.Configuration.addInputStream(Configuration.java:555)rn at org.<em>hibernate</em>.cfg.Configuration.addResource(Configuration.java:613)rn ... 7 morernCaused by: org.dom4j.DocumentException: www.<em>hibernate</em>.org Nested <em>exception</em>: www.<em>hibernate</em>.orgrn at org.dom4j.io.SAXReader.read(SAXReader.java:484)rn at org.<em>hibernate</em>.cfg.Configuration.addInputStream(Configuration.java:546)rn ... 8 morernjava.lang.NullPointerExceptionrn at com.action.Test.main(Test.java:79)rnrnrnrnrnrn创建 SessionFactory 和 Session 的几行代码rnrn private static SessionFactory sessionFactory;rn rn staticrn rn sessionFactory = new Configuration().configure().buildSessionFactory();rn rn rn public static Session opens()rn rn Session session = sessionFactory.openSession();rn return session;rn rnrnrnrnrnrnrnrnrnrnrn这是 hbm.xml rnrnrn rnrnrn rn rn rn rn rn rn rn rn rn rn rn rnrnrnrnrnrnrnrn这是 cfg.xmlrnrnrnrnrnrn rn jdbc:mysql://localhost:3306/<em>hibernate</em>rn rootrn rn com.mysql.jdbc.Driverrn org.<em>hibernate</em>.dialect.MySQLDialectrn truern rn rn rnrnrnrnrnrnrn麻烦各位朋友,带小弟看一下,
hibernate exception应该怎样抛出?
![图片说明](https://img-ask.csdn.net/upload/201704/16/1492328822_144667.png)n![图片说明](https://img-ask.csdn.net/upload/201704/16/1492328868_529205.png)n到底该怎么改呢?
hibernate 连续 save 的时候报错事务回滚
下面的<em>save</em>添加的时候一定要注意,上面外键相关的主键有没有,有没有id,如果下面的<em>save</em> ,不是外键,则添加进去为空,为外键,则报错,则不行 ,在service层, 如果直接在action层,则没有报错,但仍需要得到id
hibernatesave发出SQL语句的问题
做了几个小例子发现,当<em>save</em>的时候,如果被<em>save</em>的对象中存在外键字段,那么<em>save</em>之后就会发出这样的语句:rnselect xxx1 from 主键表 where 主键字段=?rninsert into 外键表 (...)value(...)rn也就是说<em>hibernate</em>会将外键字段的值,到主键表中检查一下,然后再添加记录!rnrn如果不希望发出那个多余的select语句怎么弄啊?
在调用hibernatesave保存数据时报错
在保存数据时,报这个错误,查了下,有人说是数据格式问题,可是检查发现数据格式是对应的,不知道到底该如何解决,求高手帮忙…………rnHTTP Status 500 - Unable to show problem report: freemarker.template.TemplateModelException: Method public java.lang.String org.<em>hibernate</em>.<em>exception</em>.NestableRuntimeException.getMessage(int) threw an <em>exception</em> when invoked on org.<em>hibernate</em>.<em>exception</em>.GenericJDBCException: Could not execute JDBC batch update Class: freemarker.ext.beans.SimpleMethodModel File: SimpleMethodModel.java Method: exec Line: 130 - freemarker/ext/beans/SimpleMethodModel.java:130:-1rntype Status reportrnrnmessage Unable to show problem report: freemarker.template.TemplateModelException: Method public java.lang.String org.<em>hibernate</em>.<em>exception</em>.NestableRuntimeException.getMessage(int) threw an <em>exception</em> when invoked on org.<em>hibernate</em>.<em>exception</em>.GenericJDBCException: Could not execute JDBC batch update Class: freemarker.ext.beans.SimpleMethodModel File: SimpleMethodModel.java Method: exec Line: 130 - freemarker/ext/beans/SimpleMethodModel.java:130:-1rnrndescription The server encountered an internal error (Unable to show problem report: freemarker.template.TemplateModelException: Method public java.lang.String org.<em>hibernate</em>.<em>exception</em>.NestableRuntimeException.getMessage(int) threw an <em>exception</em> when invoked on org.<em>hibernate</em>.<em>exception</em>.GenericJDBCException: Could not execute JDBC batch update Class: freemarker.ext.beans.SimpleMethodModel File: SimpleMethodModel.java Method: exec Line: 130 - freemarker/ext/beans/SimpleMethodModel.java:130:-1) that prevented it from fulfilling this request.rn
hibernate生成dao save方法的问题
自动生成的<em>save</em>方法rn一般要改动返回值吗rn例如改为booleanrn方便判断是否保存成功rn如果部改rn如何判断成功?rnException ?rnrn[img=http://m1.img.libdd.com/farm2/165/961564925DCF1012FAB7CBC9096EAEA5_480_480.GIF][/img]rnrn
Hibernate save的时候能自动生成表吗
rn事先还没建表,在测试<em>save</em>方法时能让<em>hibernate</em>帮我自动生成数据库表吗?rn[code=Java]rn@Entityrnpublic class Category rn private int id;rn private String name;rn rn @Idrn @GeneratedValuern public int getId() rn return id;rn rn public void setId(int id) rn this.id = id;rn rn public String getName() rn return name;rn rn public void setName(String name) rn this.name = name;rn rnrn[/code]rn下面是<em>save</em>的测试方法,通过Service层的方法rn[code=Java]rn     @Testrn public void testAdd() rn Category category = new Category();rn category.setName("c1");rn categoryService.add(category);rn rn[/code]rn连接数据库都是交给Spring容器来管理。。。。在测试以上方法时不能自动生成数据表?rnrn[code=Java]rnCaused by: com.mysql.jdbc.<em>exception</em>s.jdbc4.MySQLSyntaxErrorException: Table 't_bbs.category' doesn't existrn[/code]
Hibernate中ManytoMany中save()方法的问题
[code=Java] @Testrn public void testInsertTeacher() rn Student s = new Student();rn s.setAge(20);rn rn Student s1 = new Student();rn s1.setAge(22);rn rn Teacher t = new Teacher();rn t.setName("Xue");rn rn Teacher t2 = new Teacher();rn t2.setName("Han");rn rn t.getStudents().add(s);rn t.getStudents().add(s1);rn t2.getStudents().add(s);rn rn Session session = sf.getCurrentSession();rn session.beginTransaction();rn session.<em>save</em>(t);rn session.<em>save</em>(t2);rn session.getTransaction().commit();rn rn rn rn @Testrn public void testInsertStudent() //Something wrong with this methodrn Student s = new Student();rn s.setAge(20);rn rn Student s1 = new Student();rn s1.setAge(22);rn rn Teacher t = new Teacher();rn t.setName("Xue");rn rn Teacher t2 = new Teacher();rn t2.setName("Han");rn rn s.getTeachers().add(t);rn s1.getTeachers().add(t2);rn rn Session session = sf.getCurrentSession();rn session.beginTransaction();rn session.<em>save</em>(s);rn session.getTransaction().commit();rn [/code]rn这个代买中insertTeacher就没有问题 在<em>save</em>Teacher的同时会在中间表中插入对应的外键连接 但是插入Student的时候就不行 Why?
模拟hibernate save方法的实现过程
<em>hibernate</em>让数据库操作变得简单,很好奇内部的实现过程,所以最近看了一些模拟<em>hibernate</em>实现过程的代码,自己也尝试了下模拟<em>hibernate</em> <em>save</em>方法的实现,当作一个笔记,希望也对大家有帮助。 下面直接po代码吧,注释写的也算清楚,我们要做的就是将用<em>save</em>方法将wife对象存入数据库。 public class Wife { private int id; private
Hibernate 在事务管理下,save之后获取Id的方法
在实体映射文件中id的映射中添加一行 class="increment"/>
Hibernate里save()、update()、saveOrUpdate()、merge()区别?
<em>hibernate</em> 太强大了,一个对数据的持久化都这么多方法,rn小弟不晓得他们之间有什么区别?各位大哥帮忙解解惑。rnrn
关于使用hibernate的session的save()方法的问题
我使用<em>hibernate</em>d中的session的<em>save</em>()方法来向数据库的表中添加新的字段,以此来替代sql语句的添加方法。可是却产生了下面的异常:rn[color=#FF0000]org.<em>hibernate</em>.PropertyValueException: not-null property references a null or transient value: com.wgh.ORM.TbTaoTi.joinTimern at org.<em>hibernate</em>.engine.Nullability.checkNullabilityrn……[/color]rnrn下面是hbm.xml的内容:rn[color=#FF0000]rn rn [/color]rnrn下面是我的代码:rn[color=#FF0000]lesson=(TbLesson)session.get(TbLesson.class, (long)taoTiForm.getLessonId());rn taoti=new TbTaoTi();rn taoti.setName(taoTiForm.getName());rn taoti.setTbLesson(lesson);rn session.<em>save</em>(taoti);[/color]rnrn我知道这里的时间是必须不能为空的,但是在使用纯sql语句进行添加时就因为表中的那个时间字段是使用了getdate()方法的,所以会自动获得,可是我在使用<em>hibernate</em>时这个该怎么弄?
Hibernate 中getSession().save() 保存不到数据库
为什么我的Hibernate 中getSession().<em>save</em>() 保存不到数据库rn我的dao中怎么写的:rn[code="java"]rn /**rn * 保存实体rn */rn public void <em>save</em>(T o) rn getSession().persist(o);rn rn rn[/code]rn我在测试单元这样写的:rn[code="java"]rn @Testrn public void testSave() rn rn ApplicationContext cxt = new ClassPathXmlApplicationContext("/applicationContext.xml");rn buyerService = (BuyerService)cxt.getBean("buyerService");rn rn rn rn rn Buyer buyer = new Buyer("dengmingti","123456","test@sina.com");rn ContactInfo contactInfo = new ContactInfo();rn contactInfo.setAddress("百色市朝阳区左家庄");rn contactInfo.setMobile("13671323507");rn contactInfo.setPhone("010-64469090-9");rn contactInfo.setPostalcode("531500");rn buyer.setContactinfo(contactInfo);rn buyer.setGender("男");rn buyer.setRealname("刘德华");rn buyer.setRegTime(new Date());rn buyerService.<em>save</em>(buyer);rn rn [/code]rnrn在dao中写 Transaction tran=getSession().beginTransaction();rntran.commit();也没有用rnrn如果我的测试单元这样写怎可以保存到数据库中:rn[code="java"]rn protected static ApplicationContext applicationContext = new ClassPathXmlApplicationContext("/applicationContext.xml");rn protected static SessionFactory sessionFactory = (SessionFactory) applicationContext.getBean("sessionFactory");rn rn @Testrn public void testSave() rn Session session = sessionFactory.openSession();rn Transaction tx = session.beginTransaction();rnrn Buyer buyer = new Buyer("dengmingrun","123456","test@sina.com");rn ContactInfo contactInfo = new ContactInfo();rn contactInfo.setAddress("北海市朝阳区左家庄");rn contactInfo.setMobile("13671323507");rn contactInfo.setPhone("010-64469090-9");rn contactInfo.setPostalcode("533000");rn buyer.setContactinfo(contactInfo);rn buyer.setGender("男");rn buyer.setRealname("张学友");rn buyer.setRegTime(new Date());rn rn session.<em>save</em>(buyer);rnrn tx.commit();rn session.close();rn [/code]rnrn我怎样才能使用buyerService.<em>save</em>(buyer);存到数据库中呀?
Hibernate save方法无法保存的问题
最近做项目使用了<em>hibernate</em>,由于对这个框架不是很熟悉,遇到了很多坑。 问题描述: 执行<em>save</em>方法时,不报错,中间表的内容没有被保存到数据库中。 可能原因: 1.实体类没有赋值 debug模式查看,传值没有问题,排除这种原因。 2.没有配置事务或事务没有提交 在代码内手动抛出异常,数据回滚,排除。 苦思冥想找不到错误的原因,几天未果。突然想到要保存的表是一张中间表,关联的表
save
下面这段C程序为何在turboc 2.0下运行时总会异常中断rn请高手们给出一点解释rn注:程序功能是:从一个字符串的任意位置起取若干个字符构成一个串rnrn#include "stdio.h"rnrnchar *mid(char *s,int beg,int count)rnrn char *substr;rn int i;rn if(count>strlen(s))rn return "Error!";rn substr=(char*)malloc(sizeof(char)*(count+1));rn for(i=0;i
关于hibernatesave方法和persist方法的区别
<em>save</em> : 在事务里执行到<em>save</em>,会向数据库插一条数据,如果事务里异常,会回滚,删除数据库中插入的数据。 persist:在事务里执行到persist,不会向数据库插数据,事务commit了才会插入数据。
hibernate save集合时只有一个值
List lists = getList(); List conlists = new ArrayList(); A a = new A(); for(D list:lists){ a.setB(b); a.setC(c); conlists.add(a); } this.<em>save</em>(lists); 这样存到数据库的值只有一个,原因就是 循环里的对象 只有一个a对象,<em>save</em>的时候
求助:Hibernate中的savesaveOrUpdate方法的问题
我在调试的时候发现,用session.<em>save</em>()可以保存新对象,可是我想用<em>save</em>OrUpdate,结果报错:Batch update row count wrong :0. 很奇怪,<em>save</em>OrUpdate不是可以自动判断保存的吗?请高手指点~
Hibernate save()和delete()函数不起作用的问题
这个问题比较初级,但是因为我确实是刚刚接触<em>hibernate</em>,本来只是想利用它的数据库orm功能给自己省点事的,可是发现有一个DAO类中的delete和<em>save</em>方法不起作用rnrn我有两个类似的表,而且更新的方法都是一样的,函数代码都是直接copy改名就行rn但是其中一个表的增删没有问题,另一个表就不行,数据库操作相关代码全都是<em>hibernate</em>自己生成的rnmapping文件也一样,所以应该不是我的代码的问题,而且单步跟踪到<em>save</em>函数里面去的时候,要被保存的对象一切正常。rnrn现在的一个现象是:调用了该DAO类的方法之后,没有例外抛出,log显示<em>save</em> successful,但是数据库里没有新纪录。用其他方法再插入数据后发现自增的id已经不连续。rnrn即插入行为已经使得Mysql的表中id自增,但是数据没有插进去。id已经设置为了identity。rnrn因为开发的机器不能上网,所以没法贴代码,请各位大牛帮我想想可能是啥原因?
hibernatesave方法错误,求助!
Hibernate: insert into TShop.dbo.Collection (UserID, ProductID, TypeID, ProName, NameInfo, Price, Dirnscount, Amount, Hits, DescribeInfo, Picture, Memo) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)rnorg.springframework.dao.InvalidDataAccessApiUsageException: com.sshshop.entity.UserInfo; nested excernption is org.<em>hibernate</em>.TransientObjectException: com.sshshop.entity.UserInfornCaused by: org.<em>hibernate</em>.TransientObjectException: com.sshshop.entity.UserInforn at org.<em>hibernate</em>.engine.ForeignKeys.getEntityIdentifierIfNotUn<em>save</em>d(ForeignKeys.java:216)rn at org.<em>hibernate</em>.type.EntityType.getIdentifier(EntityType.java:108)rn at org.<em>hibernate</em>.type.ManyToOneType.isDirty(ManyToOneType.java:221)rn at org.<em>hibernate</em>.type.TypeFactory.findDirty(TypeFactory.java:476)rn at org.<em>hibernate</em>.persister.entity.AbstractEntityPersister.findDirty(AbstractEntityPersister.java:28rn03)rn at org.<em>hibernate</em>.event.def.DefaultFlushEntityEventListener.dirtyCheck(DefaultFlushEntityEventListenrner.java:467)rn at org.<em>hibernate</em>.event.def.DefaultFlushEntityEventListener.isUpdateNecessary(DefaultFlushEntityEvenrntListener.java:190)rn at org.<em>hibernate</em>.event.def.DefaultFlushEntityEventListener.onFlushEntity(DefaultFlushEntityEventLisrntener.java:113)rn at org.<em>hibernate</em>.event.def.AbstractFlushingEventListener.flushEntities(AbstractFlushingEventListenernr.java:195)rn at org.<em>hibernate</em>.event.def.AbstractFlushingEventListener.flushEverythingToExecutions(AbstractFlushirnngEventListener.java:76)rn at org.<em>hibernate</em>.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:26)rn at org.<em>hibernate</em>.impl.SessionImpl.flush(SessionImpl.java:985)rn at org.<em>hibernate</em>.impl.SessionImpl.managedFlush(SessionImpl.java:333)rn at org.<em>hibernate</em>.transaction.JDBCTransaction.commit(JDBCTransaction.java:106)rn at org.springframework.orm.<em>hibernate</em>3.HibernateTransactionManager.doCommit(HibernateTransactionManarnger.java:578)rn at org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstracrntPlatformTransactionManager.java:662)rn at org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatfornrmTransactionManager.java:632)rn at org.springframework.transaction.interceptor.TransactionAspectSupport.commitTransactionAfterReturrnning(TransactionAspectSupport.java:314)rn at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptorrn.java:116)rn at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.rnjava:171)rn at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)rn at $Proxy68.<em>save</em>Collections(Unknown Source)rn at com.sshshop.biz.impl.CollectionBizImpl.<em>save</em>Collections(CollectionBizImpl.java:70)rn at com.sshshop.struts.action.MyCollectionAction.execute(MyCollectionAction.java:123)rn at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:431)rn at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:236)rn at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196)rn at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:414)rn at javax.servlet.http.HttpServlet.service(HttpServlet.java:690)rn at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)rn at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290rn)rn at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)rn at com.sshshop.filter.MyFilter.doFilter(MyFilter.java:52)rn at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235rn)rn at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)rn at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)rn at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)rn at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)rn at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)rn at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)rn at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:263)rn at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)rn at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:584)rn at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)rn at java.lang.Thread.run(Thread.java:619)rn这个问题如何解决
hibernatesave方法报错找不到表的问题
我用的是struts+spring+<em>hibernate</em>框架,获得列表的时候(find方法)可以正常使用,但是使用<em>save</em>方法保存对象就会报错。rnorg.springframework.jdbc.BadSqlGrammarException: Bad SQL grammar [] in task 'Hibernate operation'; nested <em>exception</em> is jrnava.sql.SQLException: ORA-00942: table or view does not existrnrnjava.sql.SQLException: ORA-00942: table or view does not existrnrn麻烦大家给我帮帮忙,谢谢了
hibernate save() 时 java.sql.SQLException: ORA-02289: 序列不存在
[b]jsp:[/b]rn rn rn 车辆名称:rn rn rn rn rn 项目名称:rn rn rn rn rn rn 厂商rn rn rn rn rn 车型rn rn rn rn rn 类别rn rn rn A类乘用车rn B类乘用车rn 小型乘用车rn MPVrn SUVrn rn rn rn rnrn[b]<em>hibernate</em>: session.<em>save</em>(carInfo);[/b][color=#FF0000]执行到这里时报错如下:[/color]rn[b]报错:[/b]rnorg.<em>hibernate</em>.<em>exception</em>.SQLGrammarException: could not get next sequence valuern at org.<em>hibernate</em>.<em>exception</em>.SQLStateConverter.convert(SQLStateConverter.java:67)rn at org.<em>hibernate</em>.<em>exception</em>.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)rn at org.<em>hibernate</em>.id.SequenceGenerator.generate(SequenceGenerator.java:96)rn at org.<em>hibernate</em>.event.def.AbstractSaveEventListener.<em>save</em>WithGeneratedId(AbstractSaveEventListener.java:99)rn at org.<em>hibernate</em>.event.def.DefaultSaveOrUpdateEventListener.<em>save</em>WithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:187)rn at org.<em>hibernate</em>.event.def.DefaultSaveEventListener.<em>save</em>WithGeneratedOrRequestedId(DefaultSaveEventListener.java:33)rn at org.<em>hibernate</em>.event.def.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:172)rn at org.<em>hibernate</em>.event.def.DefaultSaveEventListener.performSaveOrUpdate(DefaultSaveEventListener.java:27)rn at org.<em>hibernate</em>.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:70)rn at org.<em>hibernate</em>.impl.SessionImpl.fireSave(SessionImpl.java:536)rn at org.<em>hibernate</em>.impl.SessionImpl.<em>save</em>(SessionImpl.java:524)rn at org.<em>hibernate</em>.impl.SessionImpl.<em>save</em>(SessionImpl.java:520)rn at dao.CarInfoDao.addCarInfo(CarInfoDao.java:28)rn at service.CarInfoService.addCarInfo(CarInfoService.java:14)rn at action.CarInfoAction.addCarInfo(CarInfoAction.java:48)rn at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)rn at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)rn at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)rn at java.lang.reflect.Method.invoke(Method.java:606)rn at com.opensymphony.xwork2.DefaultActionInvocation.invokeAction(DefaultActionInvocation.java:452)rn at com.opensymphony.xwork2.DefaultActionInvocation.invokeActionOnly(DefaultActionInvocation.java:291)rn at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:254)rn at com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor.doIntercept(DefaultWorkflowInterceptor.java:176)rn at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)rn at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)rn at com.opensymphony.xwork2.validator.ValidationInterceptor.doIntercept(ValidationInterceptor.java:263)rn at org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor.doIntercept(AnnotationValidationInterceptor.java:68)rn at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)rn at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)rn at com.opensymphony.xwork2.interceptor.ConversionErrorInterceptor.intercept(ConversionErrorInterceptor.java:133)rn at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)rn at com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:207)rn at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)rn at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)rn at com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:207)rn at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)rn at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)rn at com.opensymphony.xwork2.interceptor.StaticParametersInterceptor.intercept(StaticParametersInterceptor.java:190)rn at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)rn at org.apache.struts2.interceptor.MultiselectInterceptor.intercept(MultiselectInterceptor.java:75)rn at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)rn at org.apache.struts2.interceptor.CheckboxInterceptor.intercept(CheckboxInterceptor.java:94)rn at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)rn at org.apache.struts2.interceptor.FileUploadInterceptor.intercept(FileUploadInterceptor.java:243)rn at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)rn at com.opensymphony.xwork2.interceptor.ModelDrivenInterceptor.intercept(ModelDrivenInterceptor.java:100)rn at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)rn at com.opensymphony.xwork2.interceptor.ScopedModelDrivenInterceptor.intercept(ScopedModelDrivenInterceptor.java:141)rn at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)rn at org.apache.struts2.interceptor.debugging.DebuggingInterceptor.intercept(DebuggingInterceptor.java:267)rn at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)rn at com.opensymphony.xwork2.interceptor.ChainingInterceptor.intercept(ChainingInterceptor.java:142)rn at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)rn at com.opensymphony.xwork2.interceptor.PrepareInterceptor.doIntercept(PrepareInterceptor.java:166)rn at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)rn at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)rn at com.opensymphony.xwork2.interceptor.I18nInterceptor.intercept(I18nInterceptor.java:176)rn at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)rn at org.apache.struts2.interceptor.ServletConfigInterceptor.intercept(ServletConfigInterceptor.java:164)rn at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)rn at com.opensymphony.xwork2.interceptor.AliasInterceptor.intercept(AliasInterceptor.java:190)rn at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)rn at com.opensymphony.xwork2.interceptor.ExceptionMappingInterceptor.intercept(ExceptionMappingInterceptor.java:187)rn at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)rn at org.apache.struts2.impl.StrutsActionProxy.execute(StrutsActionProxy.java:52)rn at org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:485)rn at org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:77)rn at org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:91)rn at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)rn at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)rn at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)rn at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)rn at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)rn at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)rn at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)rn at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)rn at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:859)rn at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:602)rn at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)rn at java.lang.Thread.run(Thread.java:745)rnCaused by: java.sql.SQLException: ORA-02289: 序列不存在rnrn at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:112)rn at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:331)rn at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:288)rn at oracle.jdbc.driver.T4C8Oall.receive(T4C8Oall.java:745)rn at oracle.jdbc.driver.T4CPreparedStatement.doOall8(T4CPreparedStatement.java:216)rn at oracle.jdbc.driver.T4CPreparedStatement.executeForDescribe(T4CPreparedStatement.java:810)rn at oracle.jdbc.driver.OracleStatement.executeMaybeDescribe(OracleStatement.java:1039)rn at oracle.jdbc.driver.T4CPreparedStatement.executeMaybeDescribe(T4CPreparedStatement.java:850)rn at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1134)rn at oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java:3339)rn at oracle.jdbc.driver.OraclePreparedStatement.executeQuery(OraclePreparedStatement.java:3384)rn at org.<em>hibernate</em>.id.SequenceGenerator.generate(SequenceGenerator.java:75)rn ... 77 morern哪出问题了,急等,谢谢!!
Hibernate assigned主键save无反应
自己写demo, 使用特定规则的字符串作为主键,generator指定assigned,但是在调用Hibernate <em>save</em>()方法时,不见输出insert语句,也无报错,直接就过了,什么也没发生,请问有知道什么情况的么?
hibernatesave及delete的底层实现是怎样的?
它们最终都调用了Session的<em>save</em>或delete方法,但Session是个接口,这些方法的实现不知道在哪?
hibernate使用save 后rollback不起作用
session=HibernateUtils.getSessionFactory().getCurrentSession();rn trans=session.getTransaction();rn trans.begin();rn session.<em>save</em>(user);rn trans.rollback();rnrn经过调试 发现在session.<em>save</em>(user)时 在数据库中插入了一条数据, 但是在trans.rollback()后数据库中user这条数据还在rnrn<em>hibernate</em>.cfg.xml中的配置是rnthreadrn org.<em>hibernate</em>.transaction.JDBCTransactionFactoryrn falsernrnrnrnrn大家帮帮忙吧
hibernate中dao的save不进数据库
我用dao的<em>save</em>方法,能显示insert语句,就是存不进去,各位大侠帮忙看下.rnrnjavabean配置文件:rn[code=Java]rnrnrnrnrn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rnrnrn[/code]rnrn<em>hibernate</em>配置文件:rnrn[code=Java]rnrnrnrnrnrn rn systemrn rn jdbc:oracle:thin:@166.111.134.26:1521:jadern rn rn org.<em>hibernate</em>.dialect.Oracle9Dialectrn rn oraclern jadern rn oracle.jdbc.driver.OracleDriverrn rn truern rn rn rn rn rn rn rn rn rn rn rn rnrn rnrn[/code]rnrndao里面的<em>save</em>方法:rnrn[code=Java]rnpublic void <em>save</em>(Script transientInstance) rn log.debug("saving Script instance");rn try rn getSession().<em>save</em>(transientInstance);rn getSession().flush();rn getSession().close();rn log.debug("<em>save</em> successful");rn catch (RuntimeException re) rn log.error("<em>save</em> failed", re);rn throw re;rn rn rn[/code]rnrn我的测试代码:[code=Java]rnpublic class test rnrn /**rn * @param argsrn */rn public static void main(String[] args) rn tryrn Script s = new Script();rn s.setName("go");rn new ScriptDAO().<em>save</em>(s);rn List list = new ScriptDAO().findByProperty("name", "go");rn System.out.println(list.size());rn catch(Exception e)rn e.printStackTrace();rn rn rnrnrnrn[/code]rnrn结果输出:rnHibernate: select max(ID) from SCRIPTrnHibernate: insert into SYSTEM.SCRIPT (NAME, DESCRIPTION, TIMES, CREATETIME, CONTENT, DSKENVIRONMENT, RESOLUTION, ID) values (?, ?, ?, ?, ?, ?, ?, ?)rnHibernate: select script0_.ID as ID0_, script0_.NAME as NAME0_, script0_.DESCRIPTION as DESCRIPT3_0_, script0_.TIMES as TIMES0_, script0_.CREATETIME as CREATETIME0_, script0_.CONTENT as CONTENT0_, script0_.DSKENVIRONMENT as DSKENVIR7_0_, script0_.RESOLUTION as RESOLUTION0_ from SYSTEM.SCRIPT script0_ where script0_.NAME=?rn1rnrn
求救hibernate 初级问题。不能save数据
type Exception reportrnrnmessage rnrndescription The server encountered an internal error () that prevented it from fulfilling this request.rnrn<em>exception</em> rnrnjavax.servlet.ServletException: org.<em>hibernate</em>.AssertionFailure: InvocationTargetExceptionrn org.apache.struts.action.RequestProcessor.processException(RequestProcessor.java:523)rn org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:421)rn org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:224)rn org.apache.struts.action.ActionServlet.process(ActionServlet.java:1194)rn org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:432)rn javax.servlet.http.HttpServlet.service(HttpServlet.java:710)rn javax.servlet.http.HttpServlet.service(HttpServlet.java:803)rnrnrnroot cause rnrnorg.<em>hibernate</em>.AssertionFailure: InvocationTargetExceptionrn org.<em>hibernate</em>.util.GetGeneratedKeysHelper.prepareStatement(GetGeneratedKeysHelper.java:49)rn org.<em>hibernate</em>.jdbc.AbstractBatcher.getPreparedStatement(AbstractBatcher.java:389)rn org.<em>hibernate</em>.jdbc.AbstractBatcher.prepareStatement(AbstractBatcher.java:76)rn org.<em>hibernate</em>.persister.entity.BasicEntityPersister.insert(BasicEntityPersister.java:1739)rn org.<em>hibernate</em>.persister.entity.BasicEntityPersister.insert(BasicEntityPersister.java:2178)rn org.<em>hibernate</em>.action.EntityIdentityInsertAction.execute(EntityIdentityInsertAction.java:34)rn org.<em>hibernate</em>.engine.ActionQueue.execute(ActionQueue.java:239)rn org.<em>hibernate</em>.event.def.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:240)rn org.<em>hibernate</em>.event.def.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:160)rn org.<em>hibernate</em>.event.def.AbstractSaveEventListener.<em>save</em>WithGeneratedId(AbstractSaveEventListener.java:95)rn org.<em>hibernate</em>.event.def.DefaultSaveOrUpdateEventListener.<em>save</em>WithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:184)rn org.<em>hibernate</em>.event.def.DefaultSaveEventListener.<em>save</em>WithGeneratedOrRequestedId(DefaultSaveEventListener.java:33)rn org.<em>hibernate</em>.event.def.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:173)rn org.<em>hibernate</em>.event.def.DefaultSaveEventListener.performSaveOrUpdate(DefaultSaveEventListener.java:27)rn org.<em>hibernate</em>.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:69)rn org.<em>hibernate</em>.impl.SessionImpl.<em>save</em>(SessionImpl.java:481)rn org.<em>hibernate</em>.impl.SessionImpl.<em>save</em>(SessionImpl.java:476)rn org.springframework.orm.<em>hibernate</em>3.HibernateTemplate$12.doInHibernate(HibernateTemplate.java:617)rn org.springframework.orm.<em>hibernate</em>3.HibernateTemplate.execute(HibernateTemplate.java:366)rn org.springframework.orm.<em>hibernate</em>3.HibernateTemplate.<em>save</em>(HibernateTemplate.java:614)rn dao.TestDAO.<em>save</em>(TestDAO.java:31)rn service.Service.<em>save</em>(Service.java:27)rn com.ssh.struts.action.LoginAction.execute(LoginAction.java:56)rn org.springframework.web.struts.DelegatingActionProxy.execute(DelegatingActionProxy.java:106)rn org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:419)rn org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:224)rn org.apache.struts.action.ActionServlet.process(ActionServlet.java:1194)rn org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:432)rn javax.servlet.http.HttpServlet.service(HttpServlet.java:710)rn javax.servlet.http.HttpServlet.service(HttpServlet.java:803)rnrn
hibernatesave方法返回出错,急
我在<em>save</em>方法过后直接定义了一个int 保存<em>save</em>后对象的id;rn现在发现<em>save</em>对象后 如果别的对象短时间内<em>save</em> 不论出错回滚与否,都有可能返回对象是之前<em>save</em>的,也就是说,我<em>save</em>1和<em>save</em>2 后,取ID 可能取到一个值,请问这是不是 <em>hibernate</em>的对象池问题,如果不是怎么整,是的话又怎么解决,真心崩溃了,求帮忙。
Hibernate save方法不能插入配置的数据库
用Hibernate做一个简单的登录和注册模块,结果,登录可以成功,注册却一直显示失败,把SQL错误抛出来显示在数据表中未找到对应的字段,但是查看了一晚上的hbm.xml和bean,字段名对应都是对的。后来才发现是还是hbm配置的问题,因为是Hibernate自动生成的,所以他的配置字段里catalog=Hibernate。 catalog应该配对应的那个table的名字,或者将该属性去掉。
Hibernate利用save()方法时报mysql语法错误
在利用<em>hibernate</em>的session.<em>save</em>()方法生成table,并插入数据时,报了如下错误 ERROR: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'O
使用java反射机制简单模拟hibernatesave
实体类:Student.java public class Student { private int id; private String name; private int age; public int getId() { return id; } public void setId(int id) { this.id = id; } ...
Spring、hibernate集成的时候list save的问题
<em>hibernate</em>配置rn[size=13px][code=html]rnrn rn rn rn rn rn rn rn rn rn rn rnrnrnrn rn rn rn rn rn rn rn rn rn[/code][/size]rn类[size=13px][code=java]public class User rnrn private Integer id;rn private String username;rn private String password;rn private List workRecord = new ArrayList();rn ...get setrnrnpublic class WorkRecord rnrn private Integer id;rn private Integer userId;rn private String type;rn private Date dateTime;rn private String address;rn private double lat;rn private double lng;rn private String attachment;rn ...get setrn[/code][/size]rn[size=13px][code=sql]Hibernate: rnselectrn user0_.id as id0_0_,rn user0_.username as username0_0_,rn user0_.password as password0_0_ rnfromrn user user0_ rnwherern user0_.id=?rnHibernate: rninsert rnintorn workrecordrn (type, dateTime, attachment, lat, lng, address, id) rnvaluesrn (?, ?, ?, ?, ?, ?, ?)[/code][/size]rn上面我单独保存WorkRecord为什么出现的insert的sql里没有user_id和record_index,这些字段在数据里都有的
hibernate中session的save,delete方法问题
public class HibernateCoreAPITest rn public static SessionFactory sf;rn rn @BeforeClassrn public static void beforeClass()rn sf = new AnnotationConfiguration().configure().buildSessionFactory();rn rn @AfterClassrn public static void afterClass()rn sf.close();rn rn rn @Testrn public void testTeacherSave()rn Teacher t = new Teacher();rn t.setName("t1");rn t.setTitle("middle");rn t.setMyWifeName("liang");rn t.setBirthDate(new Date());rn rn //Session session = sf.openSession();rn Session session = sf.getCurrentSession();rn session.beginTransaction();rn session.<em>save</em>(t);rn session.getTransaction().commit(); rn rn @Testrn public void testSave2()rn Teacher t = new Teacher();rn t.setName("t3");rn t.setTitle("middle");rn t.setBirthDate(new Date());rn rn Session session = sf.getCurrentSession();rn session.beginTransaction();rn session.<em>save</em>(t);rn System.out.println(t.getId());rn session.getTransaction().commit();rn System.out.println(t.getId());rn rn @Testrn public void testDelete()rn Teacher t = new Teacher();rn t.setName("t1");rn t.setTitle("middle");rn t.setBirthDate(new Date());rn rn Session session = sf.getCurrentSession();rn session.beginTransaction();rn session.<em>save</em>(t);rn System.out.println(t.getId());rn session.getTransaction().commit();rn rn Session session2 = sf.getCurrentSession();rn session2.beginTransaction();rn System.out.println(t.getId());rn session2.delete(t);rn session2.getTransaction().commit();rn rnrn自学<em>hibernate</em>过程中,学习session的<em>save</em>,delete,load等方法,测试代码如上面所示,用Junit单独运行test<em>save</em>()方法,运行正常,查看数据库对应表有一行数据;单独运行test<em>save</em>2(),运行正常,查看数据库对应表也是一行数据,只是test<em>save</em>2的数据替换了test<em>save</em>的数据;屏蔽testdelete();运行整个程序,运行正常,查看数据库表有2行数据,分别是test<em>save</em>()和test<em>save</em>2()的数据;恢复testdelete(),Junit单独运行testdelete(),正常运行,查看数据库表,表为空。如果整个程序运行,即test<em>save</em>()、test<em>save</em>2()、testdelete()一起运行,运行正常,查看数据库表,保持2行数据。rn我想问,怎么test<em>save</em>和test<em>save</em>2分别单独运行,都是一行数据,后面运行的数据会替换原来<em>save</em>的数据,而不是直接增加数据,也就是2行数据;但如果一起运行,就能有2行数据???rn还有,单独运行delete方法怎么一下子删除了2行数据,不是只删除一行数据么?还有,怎么3个方法一起运行,数据仍然是2行???rn求高手解答上面的问题,最好能具体说明这些方法运行过程做了啥,为什么出现我上面的情况!!!
hibernate 能够save delete 但是不能update
如题:<em>hibernate</em> 能够<em>save</em> delete 但是不能update 是怎么回事啊
Hibernate中save真正的执行时刻
知道对于持久态对象,在事务提交时会flush,如果是保存一个瞬时太的或者是更新一个托管太对象的话,真正的执行是在什么时候呢?rn个人感觉由于hibnerate的一级缓存(Session缓存),保存的对象也是先缓存起来,等到事务提交时再一起进行保存吧。是这样吗?否则也不会有<em>hibernate</em>文档上大批量保存时出现的溢出问题了。
java.lang.NullPointerException SSH搭建 hibernate getHibernateTemplate 没法save
HTTP Status 500 - rnrn--------------------------------------------------------------------------------rnrntype Exception reportrnrnmessage rnrndescription The server encountered an internal error () that prevented it from fulfilling this request.rnrn<em>exception</em> rnrnjava.lang.NullPointerExceptionrn UserAction.add(UserAction.java:28)rn sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)rn sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)rn sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)rn java.lang.reflect.Method.invoke(Unknown Source)rn com.opensymphony.xwork2.DefaultActionInvocation.invokeAction(DefaultActionInvocation.java:453)rn com.opensymphony.xwork2.DefaultActionInvocation.invokeActionOnly(DefaultActionInvocation.java:292)rn com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:255)rn org.apache.struts2.interceptor.debugging.DebuggingInterceptor.intercept(DebuggingInterceptor.java:256)rn com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)rn com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor.doIntercept(DefaultWorkflowInterceptor.java:176)rn com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)rn com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)rn com.opensymphony.xwork2.validator.ValidationInterceptor.doIntercept(ValidationInterceptor.java:265)rn org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor.doIntercept(AnnotationValidationInterceptor.java:68)rn com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)rn com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)rn com.opensymphony.xwork2.interceptor.ConversionErrorInterceptor.intercept(ConversionErrorInterceptor.java:138)rn com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)rn com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:211)rn com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)rn com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)rn com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:211)rn com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)rn com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)rn com.opensymphony.xwork2.interceptor.StaticParametersInterceptor.intercept(StaticParametersInterceptor.java:190)rn com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)rn org.apache.struts2.interceptor.MultiselectInterceptor.intercept(MultiselectInterceptor.java:75)rn com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)rn org.apache.struts2.interceptor.CheckboxInterceptor.intercept(CheckboxInterceptor.java:90)rn com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)rnrnrnrn hello.jsp 里 action为useradd.action 转到useraction类存储user实体类时,调用getHibernateTemplate().<em>save</em>OrUpdate(user);出错 查了很久了,大家谁能帮下啊 rntomcat6.0 + jdk1.6 + eclipsernrn--------------------librn[img=http://imgsrc.baidu.com/forum/pic/item/08f790529822720e3f3ddb547bcb0a46f31faba8.jpg][/img]rn[img=http://imgsrc.baidu.com/forum/pic/item/730e0cf3d7ca7bcb3c88fe81be096b63f724a8a8.jpg][/img]rn[img=http://imgsrc.baidu.com/forum/pic/item/3c6d55fbb2fb431646ec43d420a4462308f7d3a8.jpg][/img]rn--------------------项目rn[img=http://imgsrc.baidu.com/forum/pic/item/08f790529822720e3f5fdb547bcb0a46f31fab8e.jpg][/img]rnrnrn附代码:rn------------applicationContext.xml (数据源 跟 spring中集成<em>hibernate</em>)rnrnrn rn rn rn rn rn rnrn rn rn rn rn Userrn rn rn rn rn org.<em>hibernate</em>.dialect.MySQLDialectrn rn rn rnrn rn rn rn rn--------------------UserAction.java (存储数据类)rnimport org.springframework.orm.<em>hibernate</em>3.support.HibernateDaoSupport;rnrnrnpublic class UserAction extends HibernateDaoSupport rn public void add() rn User user = new User();rn user.setName("aa");rn user.setAddress("beijing");rn user.setAge("11");rn getHibernateTemplate().<em>save</em>OrUpdate(user);rn rnrn--------------------------User.java (实体类)rnimport javax.persistence.Entity;rnimport javax.persistence.Id;rnimport javax.persistence.Table;rn@Entityrn@Table(name = "user")rnpublic class User rn @Idrn public String name;rn public String age;rn public String address;rn public String getName() rn return name;rn rn public void setName(String name) rn this.name = name;rn rn public String getAge() rn return age;rn rn public void setAge(String age) rn this.age = age;rn rn public String getAddress() rn return address;rn rn public void setAddress(String address) rn this.address = address;rn rnrnrn-------------------------web.xmlrnrnrn SSH0701rnrn rn rn struts2 rn rn org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter rn rn rn rn struts2 rn /* rn rn rn rn rn contextConfigLocation rn /WEB-INF/applicationContext.xml rn rn rn rn org.springframework.web.context.ContextLoaderListener rn rn rnrn----------------------struts.xmlrn rn rn rn rn rn OK.jsp rn rn rn rn----------------------hello.jsprnrnrnrnrn rn Insert title herernrnrn rn rn rnrnrnrn---------------------
hibernatesave的时候发update语句
[code=java]rn SessionFactory sessionFactory=HibernateUtil.getSessionFactory();rn Session session=sessionFactory.getCurrentSession();rn Student s = new Student();rn s.setName("zt1");rn s.setPassword("111111");rn Transaction t = session.beginTransaction();rn session.<em>save</em>(s);rn //s.setName("zt3");此时只发insertrn t.commit();rn[/code]rn控制台打印:Hibernate: insert into Student (name, password) values (?, ?)rn把注释解开后rn[code=java]rn SessionFactory sessionFactory=HibernateUtil.getSessionFactory();rn Session session=sessionFactory.getCurrentSession();rn Student s = new Student();rn s.setName("zt1");rn s.setPassword("111111");rn Transaction t = session.beginTransaction();rn session.<em>save</em>(s);rn s.setName("zt3");//此时发insert后还有updatern t.commit();rn[/code]rn控制台打印:rnHibernate: insert into Student (name, password) values (?, ?)rnHibernate: update Student set name=?, password=? where id=?rn我是这么想的:一个对象在刚new出来的时候是Transient,<em>save</em>之后是Persistent,rncommit之后Detached。Detached时,对象跟数据库没有联系,如果对象修改,需要update,变为Persistent,这时会发update语句。rn我代码里的对象s在session还没有提交事务的时候修改s的name,为何还发update语句?
JUnit测试 Hibernate的save等操作,设置事务回滚的?
如题,我测试完,数据库怎么会有数据,Junit下默认不是rnrn自动回滚吗?怎么设置?rnrn再现等待!!!
求助Sping、hibernate中的save方法
自己写了一个注册页面,在dao中使用<em>save</em>方法怎样去判断是否insert成功,如果用boolean怎么去用
hibernate.Mapping异常Exception">学习hibernate报:Exception in thread "main" org.hibernate.Mapping异常Exception
最近自学<em>hibernate</em>框架,J2SE项目+ORACLE数据库,报出下面异常,求解决:rnrnrnException in thread "main" org.<em>hibernate</em>.MappingException: Could not get constructor for org.<em>hibernate</em>.persister.entity.SingleTableEntityPersisterrn at org.<em>hibernate</em>.persister.internal.PersisterFactoryImpl.create(PersisterFactoryImpl.java:185)rn at org.<em>hibernate</em>.persister.internal.PersisterFactoryImpl.createEntityPersister(PersisterFactoryImpl.java:135)rn at org.<em>hibernate</em>.internal.SessionFactoryImpl.(SessionFactoryImpl.java:384)rn at org.<em>hibernate</em>.cfg.Configuration.buildSessionFactory(Configuration.java:1740)rn at org.<em>hibernate</em>.cfg.Configuration.buildSessionFactory(Configuration.java:1778)rn at com.hsp.view.TestMain.addEmployee(TestMain.java:45)rn at com.hsp.view.TestMain.main(TestMain.java:37)rnCaused by: org.<em>hibernate</em>.HibernateException: Unable to instantiate default tuplizer [org.<em>hibernate</em>.tuple.entity.PojoEntityTuplizer]rn at org.<em>hibernate</em>.tuple.entity.EntityTuplizerFactory.constructTuplizer(EntityTuplizerFactory.java:138)rn at org.<em>hibernate</em>.tuple.entity.EntityTuplizerFactory.constructDefaultTuplizer(EntityTuplizerFactory.java:188)rn at org.<em>hibernate</em>.tuple.entity.EntityMetamodel.(EntityMetamodel.java:341)rn at org.<em>hibernate</em>.persister.entity.AbstractEntityPersister.(AbstractEntityPersister.java:503)rn at org.<em>hibernate</em>.persister.entity.SingleTableEntityPersister.(SingleTableEntityPersister.java:144)rn at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)rn at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)rn at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)rn at java.lang.reflect.Constructor.newInstance(Constructor.java:513)rn at org.<em>hibernate</em>.persister.internal.PersisterFactoryImpl.create(PersisterFactoryImpl.java:163)rn ... 6 morernCaused by: java.lang.reflect.InvocationTargetExceptionrn at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)rn at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)rn at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)rn at java.lang.reflect.Constructor.newInstance(Constructor.java:513)rn at org.<em>hibernate</em>.tuple.entity.EntityTuplizerFactory.constructTuplizer(EntityTuplizerFactory.java:135)rn ... 15 morernCaused by: org.<em>hibernate</em>.PropertyNotFoundException: Could not find a getter for hirenate in class com.hsp.domain.Employeern at org.<em>hibernate</em>.property.BasicPropertyAccessor.createGetter(BasicPropertyAccessor.java:316)rn at org.<em>hibernate</em>.property.BasicPropertyAccessor.getGetter(BasicPropertyAccessor.java:310)rn at org.<em>hibernate</em>.mapping.Property.getGetter(Property.java:320)rn at org.<em>hibernate</em>.tuple.entity.PojoEntityTuplizer.buildPropertyGetter(PojoEntityTuplizer.java:436)rn at org.<em>hibernate</em>.tuple.entity.AbstractEntityTuplizer.(AbstractEntityTuplizer.java:200)rn at org.<em>hibernate</em>.tuple.entity.PojoEntityTuplizer.(PojoEntityTuplizer.java:82)rn ... 20 morern
hibernate+spring save的时候为什么报nested exception is org.hibernate.MappingException:
org.springframework.orm.<em>hibernate</em>3.HibernateSystemException: Unknown entity: com.setecusa.<em>hibernate</em>.tblinventorylog.Tblinventorylog; nested <em>exception</em> is org.<em>hibernate</em>.MappingException: Unknown entity: com.setecusa.<em>hibernate</em>.tblinventorylog.Tblinventorylogrnrnrn//-----这是配置文件---rnrnrnrnrn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rnrnrnrn我没发现哪里配错了呀。这是什么原因。。。急,,,,卡一天了。
如何实现SAVE和SAVE AS的效果
如何用VC++实现SAVE、SAVE AS的效果,如果能有源代码那就最好rnzhuzhengzhou@163.com
hibernateexception:could not instantiate id generator
could not instantiate id generatorrnrndialect does not support sequescesrn我的hbm是rnrnrnrnrn数据库是sqlserver,对应的id属性是char 64rnrn究竟哪里出错了呢?谢谢大家
nested exception is java.lang.NoClassDefFoundError: org/hibernate/MappingExcepti
[code=Java]rnpackage com.sj.persistence.daornorg.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [com/sj/applicationContext.xml]: Invocation of init method failed; nested <em>exception</em> is java.lang.NoClassDefFoundError: org/<em>hibernate</em>/MappingExceptionrn at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1403)rn at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:513)rn at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:450)rn at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:290)rn at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)rn at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:287)rn at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:189)rn at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:545)rn at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:871)rn at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:423)rn at org.springframework.context.support.ClassPathXmlApplicationContext.(ClassPathXmlApplicationContext.java:139)rn at org.springframework.context.support.ClassPathXmlApplicationContext.(ClassPathXmlApplicationContext.java:83)rn at persistence.dao.CustomerDaoTest.setUpBeforeClass(CustomerDaoTest.java:20)rn at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)rn at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)rn at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)rn at java.lang.reflect.Method.invoke(Method.java:597)rn at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)rn at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)rn at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)rn at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:27)rn at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)rn at org.junit.runners.ParentRunner.run(ParentRunner.java:220)rn at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:46)rn at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)rn at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)rn at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)rn at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)rn at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)rnCaused by: java.lang.NoClassDefFoundError: org/<em>hibernate</em>/MappingExceptionrn at org.<em>hibernate</em>.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:124)rn at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:83)rn at org.springframework.orm.jpa.LocalEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalEntityManagerFactoryBean.java:92)rn at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:308)rn at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1460)rn at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1400)rn ... 28 morernCaused by: java.lang.ClassNotFoundException: org.<em>hibernate</em>.MappingExceptionrn at java.net.URLClassLoader$1.run(URLClassLoader.java:200)rn at java.security.AccessController.doPrivileged(Native Method)rn at java.net.URLClassLoader.findClass(URLClassLoader.java:188)rn at java.lang.ClassLoader.loadClass(ClassLoader.java:307)rn at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)rn at java.lang.ClassLoader.loadClass(ClassLoader.java:252)rn at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)rn ... 34 morernrn[/code]rnrn谁能帮看看啊!这个异常是怎么回事rn哪里出事了?
hibernate中Exception in thread "main" java.lang.ExceptionInInitializerError错误
晚上用马士兵的<em>hibernate</em>练习项目做了一个导入,但是一直报slf4j错误,后根据视频把jar包引入,rn但是又出现了以下错误:rn[code=Java]rnSLF4J: Class path contains multiple SLF4J bindings.rnSLF4J: Found binding in [jar:file:/D:/Jar%20Package/slf4j-1.6.4/slf4j-log4j12-1.6.4.jar!/org/slf4j/impl/StaticLoggerBinder.class]rnSLF4J: Found binding in [jar:file:/D:/Jar%20Package/slf4j-1.6.4/slf4j-nop-1.6.4.jar!/org/slf4j/impl/StaticLoggerBinder.class]rnSLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.rnException in thread "main" java.lang.ExceptionInInitializerErrorrn at org.<em>hibernate</em>.cfg.Configuration.reset(Configuration.java:217)rn at org.<em>hibernate</em>.cfg.AnnotationConfiguration.reset(AnnotationConfiguration.java:233)rn at org.<em>hibernate</em>.cfg.Configuration.(Configuration.java:197)rn at org.<em>hibernate</em>.cfg.Configuration.(Configuration.java:201)rn at org.<em>hibernate</em>.cfg.AnnotationConfiguration.(AnnotationConfiguration.java:108)rn at com.bjsxt.<em>hibernate</em>.HibernateQLTest.beforeClass(HibernateQLTest.java:21)rn at com.bjsxt.<em>hibernate</em>.HibernateQLTest.main(HibernateQLTest.java:367)rnCaused by: java.lang.NullPointerExceptionrn at org.<em>hibernate</em>.util.ConfigHelper.getResourceAsStream(ConfigHelper.java:167)rn at org.<em>hibernate</em>.cfg.Environment.(Environment.java:575)rn ... 7 morernrn[/code]rnrn真是不知道少了哪个包,很讨厌这种小错误,浪费了一晚上,请朋友们帮分析下。谢谢
Hibernate抛出的Exception in thread "main" java.lang.NoSuchMethodError
我的hql语句如下:rn[code=Java]rnString queryString = "select w.*,u.unitsName,s.sectorName,st.statusName from WorkersInfo w,UnitsInfo u,SectorInfo s,StatusInfo st where w.unitsId = u.unitsCode and w.sectorId = s.sectorCode and w.statusInfo.statusId = st.statusId";rn[/code]rn执行该hql语句的程序如下:rn[code=Java]rnQuery queryObject = session.createQuery(queryString);rnqueryObject.setFirstResult(pageBean.getFirstRow());rnqueryObject.setMaxResults(pageBean.getMaxSize());rnreturn queryObject.list();rn[/code]rn结果抛出了如下异常:rn[code=Java]rnException in thread "main" java.lang.NoSuchMethodError: org.<em>hibernate</em>.hql.antlr.HqlBaseParser.recover(Lantlr/RecognitionException;Lantlr/collections/impl/BitSet;)Vrn at org.<em>hibernate</em>.hql.antlr.HqlBaseParser.atom(HqlBaseParser.java:3533)rn at org.<em>hibernate</em>.hql.antlr.HqlBaseParser.unaryExpression(HqlBaseParser.java:3200)rn at org.<em>hibernate</em>.hql.antlr.HqlBaseParser.multiplyExpression(HqlBaseParser.java:3082)rn at org.<em>hibernate</em>.hql.antlr.HqlBaseParser.additiveExpression(HqlBaseParser.java:2802)rn at org.<em>hibernate</em>.hql.antlr.HqlBaseParser.concatenation(HqlBaseParser.java:570)rn at org.<em>hibernate</em>.hql.antlr.HqlBaseParser.relationalExpression(HqlBaseParser.java:2586)rn at org.<em>hibernate</em>.hql.antlr.HqlBaseParser.equalityExpression(HqlBaseParser.java:2449)rn at org.<em>hibernate</em>.hql.antlr.HqlBaseParser.negatedExpression(HqlBaseParser.java:2413)rn at org.<em>hibernate</em>.hql.antlr.HqlBaseParser.logicalAndExpression(HqlBaseParser.java:2331)rn at org.<em>hibernate</em>.hql.antlr.HqlBaseParser.logicalOrExpression(HqlBaseParser.java:2296)rn at org.<em>hibernate</em>.hql.antlr.HqlBaseParser.expression(HqlBaseParser.java:2082)rn at org.<em>hibernate</em>.hql.antlr.HqlBaseParser.aliasedExpression(HqlBaseParser.java:2249)rn at org.<em>hibernate</em>.hql.antlr.HqlBaseParser.selectedPropertiesList(HqlBaseParser.java:1455)rn at org.<em>hibernate</em>.hql.antlr.HqlBaseParser.selectClause(HqlBaseParser.java:1365)rn at org.<em>hibernate</em>.hql.antlr.HqlBaseParser.selectFrom(HqlBaseParser.java:1106)rn at org.<em>hibernate</em>.hql.antlr.HqlBaseParser.queryRule(HqlBaseParser.java:702)rn at org.<em>hibernate</em>.hql.antlr.HqlBaseParser.selectStatement(HqlBaseParser.java:296)rn at org.<em>hibernate</em>.hql.antlr.HqlBaseParser.statement(HqlBaseParser.java:159)rn at org.<em>hibernate</em>.hql.ast.QueryTranslatorImpl.parse(QueryTranslatorImpl.java:238)rn at org.<em>hibernate</em>.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:155)rn at org.<em>hibernate</em>.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:109)rn at org.<em>hibernate</em>.engine.query.HQLQueryPlan.(HQLQueryPlan.java:75)rn at org.<em>hibernate</em>.engine.query.HQLQueryPlan.(HQLQueryPlan.java:54)rn at org.<em>hibernate</em>.engine.query.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:71)rn at org.<em>hibernate</em>.impl.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:133)rn at org.<em>hibernate</em>.impl.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:112)rn at org.<em>hibernate</em>.impl.SessionImpl.createQuery(SessionImpl.java:1583)rn at org.qpyong.emp.dao.WorkersInfoDAO.findByPropertyForEmployee(WorkersInfoDAO.java:159)rn at org.qpyong.emp.dao.WorkersInfoDAO.main(WorkersInfoDAO.java:272)rn[/code]rn但是我执行rnselect count(*) from WorkersInfo w,UnitsInfo u,SectorInfo s,StatusInfo st where w.unitsId = u.unitsCode and w.sectorId = s.sectorCode and w.statusInfo.statusId = st.statusId这个语句却是正常的。rn有哪为高手指点指点下?
hibernate Unhandled Exception thrown: class java.l
在通过<em>hibernate</em>访问数据库时,报错如下:rnWARN action.RequestProcessor - Unhandled Exception thrown: class java.lang.NullPointerExceptionrn大概是什么原因呢?n[b]问题补充:[/b]n是查询的时候,调用查询方法时直接报这个错。rn文件配置应该没有问题。n[b]问题补充:[/b]n这是全部的错误提示:rn25609 [http-8888-1] WARN action.RequestProcessor - Unhandled Exception thrown: class java.lang.NullPointerExceptionrn2008-8-14 14:48:17 org.apache.catalina.core.StandardWrapperValve invokern严重: Servlet.service() for servlet action threw <em>exception</em>rnjava.lang.NullPointerExceptionrn at com.afa.struts.action.Test1Action.execute(Test1Action.java:19)rn at org.springframework.web.struts.DelegatingActionProxy.execute(DelegatingActionProxy.java:106)rn at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:484)rn at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:274)rn at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1482)rn at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:507)rn at javax.servlet.http.HttpServlet.service(HttpServlet.java:690)rn at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)rn at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)rn at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)rn at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)rn at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)rn at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)rn at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)rn at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)rn at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:263)rn at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)rn at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:584)rn at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)rn at java.lang.Thread.run(Unknown Source)rnrn我的访问数据库的方法如下:rnpublic List findAll(Class clazz) rn try rn return this.getHibernateTemplate().find(" from " + clazz.getName());rn catch (DataAccessException e) rn // TODO Auto-generated catch blockrn e.printStackTrace();rnSystem.out.println("e "+e.getMessage()); rn rn return null;rn rn调用该方法时参数类是通过<em>hibernate</em>映射而成的。rn我怀疑是不是没有通过<em>hibernate</em>得到对象?n[b]问题补充:[/b]n这是action的execute方法:rnpublic ActionForward execute(ActionMapping mapping, ActionForm arg1, HttpServletRequest arg2, HttpServletResponse arg3) throws Exception rn System.out.println("action!");rn ComDaoIMPL comservice=new ComDaoIMPL();rn comservice.findAll(Test.class); return mapping.findForward("test1");rn rn这是ComServiceIMPL方法:rnpublic class ComServiceIMPL implements IComService rn Comdao comdaoimpl;rn public Comdao getComdaoimpl() rn return comdaoimpl;rn rn public void setComdaoimpl(Comdao comdaoimpl) rn this.comdaoimpl = comdaoimpl;rn rn public List findAll(Class clazz) rn return this.comdaoimpl.findAll(clazz);rn rnrn其中comdaoimpl是通过spring依赖注入的:rnrn rn rn rn rn其中comDao对应的方法是:rnpublic List findAll(Class clazz) rn try rn return this.getHibernateTemplate().find(" from " + clazz.getName());rn catch (DataAccessException e) rn // TODO Auto-generated catch blockrn e.printStackTrace();rnSystem.out.println("e "+e.getMessage()); rn rn return null;rn rn不知道问题出在哪个环节上了。n[b]问题补充:[/b]n这是spring ,hibernat配置文件 spring-config.xmlrnrnrnrnrn rn com.microsoft.jdbc.sqlserver.SQLServerDriverrn rn rn jdbc:microsoft:sqlserver://192.168.0.7:1433;DatabaseName=dsltxsalaryrn rn rn rn 5 rn 10 rn 60 rn 50 rn true rn sarn rn rn rn rn rn rn rn rn rn rn org.<em>hibernate</em>.dialect.SQLServerDialectrn truern rn rn rn rn classpath*:com/afa/auto/*.hbm.xmlrn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn PROPAGATION_REQUIRED,-InfoObjectExceptionrn PROPAGATION_REQUIRED,-InfoObjectExceptionrn PROPAGATION_REQUIRED,-InfoObjectExceptionrn PROPAGATION_REQUIRED,readOnly,-InfoObjectExceptionrn PROPAGATION_REQUIRED,readOnly,-InfoObjectException rn PROPAGATION_REQUIRED,readOnly,-InfoObjectException rn rn rn rnrn rn rn rn rn rn rn rn rnrnrnrn这是spring actionrnrn rn rnrn这是struts actionrnrn rn rn我将那一句注释掉还是老毛病,快晕死了,是不是<em>hibernate</em>的部署有问题?n[b]问题补充:[/b]n在这里注入的:rn rn rn rn rn rnrn其他action 都继承BaseActionn[b]问题补充:[/b]n折磨了我将近一周的问题就在忘记了继承baseAction的这个配置。rn疯了。rn十分感谢小疯子的帮助。
hibernate报错Exception in thread "main" java.lang.ExceptionInInitializerError
<em>hibernate</em>.cfg.xml(放在src下面)rnrnrnrnrnrnrn rnrn rn com.mysql.jdbc.Driverrn jdbc:mysql://localhost:3306/<em>hibernate</em>rn rootrn rootrnrn rn 1rnrn rn org.<em>hibernate</em>.dialect.MySQLDialectrnrn rn threadrnrn rn org.<em>hibernate</em>.cache.NoCacheProviderrnrn rn truernrn rn create rnrn rn rn rnrnrnrnrnrnTest.javarnrnrnpackage com.bjsxt.<em>hibernate</em>;rnrnimport org.<em>hibernate</em>.Session;rnimport org.<em>hibernate</em>.SessionFactory;rnimport org.<em>hibernate</em>.cfg.Configuration;rnrnpublic class Test rn public static void main(String[] args) rn Student s = new Student();rn s.setId(1);rn s.setName("zhangsan");rn s.setAge(8);rn rn SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();rn Session session = sessionFactory.getCurrentSession();rn session.beginTransaction();rn session.<em>save</em>(s);rn session.getTransaction().commit();rn rn rnrnrn报错信息rnException in thread "main" java.lang.ExceptionInInitializerErrorrn at com.bjsxt.<em>hibernate</em>.Test.main(Test.java:14)rnCaused by: java.lang.NullPointerExceptionrn at org.slf4j.LoggerFactory.singleImplementationSanityCheck(LoggerFactory.java:192)rn at org.slf4j.LoggerFactory.performInitialization(LoggerFactory.java:113)rn at org.slf4j.LoggerFactory.getILoggerFactory(LoggerFactory.java:269)rn at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:242)rn at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:255)rn at org.<em>hibernate</em>.cfg.Configuration.(Configuration.java:152)rn ... 1 morernrn
Could not open Hibernate Session ; nested exception is java.lang.NullPointerExce
[code=java]HTTP Status 500 - rnrn--------------------------------------------------------------------------------rnrntype Exception reportrnrnmessage rnrndescription The server encountered an internal error () that prevented it from fulfilling this request.rnrn<em>exception</em> rnrnorg.apache.jasper.JasperException: org.springframework.transaction.CannotCreateTransactionException: Could not open Hibernate Session for transaction; nested <em>exception</em> is java.lang.NullPointerExceptionrn org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:522)rn org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:416)rn org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)rn org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)rn javax.servlet.http.HttpServlet.service(HttpServlet.java:717)rn org.codehaus.enunciate.modules.spring_app.HTTPRequestContextFilter.doFilter(HTTPRequestContextFilter.java:36)rnrnrnroot cause rnrnorg.springframework.transaction.CannotCreateTransactionException: Could not open Hibernate Session for transaction; nested <em>exception</em> is java.lang.NullPointerExceptionrn org.springframework.orm.<em>hibernate</em>3.HibernateTransactionManager.doBegin(HibernateTransactionManager.java:545)rn org.springframework.transaction.support.AbstractPlatformTransactionManager.getTransaction(AbstractPlatformTransactionManager.java:283)rn org.springframework.transaction.interceptor.TransactionAspectSupport.createTransactionIfNecessary(TransactionAspectSupport.java:234)rn org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:93)rn org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)rn org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:89)rn org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)rn org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)rn $Proxy54.list(Unknown Source)rn org.apache.jsp.frame_jsp._jspService(frame_jsp.java:94)rn org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)rn javax.servlet.http.HttpServlet.service(HttpServlet.java:717)rn org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:374)rn org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)rn org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)rn javax.servlet.http.HttpServlet.service(HttpServlet.java:717)rn org.codehaus.enunciate.modules.spring_app.HTTPRequestContextFilter.doFilter(HTTPRequestContextFilter.java:36)rnrnrnroot cause rnrnjava.lang.NullPointerExceptionrn org.<em>hibernate</em>.cache.impl.bridge.RegionFactoryCacheProviderBridge.nextTimestamp(RegionFactoryCacheProviderBridge.java:85)rn org.<em>hibernate</em>.impl.SessionFactoryImpl.openSession(SessionFactoryImpl.java:526)rn org.<em>hibernate</em>.impl.SessionFactoryImpl.openSession(SessionFactoryImpl.java:535)rn sun.reflect.GeneratedMethodAccessor37.invoke(Unknown Source)rn sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)rn java.lang.reflect.Method.invoke(Method.java:597)rn org.springframework.orm.<em>hibernate</em>3.LocalSessionFactoryBean$TransactionAwareInvocationHandler.invoke(LocalSessionFactoryBean.java:1124)rn $Proxy47.openSession(Unknown Source)rn org.springframework.orm.<em>hibernate</em>3.HibernateTransactionManager.doBegin(HibernateTransactionManager.java:445)rn org.springframework.transaction.support.AbstractPlatformTransactionManager.getTransaction(AbstractPlatformTransactionManager.java:283)rn org.springframework.transaction.interceptor.TransactionAspectSupport.createTransactionIfNecessary(TransactionAspectSupport.java:234)rn org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:93)rn org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)rn org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:89)rn org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)rn org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)rn $Proxy54.list(Unknown Source)rn org.apache.jsp.frame_jsp._jspService(frame_jsp.java:94)rn org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)rn javax.servlet.http.HttpServlet.service(HttpServlet.java:717)rn org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:374)rn org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)rn org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)rn javax.servlet.http.HttpServlet.service(HttpServlet.java:717)rn org.codehaus.enunciate.modules.spring_app.HTTPRequestContextFilter.doFilter(HTTPRequestContextFilter.java:36)rnrnrnnote The full stack trace of the root cause is available in the Apache Tomcat/6.0.20 logs.rnrnrn--------------------------------------------------------------------------------rnrnApache Tomcat/6.0.20[/code]
hibernate.MappingException">hibernate抛异常Exception in thread "main" org.hibernate.MappingException
这是users.hbm.xml文件rnrn rn rn rn users_seqrn rn rn rn rn rnrnrn这是users.cfg.xml文件rnrn rn oracle.jdbc.driver.OracleDriverrn rn jdbc:oracle:thin:@localhost:1521:orclrn rn youngrn rn yiyangrnrn org.<em>hibernate</em>.dialect.Oracle9Dialectrn threadrn rn truern rnrnrn然后是测试类rnpublic static void main(String[] args) rn Users user=new Users();rn user.setName("张三");rn user.setPwd("321");rn rn Configuration config=new Configuration();rn config.configure();rn rn SessionFactory sessionfactory=config.buildSessionFactory();rn Session session=sessionfactory.getCurrentSession();rn Transaction tx=session.beginTransaction();rn session.<em>save</em>(user);rn tx.commit();rn rnrn结果给抛出异常了rnException in thread "main" org.<em>hibernate</em>.MappingException: entity class not found: Usersrn...rnCaused by: java.lang.ClassNotFoundException: Usersrnrn新手刚学。高手请指教。。还是哪配置出错了。
500 Dispatch to method returned an exception(hibernate错误)
这段代码本来是正确的,但是放到Struts就报错,是怎么回事? rnSession session=HibernateSessionFactory.getSession(); rnint pageSize=5; rnint currentPage=2; rnQuery qy=session.createQuery("from Product"); rnint count=qy.list().size(); rnint totalPage=(count-1)/5+1; rnSystem.err.print(totalPage); rnqy.setFirstResult((currentPage-1)*pageSize); rnqy.setMaxResults(pageSize); rnList list=qy.list(); rnfor(int i=0;i (HQLQueryPlan.java:72) rn[18:37:47.039] at org.<em>hibernate</em>.engine.query.HQLQueryPlan. (HQLQueryPlan.java:54) rn[18:37:47.039] at org.<em>hibernate</em>.engine.query.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:71) rn[18:37:47.039] at org.<em>hibernate</em>.impl.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:133) rn[18:37:47.039] at org.<em>hibernate</em>.impl.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:112) rn[18:37:47.039] at org.<em>hibernate</em>.impl.SessionImpl.createQuery(SessionImpl.java:1583) rn[18:37:47.039] at com.jgssdw.product.service.ProductDuration.pagination(ProductDuration.java:58) rn[18:37:47.039] at com.jgssdw.product.action.ProductAction.pagination(ProductAction.java:41) rn[18:37:47.039] ... 22 more rnrnrn如果不要这两句就正确了!rnqy.setFirstResult((currentPage-1)*pageSize); rnqy.setMaxResults(pageSize); rn
exception 异常处理 exception
异常处理 <em>exception</em> <em>exception</em> <em>exception</em> <em>exception</em> 异常处理 <em>exception</em>
unchecked exception和checked exception
一直没搞明白为何把异常分成unchecked <em>exception</em>和checked <em>exception</em>两类。rnrn刚刚反复看api,我有这样一种感觉,不知想的对不对,还望大家指教啊:rnrnRuntimeException和他的子类貌似都是因为程序设计上有错误导致的,比如:rnrnIllegalMonitorStateException 这是同步机制使用的不正确rnIndexOutOfBoundsException 数组用的不对rnNullPointerException 没初始化rnrn等等还有很多。rnrn=====================================================rnrn我又看了看checked <em>exception</em>,他们都是java程序本身控制不了的,但是又不能不应对的异常,比如:rnrnSQLException api解释:An <em>exception</em> that provides information on a database access error or other errors 数据库造成的rnrnFileNotFoundException 文件系统造成的rnrnSocketException Signals that an error occurred while attempting to connect a socket to a remote address and port. Typically, the connection was refused remotely 这是socket服务器的原因。rnrn大家拍砖,指条明路吧,大侠们 谢谢rnrnrnrn
FIX WIN windows系统常见问题修复工具下载
简单易用的小工具,可以用来修复如IE,WINDOWS MEDIA等出错的常见问题。 相关下载链接:[url=//download.csdn.net/download/zhangwenfeng12345/3978462?utm_source=bbsseo]//download.csdn.net/download/zhangwenfeng12345/3978462?utm_source=bbsseo[/url]
labview退出程序下载
一个有关于labview的程序,关于退出的建议 相关下载链接:[url=//download.csdn.net/download/ahai258258/4233771?utm_source=bbsseo]//download.csdn.net/download/ahai258258/4233771?utm_source=bbsseo[/url]
LTE-UMTS长期演进理论与实践下载
LTE-UMTS长期演进理论与实践 内容新颖实用:最新LTE和LTE-Advanced技术讨论结果的反映作者译者权威:3GPP标准制定者倾心编撰,国内通信技术专家严谨翻译内容全面深入:篇幅大,内容深刻透彻,适合作为人手一本的“宝典” 相关下载链接:[url=//download.csdn.net/download/zhang55qwe/5045086?utm_source=bbsseo]//download.csdn.net/download/zhang55qwe/5045086?utm_source=bbsseo[/url]
相关热词 c#入门推荐书 c# 解码海康数据流 c# xml的遍历循环 c# 取 查看源码没有的 c#解决高并发 委托 c#日期转化为字符串 c# 显示问号 c# 字典对象池 c#5.0 安装程序 c# 分页算法
我们是很有底线的